Public Member Functions | Data Fields

ilObjLanguage Class Reference

Inheritance diagram for ilObjLanguage:
Collaboration diagram for ilObjLanguage:

Public Member Functions

 ilObjLanguage ($a_id=0, $a_call_by_reference=false)
 Constructor.
 getKey ()
 get language key
 getStatus ()
 get language status
 isSystemLanguage ()
 check if language is system language
 isUserLanguage ()
 check if language is system language
 isInstalled ()
 Check language object status, and return true if language is installed.
 isLocal ()
 Check language object status, and return true if a local language file is installed.
 install ($scope= '')
 install current language
 uninstall ()
 uninstall current language
 flush ()
 remove language data from database
 insert ($scope= '')
 insert language data from file into database
 resetUserLanguage ($lang_key)
 search ILIAS for users which have selected '$lang_key' as their prefered language and reset them to default language (english).
 cut_header ($content)
 remove lang-file haeder information from '$content' This function seeks for a special keyword where the language information starts.
 optimizeData ()
 optimizes the db-table langdata
 check ($scope= '')
 Validate the logical structure of a lang file.

Data Fields

 $separator
 $comment_separator
 $lang_default
 $lang_user
 $lang_path
 $key
 $status

Detailed Description

Definition at line 35 of file class.ilObjLanguage.php.


Member Function Documentation

ilObjLanguage::check ( scope = ''  ) 

Validate the logical structure of a lang file.

This function checks if a lang file exists, the file has a header, and each lang-entry consists of exactly three elements (module, identifier, value).

Returns:
string system message
Parameters:
string $scope empty (global) or "local"

Definition at line 420 of file class.ilObjLanguage.php.

References $key, and cut_header().

