ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCachedLanguage Class Reference

Class ilCachedLanguage. More...

+ Collaboration diagram for ilCachedLanguage:

Public Member Functions

 isActive ()
 
 writeToCache ()
 
 deleteInCache ()
 Delete the cache entry for this language without flushing the whole global cache Using this function avoids a flush loop when languages are updated A missing entry will cause the next request to refill the cache in the constructor of this class. More...
 
 flush ()
 
 setLanguageKey ($language_key)
 
 getLanguageKey ()
 
 setLoaded ($loaded)
 
 getLoaded ()
 
 setTranslations ($translations)
 
 getTranslations ()
 

Static Public Member Functions

static getInstance ($key)
 

Protected Member Functions

 readFromCache ()
 
 readFromDB ()
 

Protected Attributes

 $global_cache
 
 $loaded = false
 
 $language_key = 'en'
 
 $translations = array()
 

Static Protected Attributes

static $instances = array()
 

Detailed Description

Class ilCachedLanguage.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

Definition at line 10 of file class.ilCachedLanguage.php.

Member Function Documentation

◆ deleteInCache()

ilCachedLanguage::deleteInCache ( )

Delete the cache entry for this language without flushing the whole global cache Using this function avoids a flush loop when languages are updated A missing entry will cause the next request to refill the cache in the constructor of this class.

See also
mantis #28818

Definition at line 85 of file class.ilCachedLanguage.php.

References getLanguageKey(), and setLoaded().

85  {
86  if ($this->global_cache->isActive()) {
87  $this->global_cache->delete('translations_' . $this->getLanguageKey());
88  $this->setLoaded(false);
89  }
90  }
+ Here is the call graph for this function:

◆ flush()

ilCachedLanguage::flush ( )

Definition at line 125 of file class.ilCachedLanguage.php.

References readFromDB(), and writeToCache().

126  {
127  if ($this->global_cache->isActive()) {
128  $this->global_cache->flush();
129  }
130  $this->readFromDB();
131  $this->writeToCache();
132  }
+ Here is the call graph for this function:

◆ getInstance()

static ilCachedLanguage::getInstance (   $key)
static
Parameters
$key
Returns
ilCachedLanguage

Definition at line 115 of file class.ilCachedLanguage.php.

Referenced by ilLanguage\__construct(), ilObjLanguageExt\_saveValues(), ilObjLanguage\insert(), and ilObjLanguageDBAccess\replaceLangModules().

116  {
117  if (!isset(self::$instances[$key])) {
118  self::$instances[$key] = new self($key);
119  }
120 
121  return self::$instances[$key];
122  }
+ Here is the caller graph for this function:

◆ getLanguageKey()

ilCachedLanguage::getLanguageKey ( )
Returns
string

Definition at line 147 of file class.ilCachedLanguage.php.

References $language_key.

Referenced by deleteInCache(), readFromCache(), readFromDB(), and writeToCache().

148  {
149  return $this->language_key;
150  }
+ Here is the caller graph for this function:

◆ getLoaded()

ilCachedLanguage::getLoaded ( )
Returns
boolean

Definition at line 165 of file class.ilCachedLanguage.php.

References $loaded.

166  {
167  return $this->loaded;
168  }

◆ getTranslations()

ilCachedLanguage::getTranslations ( )
Returns
array

Definition at line 183 of file class.ilCachedLanguage.php.

References $translations.

Referenced by writeToCache().

184  {
185  return $this->translations;
186  }
+ Here is the caller graph for this function:

◆ isActive()

ilCachedLanguage::isActive ( )
Returns
bool

Definition at line 54 of file class.ilCachedLanguage.php.

55  {
56  return $this->global_cache->isActive();
57  }

◆ readFromCache()

ilCachedLanguage::readFromCache ( )
protected

Definition at line 60 of file class.ilCachedLanguage.php.

References $translations, getLanguageKey(), setLoaded(), and setTranslations().

61  {
62  if ($this->global_cache->isActive()) {
63  $translations = $this->global_cache->get('translations_' . $this->getLanguageKey());
64  if (is_array($translations)) {
66  $this->setLoaded(true);
67  }
68  }
69  }
setTranslations($translations)
+ Here is the call graph for this function:

◆ readFromDB()

ilCachedLanguage::readFromDB ( )
protected

Definition at line 92 of file class.ilCachedLanguage.php.

References $DIC, $ilDB, $res, $translations, getLanguageKey(), and setTranslations().

Referenced by flush().

93  {
94  global $DIC;
95  $ilDB = $DIC->database();
96 
97  $q = 'SELECT module, lang_array FROM lng_modules WHERE lang_key = %s';
98  $res = $ilDB->queryF($q, array( 'text' ), array( $this->getLanguageKey() ));
99  $translations = array();
100  while ($set = $ilDB->fetchObject($res)) {
101  $lang_array = unserialize($set->lang_array);
102  if (is_array($lang_array)) {
103  $translations[$set->module] = $lang_array;
104  }
105  }
107  }
setTranslations($translations)
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLanguageKey()

ilCachedLanguage::setLanguageKey (   $language_key)
Parameters
string$language_key

Definition at line 138 of file class.ilCachedLanguage.php.

References $language_key.

139  {
140  $this->language_key = $language_key;
141  }

◆ setLoaded()

ilCachedLanguage::setLoaded (   $loaded)
Parameters
boolean$loaded

Definition at line 156 of file class.ilCachedLanguage.php.

References $loaded.

Referenced by deleteInCache(), and readFromCache().

157  {
158  $this->loaded = $loaded;
159  }
+ Here is the caller graph for this function:

◆ setTranslations()

ilCachedLanguage::setTranslations (   $translations)
Parameters
array$translations

Definition at line 174 of file class.ilCachedLanguage.php.

References $translations.

Referenced by readFromCache(), and readFromDB().

175  {
176  $this->translations = $translations;
177  }
+ Here is the caller graph for this function:

◆ writeToCache()

ilCachedLanguage::writeToCache ( )

Definition at line 72 of file class.ilCachedLanguage.php.

References getLanguageKey(), and getTranslations().

Referenced by flush().

73  {
74  if ($this->global_cache->isActive()) {
75  $this->global_cache->set('translations_' . $this->getLanguageKey(), $this->getTranslations());
76  }
77  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $global_cache

ilCachedLanguage::$global_cache
protected

Definition at line 12 of file class.ilCachedLanguage.php.

◆ $instances

ilCachedLanguage::$instances = array()
staticprotected

Definition at line 28 of file class.ilCachedLanguage.php.

◆ $language_key

ilCachedLanguage::$language_key = 'en'
protected

Definition at line 20 of file class.ilCachedLanguage.php.

Referenced by getLanguageKey(), and setLanguageKey().

◆ $loaded

ilCachedLanguage::$loaded = false
protected

Definition at line 16 of file class.ilCachedLanguage.php.

Referenced by getLoaded(), and setLoaded().

◆ $translations

ilCachedLanguage::$translations = array()
protected

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