ILIAS  release_8 Revision v8.23
ilAdvancedMDRecordTranslations Class Reference

Class ilAdvancedMDRecordTranslation. More...

+ Collaboration diagram for ilAdvancedMDRecordTranslations:

Public Member Functions

 getDefaultLanguage ()
 
 getRecordId ()
 
 isConfigured (string $lang_key)
 
 getTranslation (string $lang_key)
 
 getTranslations ()
 array<string, ilAdvancedMDRecordTranslation> More...
 
 getDefaultTranslation ()
 
 cloneRecord (int $new_record_id)
 
 addTranslationEntry (string $language_code, bool $default=false)
 
 updateDefault (string $default)
 
 getFormTranslationInfo (string $active_language)
 
 modifyTranslationInfoForTitle (ilPropertyFormGUI $form, ilTextInputGUI $title, string $active_language)
 
 modifyTranslationInfoForDescription (ilPropertyFormGUI $form, ilTextAreaInputGUI $description, string $active_language)
 
 updateTranslations (string $active_language, string $title, string $description)
 
 getTitleForLanguage (string $language)
 
 getDescriptionForLanguage (string $language)
 
 toXML (ilXmlWriter $writer)
 

Static Public Member Functions

static getInstanceByRecordId (int $record_id)
 

Private Member Functions

 __construct (int $record_id)
 
 read ()
 

Private Attributes

int $record_id
 
ilAdvancedMDRecord $record
 
 $translations = []
 
string $default_language = ''
 
ilDBInterface $db
 
ilLanguage $lng
 

Static Private Attributes

static $instances = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDRecordTranslations::__construct ( int  $record_id)
private

Definition at line 30 of file class.ilAdvancedMDRecordTranslations.php.

References $DIC, $record_id, ILIAS\Repository\lng(), and read().

