ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjLanguageExt.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-20014 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "./Services/Language/classes/class.ilObjLanguage.php";
5
15{
16
20 public function __construct($a_id = 0, $a_call_by_reference = false)
21 {
22 parent::__construct($a_id, $a_call_by_reference);
23 }
24
29 public function getGlobalLanguageFile()
30 {
31 require_once "./Services/Language/classes/class.ilLanguageFile.php";
33 }
34
40 public function setLocal($a_local = true)
41 {
42 if ($this->isInstalled()) {
43 if ($a_local == true) {
44 $this->setDescription("installed_local");
45 } else {
46 $this->setDescription("installed");
47 }
48 $this->update();
49 }
50 }
51
52
58 public function getLongDescription()
59 {
60 return $this->lng->txt($this->desc);
61 }
62
63
68 public function getDataPath()
69 {
70 if (!is_dir(CLIENT_DATA_DIR . '/lang_data')) {
71 ilUtil::makeDir(CLIENT_DATA_DIR . '/lang_data');
72 }
73 return CLIENT_DATA_DIR . '/lang_data';
74 }
75
81 public function getLangPath()
82 {
83 return $this->lang_path;
84 }
85
91 public function getCustLangPath()
92 {
93 return $this->cust_lang_path;
94 }
95
101 public function getAllRemarks()
102 {
103 return self::_getRemarks($this->key);
104 }
105
114 public function getAllValues($a_modules = array(), $a_pattern = '', $a_topics = array())
115 {
116 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
117 }
118
119
129 public function getChangedValues($a_modules = array(), $a_pattern = '', $a_topics = array())
130 {
131 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern, 'changed');
132 }
133
134
144 public function getUnchangedValues($a_modules = array(), $a_pattern = '', $a_topics = array())
145 {
146 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern, 'unchanged');
147 }
148
157 public function getAddedValues($a_modules = array(), $a_pattern = '', $a_topics = array())
158 {
159 $global_file_obj = $this->getGlobalLanguageFile();
160 $global_values = $global_file_obj->getAllValues();
161 $local_values = self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
162
163 return array_diff_key($local_values, $global_values);
164 }
165
166
178 public function getCommentedValues($a_modules = array(), $a_pattern = '', $a_topics = array())
179 {
180 $global_file_obj = $this->getGlobalLanguageFile();
181 $global_comments = $global_file_obj->getAllComments();
182 $local_values = self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
183
184 return array_intersect_key($local_values, $global_comments);
185 }
186
187
199 public function getMergedValues()
200 {
201 $global_file_obj = $this->getGlobalLanguageFile();
202 $global_values = $global_file_obj->getAllValues();
203 $local_values = self::_getValues($this->key);
204
205 return array_merge($global_values, $local_values);
206 }
207
219 public function getMergedRemarks()
220 {
221 $global_file_obj = $this->getGlobalLanguageFile();
222 $global_comments = $global_file_obj->getAllComments();
223
224 // get remarks including empty remarks for local changes
225 $local_remarks = self::_getRemarks($this->key, true);
226
227 return array_merge($global_comments, $local_remarks);
228 }
229
230
231
238 public function importLanguageFile($a_file, $a_mode_existing = 'keepnew')
239 {
240 global $ilDB, $ilErr;
241
242 // read the new language file
243 require_once "./Services/Language/classes/class.ilLanguageFile.php";
244 $import_file_obj = new ilLanguageFile($a_file);
245 if (!$import_file_obj->read()) {
246 $ilErr->raiseError($import_file_obj->getErrorMessage(), $ilErr->MESSAGE);
247 }
248
249 switch ($a_mode_existing) {
250 // keep all existing entries
251 case 'keepall':
252 $to_keep = $this->getAllValues();
253 break;
254
255 // keep existing online changes
256 case 'keepnew':
257 $to_keep = $this->getChangedValues();
258 break;
259
260 // replace all existing definitions
261 case 'replace':
262 $to_keep = array();
263 break;
264
265 // delete all existing entries
266 case 'delete':
267 ilObjLanguage::_deleteLangData($this->key, false);
268 $ilDB->manipulate("DELETE FROM lng_modules WHERE lang_key = " .
269 $ilDB->quote($this->key, "text"));
270 $to_keep = array();
271 break;
272
273 default:
274 return;
275 }
276
277 // process the values of the import file
278 $to_save = array();
279 foreach ($import_file_obj->getAllValues() as $key => $value) {
280 if (!isset($to_keep[$key])) {
281 $to_save[$key] = $value;
282 }
283 }
284 self::_saveValues($this->key, $to_save, $import_file_obj->getAllComments());
285 }
286
294 public static function _getModules($a_lang_key)
295 {
296 global $ilDB;
297
298 $q = "SELECT DISTINCT module FROM lng_data WHERE " .
299 " lang_key = " . $ilDB->quote($a_lang_key, "text") . " order by module";
300 $set = $ilDB->query($q);
301
302 $modules = array();
303 while ($rec = $set->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
304 $modules[] = $rec["module"];
305 }
306 return $modules;
307 }
308
309
318 public static function _getRemarks($a_lang_key, $a_all_changed = false)
319 {
320 global $ilDB, $lng;
321
322 $q = "SELECT module, identifier, remarks"
323 . " FROM lng_data"
324 . " WHERE lang_key = " . $ilDB->quote($a_lang_key, "text");
325
326 if ($a_all_changed) {
327 $q .= " AND (remarks IS NOT NULL OR local_change IS NOT NULL)";
328 } else {
329 $q .= " AND remarks IS NOT NULL";
330 }
331
332 $result = $ilDB->query($q);
333
334 $remarks = array();
335 while ($row = $ilDB->fetchAssoc($result)) {
336 $remarks[$row["module"] . $lng->separator . $row["identifier"]] = $row["remarks"];
337 }
338 return $remarks;
339 }
340
341
353 public static function _getValues(
354 $a_lang_key,
355 $a_modules = array(),
356 $a_topics = array(),
357 $a_pattern = '',
358 $a_state = ''
359 ) {
360 global $ilDB, $lng;
361
362 $q = "SELECT * FROM lng_data WHERE" .
363 " lang_key = " . $ilDB->quote($a_lang_key, "text") . " ";
364
365 if (is_array($a_modules) && count($a_modules) > 0) {
366 $q .= " AND " . $ilDB->in("module", $a_modules, false, "text");
367 }
368 if (is_array($a_topics) && count($a_topics) > 0) {
369 $q .= " AND " . $ilDB->in("identifier", $a_topics, false, "text");
370 }
371 if ($a_pattern) {
372 $q .= " AND " . $ilDB->like("value", "text", "%" . $a_pattern . "%");
373 }
374 if ($a_state == "changed") {
375 $q .= " AND NOT local_change IS NULL ";
376 }
377 if ($a_state == "unchanged") {
378 $q .= " AND local_change IS NULL ";
379 }
380 $q .= " ORDER BY module, identifier";
381
382 $set = $ilDB->query($q);
383
384 $values = array();
385 while ($rec = $set->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
386 $values[$rec["module"] . $lng->separator . $rec["identifier"]] = $rec["value"];
387 }
388 return $values;
389 }
390
391
392
393
402 public static function _saveValues($a_lang_key, $a_values = array(), $a_remarks = array())
403 {
404 global $ilDB, $lng;
405
406 if (!is_array($a_values)) {
407 return;
408 }
409 $save_array = array();
410 $save_date = date("Y-m-d H:i:s", time());
411
412 // read and get the global values
413 require_once "./Services/Language/classes/class.ilLanguageFile.php";
414 $global_file_obj = ilLanguageFile::_getGlobalLanguageFile($a_lang_key);
415 $global_values = $global_file_obj->getAllValues();
416 $global_comments = $global_file_obj->getAllComments();
417
418 // save the single translations in lng_data
419 foreach ($a_values as $key => $value) {
420 $keys = explode($lng->separator, $key);
421 if (count($keys) == 2) {
422 $module = $keys[0];
423 $topic = $keys[1];
424 $save_array[$module][$topic] = $value;
425
426 if ($global_values[$key] != $value
427 or $global_comments[$key] != $a_remarks[$key]) {
428 $local_change = $save_date;
429 } else {
430 $local_change = null;
431 }
432
434 $module,
435 $topic,
436 $a_lang_key,
437 $value,
438 $local_change,
439 $a_remarks[$key]
440 );
441 }
442 }
443
444 // save the serialized module entries in lng_modules
445 foreach ($save_array as $module => $entries) {
446 $set = $ilDB->query(sprintf(
447 "SELECT * FROM lng_modules " .
448 "WHERE lang_key = %s AND module = %s",
449 $ilDB->quote($a_lang_key, "text"),
450 $ilDB->quote($module, "text")
451 ));
452 $row = $ilDB->fetchAssoc($set);
453
454 $arr = unserialize($row["lang_array"]);
455 if (is_array($arr)) {
456 $entries = array_merge($arr, $entries);
457 }
458 ilObjLanguage::replaceLangModule($a_lang_key, $module, $entries);
459 }
460
461
462 require_once('class.ilCachedLanguage.php');
463 ilCachedLanguage::getInstance($a_lang_key)->flush();
464 }
465
466
474 public static function _deleteValues($a_lang_key, $a_values = array())
475 {
476 global $ilDB, $lng;
477
478 if (!is_array($a_values)) {
479 return;
480 }
481 $delete_array = array();
482
483 // save the single translations in lng_data
484 foreach ($a_values as $key => $value) {
485 $keys = explode($lng->separator, $key);
486 if (count($keys) == 2) {
487 $module = $keys[0];
488 $topic = $keys[1];
489 $delete_array[$module][$topic] = $value;
490
491 ilObjLanguage::deleteLangEntry($module, $topic, $a_lang_key);
492 }
493 }
494
495 // save the serialized module entries in lng_modules
496 foreach ($delete_array as $module => $entries) {
497 $set = $ilDB->query(sprintf(
498 "SELECT * FROM lng_modules " .
499 "WHERE lang_key = %s AND module = %s",
500 $ilDB->quote($a_lang_key, "text"),
501 $ilDB->quote($module, "text")
502 ));
503 $row = $ilDB->fetchAssoc($set);
504
505 $arr = unserialize($row["lang_array"]);
506 if (is_array($arr)) {
507 $entries = array_diff_key($arr, $entries);
508 }
509 ilObjLanguage::replaceLangModule($a_lang_key, $module, $entries);
510 }
511 }
512} // END class.ilObjLanguageExt
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilLanguageFile.
static _getGlobalLanguageFile($a_lang_key)
Read and get a global language file as a singleton object.
Class ilObjLanguageExt.
getGlobalLanguageFile()
Read and get the global language file as an object.
getAddedValues($a_modules=array(), $a_pattern='', $a_topics=array())
Get only the entries which don't exist in the global language file.
importLanguageFile($a_file, $a_mode_existing='keepnew')
Import a language file into the ilias database.
getAllValues($a_modules=array(), $a_pattern='', $a_topics=array())
Get all values from the database.
getChangedValues($a_modules=array(), $a_pattern='', $a_topics=array())
Get only the changed values from the database which differ from the original language file.
static _deleteValues($a_lang_key, $a_values=array())
Delete a set of translation in the database.
getLongDescription()
Get the full language description.
static _getModules($a_lang_key)
Get all modules of a language.
__construct($a_id=0, $a_call_by_reference=false)
Constructor.
getMergedValues()
Get the local values merged into the values of the global language file.
getCustLangPath()
Get the customized language files path.
getDataPath()
Get the path for language data written by ILIAS.
static _getRemarks($a_lang_key, $a_all_changed=false)
Get all remarks of a language.
setLocal($a_local=true)
Set the local status of the language.
getCommentedValues($a_modules=array(), $a_pattern='', $a_topics=array())
Get all values from the database for wich the global language file has a comment.
getLangPath()
Get the language files path.
static _saveValues($a_lang_key, $a_values=array(), $a_remarks=array())
Save a set of translation in the database.
getUnchangedValues($a_modules=array(), $a_pattern='', $a_topics=array())
Get only the unchanged values from the database which are equal to the original language file.
getMergedRemarks()
Get the local remarks merged into the remarks of the global language file.
static _getValues( $a_lang_key, $a_modules=array(), $a_topics=array(), $a_pattern='', $a_state='')
Get the translations of specified topics.
getAllRemarks()
Get all remarks from the database.
Class ilObjLanguage.
static _deleteLangData($a_lang_key, $a_keep_local_change=false)
Delete languge data.
static deleteLangEntry($a_module, $a_identifier, $a_lang_key)
Delete lang entry.
isInstalled()
Check language object status, and return true if language is installed.
static replaceLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null, $a_remarks=null)
Replace lang entry.
update()
update object in db
setDescription($a_desc)
set object description
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
$keys
if($modEnd===false) $module
Definition: module.php:59
global $ilErr
Definition: raiseError.php:16
global $ilDB