ILIAS  release_8 Revision v8.24
ilCachedLanguage Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilCachedLanguage:

Public Member Functions

 isActive ()
 Return whether the global cache is active. More...
 
 writeToCache ()
 Write to global cache. More...
 
 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 (string $language_key)
 Set language key. More...
 
 getLanguageKey ()
 Return language key. More...
 
 setLoaded (bool $loaded)
 
 getLoaded ()
 
 setTranslations (array $translations)
 Set translations. More...
 
 getTranslations ()
 Return translations as array. More...
 

Static Public Member Functions

static getInstance ($key)
 

Protected Member Functions

 __construct (string $language_key)
 ilCachedLanguage constructor. More...
 
 readFromCache ()
 Read from cache. More...
 
 readFromDB ()
 Read data from table lng_module from DB. More...
 

Protected Attributes

ilGlobalCache $global_cache
 
bool $loaded = false
 
string $language_key = "en"
 
array $translations = array()
 

Static Protected Attributes

static array $instances = array()
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 30 of file class.ilCachedLanguage.php.

Constructor & Destructor Documentation

◆ __construct()

ilCachedLanguage::__construct ( string  $language_key)
protected

ilCachedLanguage constructor.

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

42 {
45 $this->readFromCache();
46 if (!$this->getLoaded()) {
47 $this->readFromDB();
48 $this->writeToCache();
49 $this->setLoaded(true);
50 }
51 }
readFromDB()
Read data from table lng_module from DB.
setLanguageKey(string $language_key)
Set language key.
readFromCache()
Read from cache.
writeToCache()
Write to global cache.
static getInstance(?string $component)

References ilGlobalCache\COMP_CLNG, ilGlobalCache\getInstance(), getLoaded(), readFromCache(), readFromDB(), setLanguageKey(), setLoaded(), and writeToCache().

+ Here is the call graph for this function:

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 91 of file class.ilCachedLanguage.php.

91 : void
92 {
93 if ($this->global_cache->isActive()) {
94 $this->global_cache->delete("translations_" . $this->getLanguageKey());
95 $this->setLoaded(false);
96 }
97 }
getLanguageKey()
Return language key.

References getLanguageKey(), and setLoaded().

+ Here is the call graph for this function:

◆ flush()

ilCachedLanguage::flush ( )

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

132 : void
133 {
134 if ($this->global_cache->isActive()) {
135 $this->global_cache->flush();
136 }
137 $this->readFromDB();
138 $this->writeToCache();
139 }

References readFromDB(), and writeToCache().

+ Here is the call graph for this function:

◆ getInstance()

static ilCachedLanguage::getInstance (   $key)
static

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

123 : self
124 {
125 if (!isset(self::$instances[$key])) {
126 self::$instances[$key] = new self($key);
127 }
128
129 return self::$instances[$key];
130 }
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key.

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

+ Here is the caller graph for this function:

◆ getLanguageKey()

ilCachedLanguage::getLanguageKey ( )

Return language key.

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

152 : string
153 {
154 return $this->language_key;
155 }

References $language_key.

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

+ Here is the caller graph for this function:

◆ getLoaded()

ilCachedLanguage::getLoaded ( )

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

162 : bool
163 {
164 return $this->loaded;
165 }

References $loaded.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getTranslations()

ilCachedLanguage::getTranslations ( )

Return translations as array.

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

178 : array
179 {
180 return $this->translations;
181 }

References $translations.

Referenced by writeToCache().

+ Here is the caller graph for this function:

◆ isActive()

ilCachedLanguage::isActive ( )

Return whether the global cache is active.

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

56 : bool
57 {
58 return $this->global_cache->isActive();
59 }

◆ readFromCache()

ilCachedLanguage::readFromCache ( )
protected

Read from cache.

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

64 : void
65 {
66 if ($this->global_cache->isActive()) {
67 $translations = $this->global_cache->get("translations_" . $this->getLanguageKey());
68 if (is_array($translations)) {
70 $this->setLoaded(true);
71 }
72 }
73 }
setTranslations(array $translations)
Set translations.

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

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readFromDB()

ilCachedLanguage::readFromDB ( )
protected

Read data from table lng_module from DB.

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

102 : void
103 {
104 global $DIC;
105 $ilDB = $DIC->database();
106
107 $q = 'SELECT module, lang_array FROM lng_modules WHERE lang_key = %s';
108 $res = $ilDB->queryF($q, array( "text" ), array( $this->getLanguageKey() ));
109 $translations = array();
110 while ($set = $ilDB->fetchObject($res)) {
111 try {
112 $lang_array = unserialize($set->lang_array, ['allowed_classes' => false]);
113 } catch (Throwable $t) {
114 continue;
115 }
116 if (is_array($lang_array)) {
117 $translations[$set->module] = $lang_array;
118 }
119 }
121 }
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69

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

Referenced by __construct(), and flush().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLanguageKey()

ilCachedLanguage::setLanguageKey ( string  $language_key)

Set language key.

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

144 : void
145 {
146 $this->language_key = $language_key;
147 }

References $language_key.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setLoaded()

ilCachedLanguage::setLoaded ( bool  $loaded)

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

157 : void
158 {
159 $this->loaded = $loaded;
160 }

References $loaded.

Referenced by __construct(), deleteInCache(), and readFromCache().

+ Here is the caller graph for this function:

◆ setTranslations()

ilCachedLanguage::setTranslations ( array  $translations)

Set translations.

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

170 : void
171 {
172 $this->translations = $translations;
173 }

References $translations.

Referenced by readFromCache(), and readFromDB().

+ Here is the caller graph for this function:

◆ writeToCache()

ilCachedLanguage::writeToCache ( )

Write to global cache.

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

78 : void
79 {
80 if ($this->global_cache->isActive()) {
81 $this->global_cache->set("translations_" . $this->getLanguageKey(), $this->getTranslations());
82 }
83 }
getTranslations()
Return translations as array.

References getLanguageKey(), and getTranslations().

Referenced by __construct(), and flush().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $global_cache

ilGlobalCache ilCachedLanguage::$global_cache
protected

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

◆ $instances

array ilCachedLanguage::$instances = array()
staticprotected

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

◆ $language_key

string ilCachedLanguage::$language_key = "en"
protected

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

Referenced by getLanguageKey(), and setLanguageKey().

◆ $loaded

bool ilCachedLanguage::$loaded = false
protected

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

Referenced by getLoaded(), and setLoaded().

◆ $translations

array ilCachedLanguage::$translations = array()
protected

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