31  {
32  global $DIC;
33 
34  $this->db = $DIC->database();
35  $this->lng = $DIC->language();
36  $this->lng->loadLanguageModule('meta');
37 
38  $this->record_id = $record_id;
39  $this->read();
40  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ addTranslationEntry()

ilAdvancedMDRecordTranslations::addTranslationEntry ( string  $language_code,
bool  $default = false 
)

Definition at line 119 of file class.ilAdvancedMDRecordTranslations.php.

119  : void
120  {
121  $this->translations[$language_code] = new ilAdvancedMDRecordTranslation(
122  $this->record_id,
123  '',
124  '',
125  $language_code,
126  $default
127  );
128  $this->translations[$language_code]->insert();
129  }
Class ilAdvancedMDRecordTranslation.

◆ cloneRecord()

ilAdvancedMDRecordTranslations::cloneRecord ( int  $new_record_id)

Definition at line 91 of file class.ilAdvancedMDRecordTranslations.php.

References getTranslations().

91  : void
92  {
93  foreach ($this->getTranslations() as $recordTranslation) {
94  $recordTranslation->setRecordId($new_record_id);
95  $recordTranslation->insert();
96  }
97  }
getTranslations()
array<string, ilAdvancedMDRecordTranslation>
+ Here is the call graph for this function:

◆ getDefaultLanguage()

ilAdvancedMDRecordTranslations::getDefaultLanguage ( )

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

References $default_language.

Referenced by toXML().

50  : string
51  {
53  }
+ Here is the caller graph for this function:

◆ getDefaultTranslation()

ilAdvancedMDRecordTranslations::getDefaultTranslation ( )

Definition at line 81 of file class.ilAdvancedMDRecordTranslations.php.

References $default_language, and getTranslations().

Referenced by modifyTranslationInfoForDescription(), and modifyTranslationInfoForTitle().

82  {
83  foreach ($this->getTranslations() as $translation) {
84  if ($translation->getLangKey() == $this->default_language) {
85  return $translation;
86  }
87  }
88  return null;
89  }
getTranslations()
array<string, ilAdvancedMDRecordTranslation>
Class ilAdvancedMDRecordTranslation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDescriptionForLanguage()

ilAdvancedMDRecordTranslations::getDescriptionForLanguage ( string  $language)

Definition at line 215 of file class.ilAdvancedMDRecordTranslations.php.

References getTranslation().

215  : string
216  {
217  if ($this->getTranslation($language) && strlen($this->getTranslation($language)->getDescription())) {
218  return $this->getTranslation($language)->getDescription();
219  }
220  return $this->record->getDescription();
221  }
+ Here is the call graph for this function:

◆ getFormTranslationInfo()

ilAdvancedMDRecordTranslations::getFormTranslationInfo ( string  $active_language)

Definition at line 145 of file class.ilAdvancedMDRecordTranslations.php.

References $default_language, $txt, and ILIAS\Repository\lng().

145  : string
146  {
147  if (count($this->translations) <= 1) {
148  return '';
149  }
150  $txt = '';
151  $txt = $this->lng->txt('md_adv_int_current') . ' ' . $this->lng->txt('meta_l_' . $active_language);
152  $txt .= ', ';
153  foreach ($this->translations as $translation) {
154  if ($translation->getLangKey() == $this->default_language) {
155  $txt .= ($this->lng->txt('md_adv_int_default') . ' ' . $this->lng->txt('meta_l_' . $translation->getLangKey()));
156  break;
157  }
158  }
159  return $txt;
160  }
$txt
Definition: error.php:13
+ Here is the call graph for this function:

◆ getInstanceByRecordId()

◆ getRecordId()

ilAdvancedMDRecordTranslations::getRecordId ( )

Definition at line 55 of file class.ilAdvancedMDRecordTranslations.php.

References $record_id.

Referenced by read().

+ Here is the caller graph for this function:

◆ getTitleForLanguage()

ilAdvancedMDRecordTranslations::getTitleForLanguage ( string  $language)

Definition at line 207 of file class.ilAdvancedMDRecordTranslations.php.

References getTranslation().

207  : string
208  {
209  if ($this->getTranslation($language) && strlen($this->getTranslation($language)->getTitle())) {
210  return $this->getTranslation($language)->getTitle();
211  }
212  return $this->record->getTitle();
213  }
+ Here is the call graph for this function:

◆ getTranslation()

ilAdvancedMDRecordTranslations::getTranslation ( string  $lang_key)

Definition at line 65 of file class.ilAdvancedMDRecordTranslations.php.

References isConfigured().

Referenced by getDescriptionForLanguage(), getTitleForLanguage(), modifyTranslationInfoForDescription(), modifyTranslationInfoForTitle(), and updateTranslations().

66  {
67  if (!$this->isConfigured($lang_key)) {
68  return null;
69  }
70  return $this->translations[$lang_key];
71  }
Class ilAdvancedMDRecordTranslation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTranslations()

ilAdvancedMDRecordTranslations::getTranslations ( )

array<string, ilAdvancedMDRecordTranslation>

Definition at line 76 of file class.ilAdvancedMDRecordTranslations.php.

References $translations.

Referenced by cloneRecord(), getDefaultTranslation(), toXML(), and updateDefault().

+ Here is the caller graph for this function:

◆ isConfigured()

ilAdvancedMDRecordTranslations::isConfigured ( string  $lang_key)

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

Referenced by getTranslation().

60  : bool
61  {
62  return isset($this->translations[$lang_key]);
63  }
+ Here is the caller graph for this function:

◆ modifyTranslationInfoForDescription()

ilAdvancedMDRecordTranslations::modifyTranslationInfoForDescription ( ilPropertyFormGUI  $form,
ilTextAreaInputGUI  $description,
string  $active_language 
)

Definition at line 179 of file class.ilAdvancedMDRecordTranslations.php.

References getDefaultTranslation(), getTranslation(), ilFormPropertyGUI\setInfo(), and ilTextAreaInputGUI\setValue().

183  : void {
184  if (count($this->translations) <= 1) {
185  return;
186  }
187  $default = $this->getDefaultTranslation();
188  if ($default->getLangKey() != $active_language) {
189  $description->setInfo($default->getLangKey() . ': ' . $default->getDescription());
190  }
191  if ($this->getTranslation($active_language) instanceof ilAdvancedMDRecordTranslation) {
192  $description->setValue($this->getTranslation($active_language)->getDescription());
193  }
194  }
Class ilAdvancedMDRecordTranslation.
+ Here is the call graph for this function:

◆ modifyTranslationInfoForTitle()

ilAdvancedMDRecordTranslations::modifyTranslationInfoForTitle ( ilPropertyFormGUI  $form,
ilTextInputGUI  $title,
string  $active_language 
)

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

References getDefaultTranslation(), getTranslation(), ilFormPropertyGUI\setInfo(), and ilTextInputGUI\setValue().

166  : void {
167  if (count($this->translations) <= 1) {
168  return;
169  }
170  $default = $this->getDefaultTranslation();
171  if ($default->getLangKey() != $active_language) {
172  $title->setInfo($default->getLangKey() . ': ' . $default->getTitle());
173  }
174  if ($this->getTranslation($active_language) instanceof ilAdvancedMDRecordTranslation) {
175  $title->setValue($this->getTranslation($active_language)->getTitle());
176  }
177  }
Class ilAdvancedMDRecordTranslation.
+ Here is the call graph for this function:

◆ read()

ilAdvancedMDRecordTranslations::read ( )
private

Definition at line 99 of file class.ilAdvancedMDRecordTranslations.php.

References $query, $res, ilAdvancedMDRecord\_getInstanceByRecordId(), ilDBConstants\FETCHMODE_OBJECT, getRecordId(), ilDBConstants\T_INTEGER, and ilAdvancedMDRecordTranslation\TABLE_NAME.

Referenced by __construct().

99  : void
100  {
101  $query = 'select * from ' . ilAdvancedMDRecordTranslation::TABLE_NAME . ' ' .
102  'where record_id = ' . $this->db->quote($this->getRecordId(), ilDBConstants::T_INTEGER);
103  $res = $this->db->query($query);
104 
105  $this->translations = [];
106  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
107  $this->translations[(string) $row->lang_code] = new ilAdvancedMDRecordTranslation(
108  (int) $row->record_id,
109  (string) $row->title,
110  (string) $row->description,
111  (string) $row->lang_code
112  );
113  }
114 
115  $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id);
116  $this->default_language = $this->record->getDefaultLanguage();
117  }
$res
Definition: ltiservices.php:69
static _getInstanceByRecordId(int $a_record_id)
Class ilAdvancedMDRecordTranslation.
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

ilAdvancedMDRecordTranslations::toXML ( ilXmlWriter  $writer)

Definition at line 223 of file class.ilAdvancedMDRecordTranslations.php.

References getDefaultLanguage(), getTranslations(), ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

223  : ilXmlWriter
224  {
225  if (!count($this->getTranslations())) {
226  return $writer;
227  }
228 
229  $writer->xmlStartTag(
230  'RecordTranslations',
231  [
232  'defaultLanguage' => $this->getDefaultLanguage()
233  ]
234  );
235  foreach ($this->getTranslations() as $translation) {
236  $writer->xmlStartTag(
237  'RecordTranslation',
238  [
239  'language' => $translation->getLangKey()
240  ]
241  );
242  $writer->xmlElement('RecordTranslationTitle', [], $translation->getTitle());
243  $writer->xmlElement('RecordTranslationDescription', [], $translation->getDescription());
244  $writer->xmlEndTag('RecordTranslation');
245  }
246  $writer->xmlEndTag('RecordTranslations');
247  return $writer;
248  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTranslations()
array<string, ilAdvancedMDRecordTranslation>
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
+ Here is the call graph for this function:

◆ updateDefault()

ilAdvancedMDRecordTranslations::updateDefault ( string  $default)

Definition at line 131 of file class.ilAdvancedMDRecordTranslations.php.

References getTranslations().

131  : void
132  {
133  foreach ($this->getTranslations() as $translation) {
134  if ($translation->getLangKey() != $default) {
135  $translation->setLangDefault(false);
136  $translation->update();
137  }
138  if ($translation->getLangKey() == $default) {
139  $translation->setLangDefault(true);
140  $translation->update();
141  }
142  }
143  }
getTranslations()
array<string, ilAdvancedMDRecordTranslation>
+ Here is the call graph for this function:

◆ updateTranslations()

ilAdvancedMDRecordTranslations::updateTranslations ( string  $active_language,
string  $title,
string  $description 
)

Definition at line 196 of file class.ilAdvancedMDRecordTranslations.php.

References getTranslation().

196  : void
197  {
198  $translation = $this->getTranslation($active_language);
199  if (!$translation instanceof ilAdvancedMDRecordTranslation) {
200  return;
201  }
202  $translation->setTitle($title);
203  $translation->setDescription($description);
204  $translation->update();
205  }
Class ilAdvancedMDRecordTranslation.
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilAdvancedMDRecordTranslations::$db
private

Definition at line 27 of file class.ilAdvancedMDRecordTranslations.php.

◆ $default_language

string ilAdvancedMDRecordTranslations::$default_language = ''
private

◆ $instances

ilAdvancedMDRecordTranslations::$instances = null
staticprivate

Definition at line 15 of file class.ilAdvancedMDRecordTranslations.php.

◆ $lng

ilLanguage ilAdvancedMDRecordTranslations::$lng
private

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

◆ $record

ilAdvancedMDRecord ilAdvancedMDRecordTranslations::$record
private

Definition at line 18 of file class.ilAdvancedMDRecordTranslations.php.

◆ $record_id

int ilAdvancedMDRecordTranslations::$record_id
private

◆ $translations

ilAdvancedMDRecordTranslations::$translations = []
private

Definition at line 23 of file class.ilAdvancedMDRecordTranslations.php.

Referenced by getTranslations().


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