Referenced by install().

        {
                if (!empty($scope))
                {
                        if ($scope == 'global')
                        {
                                $scope = ''; 
                        }
                        else
                        {
                                $scopeExtension = '.' . $scope;
                        }
                }

                $tmpPath = getcwd();
                chdir($this->lang_path);

                // compute lang-file name format
                $lang_file = "ilias_" . $this->key . ".lang" . $scopeExtension;

                // file check
                if (!is_file($lang_file))
                {
                        $this->ilias->raiseError("File not found: ".$lang_file,$this->ilias->error_obj->MESSAGE);
                }

                // header check
                if (!$content = $this->cut_header(file($lang_file)))
                {
                        $this->ilias->raiseError("Wrong Header in ".$lang_file,$this->ilias->error_obj->MESSAGE);
                }

                // check (counting) elements of each lang-entry
                $line = 0;
                foreach ($content as $key => $val)
                {
                        $separated = explode($this->separator, trim($val));
                        $num = count($separated);
                        ++$n;
                        if ($num != 3)
                        {
                                $line = $n + 36;
                                $this->ilias->raiseError("Wrong parameter count in ".$lang_file." in line $line (Value: $val)! Please check your language file!",$this->ilias->error_obj->MESSAGE);
                        }
                }

                chdir($tmpPath);

                // no error occured
                return true;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilObjLanguage::cut_header ( content  ) 

remove lang-file haeder information from '$content' This function seeks for a special keyword where the language information starts.

if found it returns the plain language information, otherwise returns false

Parameters:
string $content expecting an ILIAS lang-file
Returns:
string $content content without header info OR false if no valid header was found

Definition at line 384 of file class.ilObjLanguage.php.

References $key.

Referenced by check(), ilObjLanguageFolder::checkAllLanguages(), and insert().

        {
                foreach ($content as $key => $val)
                {
                        if (trim($val) == "<!-- language file start -->")
                        {
                                return array_slice($content,$key +1);
                        }
                }

                return false;
        }

Here is the caller graph for this function:

ilObjLanguage::flush (  ) 

remove language data from database

Definition at line 237 of file class.ilObjLanguage.php.

References $query.

Referenced by install(), and uninstall().

        {
                $query = "DELETE FROM lng_data WHERE lang_key='".$this->key."'";
                $this->ilias->db->query($query);
        }

Here is the caller graph for this function:

ilObjLanguage::getKey (  ) 

get language key

Returns:
string language key

Definition at line 83 of file class.ilObjLanguage.php.

Referenced by install().

        {
                return $this->key;
        }

Here is the caller graph for this function:

ilObjLanguage::getStatus (  ) 

get language status

Returns:
string language status

Definition at line 93 of file class.ilObjLanguage.php.

Referenced by isInstalled(), and isLocal().

        {
                return $this->status;
        }

Here is the caller graph for this function:

ilObjLanguage::ilObjLanguage ( a_id = 0,
a_call_by_reference = false 
)

Constructor.

public

Parameters:
integer reference_id or object_id
boolean treat the id as reference_id (true) or object_id (false)

Definition at line 61 of file class.ilObjLanguage.php.

References ilObject::$lng, and ilObject::ilObject().

        {
                global $lng;

                $this->type = "lng";
                $this->ilObject($a_id,$a_call_by_reference);

                $this->type = "lng";
                $this->key = $this->title;
                $this->status = $this->desc;
                $this->lang_default = $lng->lang_default;
                $this->lang_user = $lng->lang_user;
                $this->lang_path = $lng->lang_path;
                $this->separator = $lng->separator;
                $this->comment_separator = $lng->comment_separator;
        }

Here is the call graph for this function:

ilObjLanguage::insert ( scope = ''  ) 

insert language data from file into database

Parameters:
string $scope empty (global) or "local"

Definition at line 249 of file class.ilObjLanguage.php.

References $key, $pos, $q, $query, $row, $set, and cut_header().

Referenced by install().

        {
                global $ilDB;
                
                if (!empty($scope))
                {
                        if ($scope == 'global')
                        {
                                $scope = ''; 
                        }
                        else
                        {
                                $scopeExtension = '.' . $scope;
                        }
                }

                $tmpPath = getcwd();
                chdir($this->lang_path);

                $lang_file = "ilias_" . $this->key . ".lang" . $scopeExtension;

                if ($lang_file)
                {
                        // remove header first
                        if ($content = $this->cut_header(file($lang_file)))
                        {
                                foreach ($content as $key => $val)
                                {
                                        $separated = explode($this->separator,trim($val));
                                        
                                        //get position of the comment_separator
                                        $pos = strpos($separated[2], $this->comment_separator);
                                
                                        if ($pos !== false)
                                        { 
                                                //cut comment of
                                                $separated[2] = substr($separated[2] , 0 , $pos);
                                        }

                                        if (empty($scope))
                                        {
                                                $query = "INSERT INTO lng_data " .
                                                                "(module, identifier, lang_key, value) " .
                                                                "VALUES " .
                                                                "('" . $separated[0] . "','" . $separated[1] . "','" . $this->key . "','" . addslashes($separated[2]) . "')";
                                                $lang_array[$separated[0]][$separated[1]] = $separated[2];
                                        }
                                        else if ($scope == 'local')
                                        {
                                                // UPDATE because the global values have already been INSERTed
                                                $query = "UPDATE lng_data SET ".
                                                                 "module = '" . $separated[0] . "', " .
                                                                 "identifier = '" . $separated[1] . "', " . 
                                                                 "lang_key = '" . $this->key . "', " .
                                                                 "value = '" . addslashes($separated[2]) . "' " .
                                                                 "WHERE module = '" . $separated[0] . "' " .
                                                                 "AND identifier = '" . $separated[1] . "' " .
                                                                 "AND lang_key = '" . $this->key . "'";
                                                $lang_array[$separated[0]][$separated[1]] = $separated[2];
                                        }
                                        $this->ilias->db->query($query);
                                }

                                if (empty($scope))
                                {
                                        $query = "UPDATE object_data SET " .
                                                        "description = 'installed', " .
                                                        "last_update = now() " .
                                                        "WHERE title = '".$this->key."' " .
                                                        "AND type = 'lng'";
                                }
                                else if ($scope == 'local')
                                {
                                        $query = "UPDATE object_data SET " .
                                                        "description = 'installed_local', " .
                                                        "last_update = now() " .
                                                        "WHERE title = '".$this->key."' " .
                                                        "AND type = 'lng'";
                                }
                                $this->ilias->db->query($query);
                        }
                        
                        // insert module data
                        $lang_array[$separated[0]][$separated[1]] = $separated[2];

                        foreach($lang_array as $module => $lang_arr)
                        {
                                if ($scope == "local")
                                {
                                        $q = "SELECT * FROM lng_modules WHERE ".
                                                " lang_key = ".$ilDB->quote($this->key).
                                                " AND module = ".$ilDB->quote($module);
                                        $set = $ilDB->query($q);
                                        $row = $set->fetchRow(DB_FETCHMODE_ASSOC);
                                        $arr2 = unserialize($row["lang_array"]);
                                        if (is_array($arr2))
                                        {
                                                $lang_arr = array_merge($arr2, $lang_arr);
                                        }
                                }
                                $query = "REPLACE INTO lng_modules (lang_key, module, lang_array) VALUES ".
                                         "(".$ilDB->quote($this->key).", " .
                                         " ".$ilDB->quote($module).", " . 
                                         " ".$ilDB->quote(serialize($lang_arr)).") ";
                                $ilDB->query($query);

                        }
                }

                chdir($tmpPath);
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilObjLanguage::install ( scope = ''  ) 

install current language

Returns:
string installed language key
Parameters:
string $scope empty (global) or "local"

Definition at line 166 of file class.ilObjLanguage.php.

References check(), flush(), getKey(), insert(), isInstalled(), isLocal(), optimizeData(), ilObject::setDescription(), and ilObject::update().

        {
                if (!empty($scope))
                {
                        if ($scope == 'global')
                        {
                                $scope = ''; 
                        }
                        else
                        {
                                $scopeExtension = '.' . $scope;
                        }
                }

                if (($this->isInstalled() == false) || 
                                ($this->isInstalled() == true && $this->isLocal() == false && !empty($scope)))
                {
                        if ($this->check($scope))
                        {
                                // lang-file is ok. Flush data in db and...
                                if (empty($scope))
                                {
                                        $this->flush();
                                }

                                // ...re-insert data from lang-file
                                $this->insert($scope);

                                // update information in db-table about available/installed languages
                                if (empty($scope))
                                {
                                        $newDesc = 'installed';
                                }
                                else if ($scope == 'local')
                                {
                                        $newDesc = 'installed_local';
                                }
                                $this->setDescription($newDesc);
                                $this->update();
                                $this->optimizeData();
                                return $this->getKey();
                        }
                }
                return "";
        }

Here is the call graph for this function:

ilObjLanguage::isInstalled (  ) 

Check language object status, and return true if language is installed.

Returns:
boolean true if installed

Definition at line 130 of file class.ilObjLanguage.php.

References getStatus().

Referenced by install().

        {
                if (substr($this->getStatus(), 0, 9) == "installed")
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilObjLanguage::isLocal (  ) 

Check language object status, and return true if a local language file is installed.

Returns:
boolean true if local language is installed

Definition at line 148 of file class.ilObjLanguage.php.

References getStatus().

Referenced by install().

        {
                if (substr($this->getStatus(), 10) == "local")
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilObjLanguage::isSystemLanguage (  ) 

check if language is system language

Definition at line 101 of file class.ilObjLanguage.php.

        {
                if ($this->key == $this->lang_default)
                        return true;
                else
                        return false;
        }

ilObjLanguage::isUserLanguage (  ) 

check if language is system language

Definition at line 112 of file class.ilObjLanguage.php.

        {
                if ($this->key == $this->lang_user)
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }

ilObjLanguage::optimizeData (  ) 

optimizes the db-table langdata

Returns:
boolean true on success

Definition at line 402 of file class.ilObjLanguage.php.

References $query.

Referenced by install().

        {
                // optimize
                $query = "OPTIMIZE TABLE lng_data";
                $this->ilias->db->query($query);

                return true;
        }

Here is the caller graph for this function:

ilObjLanguage::resetUserLanguage ( lang_key  ) 

search ILIAS for users which have selected '$lang_key' as their prefered language and reset them to default language (english).

A message is sent to all affected users

Parameters:
string $lang_key international language key (2 digits)

Definition at line 367 of file class.ilObjLanguage.php.

References $query.

Referenced by uninstall().

        {
                $query = "UPDATE usr_pref SET " .
                                "value = '" . $this->lang_default."' " .
                                "WHERE keyword = 'language' " .
                                "AND value = '" . $lang_key . "'";
                $this->ilias->db->query($query);
        }

Here is the caller graph for this function:

ilObjLanguage::uninstall (  ) 

uninstall current language

Returns:
string uninstalled language key

Definition at line 218 of file class.ilObjLanguage.php.

References flush(), resetUserLanguage(), ilObject::setDescription(), ilObject::setTitle(), and ilObject::update().

        {
                if ((substr($this->status, 0, 9) == "installed") && ($this->key != $this->lang_default) && ($this->key != $this->lang_user))
                {
                        $this->flush();
                        $this->setTitle($this->key);
                        $this->setDescription("not_installed");
                        $this->update();
                        $this->resetUserLanguage($this->key);

                        return $this->key;
                }
                return "";
        }

Here is the call graph for this function:


Field Documentation

ilObjLanguage::$comment_separator

Definition at line 45 of file class.ilObjLanguage.php.

ilObjLanguage::$key

Definition at line 50 of file class.ilObjLanguage.php.

Referenced by check(), cut_header(), and insert().

ilObjLanguage::$lang_default

Definition at line 46 of file class.ilObjLanguage.php.

ilObjLanguage::$lang_path

Definition at line 48 of file class.ilObjLanguage.php.

ilObjLanguage::$lang_user

Definition at line 47 of file class.ilObjLanguage.php.

ilObjLanguage::$separator

Definition at line 44 of file class.ilObjLanguage.php.

ilObjLanguage::$status

Definition at line 51 of file class.ilObjLanguage.php.


The documentation for this class was generated from the following file: