ILIAS  release_7 Revision v7.30-3-g800a261c036
ilAdvancedMDRecordTranslations Class Reference

Class ilAdvancedMDRecordTranslation. More...

+ Collaboration diagram for ilAdvancedMDRecordTranslations:

Public Member Functions

 getDefaultLanguage ()
 
 getRecordId ()
 
 isConfigured (string $lang_key)
 
 getTranslation (string $lang_key)
 
 getTranslations ()
 
 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

 $record_id
 
 $record
 
 $translations = []
 
 $default_language = ''
 
 $db
 
 $lng
 

Static Private Attributes

static $instances = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDRecordTranslations::__construct ( int  $record_id)
private

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

References $DIC, $record_id, and read().

47  {
48  global $DIC;
49 
50  $this->db = $DIC->database();
51  $this->lng = $DIC->language();
52  $this->lng->loadLanguageModule('meta');
53 
54  $this->record_id = $record_id;
55  $this->read();
56  }
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:

Member Function Documentation

◆ addTranslationEntry()

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

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

157  {
158  $this->translations[$language_code] = new ilAdvancedMDRecordTranslation(
159  $this->record_id,
160  '',
161  '',
162  $language_code,
163  $default
164  );
165  $this->translations[$language_code]->insert();
166  }
Class ilAdvancedMDRecordTranslation.

◆ cloneRecord()

ilAdvancedMDRecordTranslations::cloneRecord ( int  $new_record_id)

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

References getTranslations().

129  {
130  foreach ($this->getTranslations() as $recordTranslation) {
131  $recordTranslation->setRecordId($new_record_id);
132  $recordTranslation->insert();
133  }
134  }
+ Here is the call graph for this function:

◆ getDefaultLanguage()

ilAdvancedMDRecordTranslations::getDefaultLanguage ( )
Returns
string

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

References $default_language.

Referenced by toXML().

+ Here is the caller graph for this function:

◆ getDefaultTranslation()

ilAdvancedMDRecordTranslations::getDefaultTranslation ( )
Returns
ilAdvancedMDRecordTranslation|null

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

References $default_language, and getTranslations().

Referenced by modifyTranslationInfoForDescription(), and modifyTranslationInfoForTitle().

119  {
120  foreach ($this->getTranslations() as $translation) {
121  if ($translation->getLangKey() == $this->default_language) {
122  return $translation;
123  }
124  }
125  return null;
126  }
Class ilAdvancedMDRecordTranslation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDescriptionForLanguage()

ilAdvancedMDRecordTranslations::getDescriptionForLanguage ( string  $language)
Parameters
string$language
Returns
string

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

References getTranslation().

273  {
274  if ($this->getTranslation($language) && strlen($this->getTranslation($language)->getDescription())) {
275  return $this->getTranslation($language)->getDescription();
276  }
277  return $this->record->getDescription();
278  }
+ Here is the call graph for this function:

◆ getFormTranslationInfo()

ilAdvancedMDRecordTranslations::getFormTranslationInfo ( string  $active_language)
Returns
string

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

References $default_language, and $txt.

188  : string
189  {
190  if (count($this->translations) <= 1) {
191  return '';
192  }
193  $txt = '';
194  $txt = $this->lng->txt('md_adv_int_current'). ' ' . $this->lng->txt('meta_l_' . $active_language);
195  $txt .= ', ';
196  foreach ($this->translations as $translation) {
197  if ($translation->getLangKey() == $this->default_language) {
198  $txt .= ($this->lng->txt('md_adv_int_default') . ' ' . $this->lng->txt('meta_l_' . $translation->getLangKey()));
199  break;
200  }
201  }
202  return $txt;
203  }
$txt
Definition: error.php:13

◆ getInstanceByRecordId()

◆ getRecordId()

ilAdvancedMDRecordTranslations::getRecordId ( )
Returns
int

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

References $record_id.

Referenced by read().

+ Here is the caller graph for this function:

◆ getTitleForLanguage()

ilAdvancedMDRecordTranslations::getTitleForLanguage ( string  $language)
Parameters
string$language
Returns
string

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

References getTranslation().

262  {
263  if ($this->getTranslation($language) && strlen($this->getTranslation($language)->getTitle())) {
264  return $this->getTranslation($language)->getTitle();
265  }
266  return $this->record->getTitle();
267  }
+ Here is the call graph for this function:

◆ getTranslation()

ilAdvancedMDRecordTranslations::getTranslation ( string  $lang_key)
Parameters
string$lang_key
Returns
ilAdvancedMDRecordTranslation|null

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

References isConfigured().

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

100  {
101  if (!$this->isConfigured($lang_key)) {
102  return null;
103  }
104  return $this->translations[$lang_key];
105  }
Class ilAdvancedMDRecordTranslation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTranslations()

ilAdvancedMDRecordTranslations::getTranslations ( )
Returns
ilAdvancedMDRecordTranslation[]

Definition at line 110 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)
Parameters
string$lang_key
Returns
bool

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

Referenced by getTranslation().

91  {
92  return isset($this->translations[$lang_key]);
93  }
+ Here is the caller graph for this function:

◆ modifyTranslationInfoForDescription()

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

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

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

228  {
229  if (count($this->translations) <= 1) {
230  return;
231  }
232  $default = $this->getDefaultTranslation();
233  if ($default->getLangKey() != $active_language) {
234  $description->setInfo($default->getLangKey() . ': ' . $default->getDescription());
235  }
236  if ($this->getTranslation($active_language) instanceof ilAdvancedMDRecordTranslation) {
237  $description->setValue($this->getTranslation($active_language)->getDescription());
238  }
239  }
setValue($a_value)
Set Value.
setInfo($a_info)
Set Information Text.
Class ilAdvancedMDRecordTranslation.
+ Here is the call graph for this function:

◆ modifyTranslationInfoForTitle()

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

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

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

210  {
211  if (count($this->translations) <= 1) {
212  return;
213  }
214  $default = $this->getDefaultTranslation();
215  if ($default->getLangKey() != $active_language) {
216  $title->setInfo($default->getLangKey() . ': ' . $default->getTitle());
217  }
218  if ($this->getTranslation($active_language) instanceof ilAdvancedMDRecordTranslation) {
219  $title->setValue($this->getTranslation($active_language)->getTitle());
220  }
221  }
setInfo($a_info)
Set Information Text.
Class ilAdvancedMDRecordTranslation.
setValue($a_value)
Set Value.
+ Here is the call graph for this function:

◆ read()

ilAdvancedMDRecordTranslations::read ( )
private

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

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

Referenced by __construct().

137  {
138  $query = 'select * from ' . ilAdvancedMDRecordTranslation::TABLE_NAME . ' ' .
139  'where record_id = ' . $this->db->quote($this->getRecordId(), ilDBConstants::T_INTEGER);
140  $res = $this->db->query($query);
141 
142  $this->translations = [];
143  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
144  $this->translations[$row->lang_code] = new ilAdvancedMDRecordTranslation(
145  (int) $row->record_id,
146  (string) $row->title,
147  (string) $row->description,
148  (string) $row->lang_code
149  );
150  }
151 
152  $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id);
153  $this->default_language = $this->record->getDefaultLanguage();
154  }
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
foreach($_POST as $key=> $value) $res
Class ilAdvancedMDRecordTranslation.
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

ilAdvancedMDRecordTranslations::toXML ( ilXmlWriter  $writer)
Parameters
ilXmlWriter$writer
Returns
ilXmlWriter

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

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

284  : ilXmlWriter
285  {
286  if (!count($this->getTranslations())) {
287  return $writer;
288  }
289 
290  $writer->xmlStartTag(
291  'RecordTranslations',
292  [
293  'defaultLanguage' => $this->getDefaultLanguage()
294  ]
295  );
296  foreach ($this->getTranslations() as $translation) {
297  $writer->xmlStartTag(
298  'RecordTranslation',
299  [
300  'language' => $translation->getLangKey()
301  ]
302  );
303  $writer->xmlElement('RecordTranslationTitle', [], $translation->getTitle());
304  $writer->xmlElement('RecordTranslationDescription', [], $translation->getDescription());
305  $writer->xmlEndTag('RecordTranslation');
306  }
307  $writer->xmlEndTag('RecordTranslations');
308  return $writer;
309  }
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlElement($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 171 of file class.ilAdvancedMDRecordTranslations.php.

References getTranslations().

172  {
173  foreach ($this->getTranslations() as $translation) {
174  if ($translation->getLangKey() != $default) {
175  $translation->setLangDefault(false);
176  $translation->update();
177  }
178  if ($translation->getLangKey() == $default) {
179  $translation->setLangDefault(true);
180  $translation->update();
181  }
182  }
183  }
+ Here is the call graph for this function:

◆ updateTranslations()

ilAdvancedMDRecordTranslations::updateTranslations ( string  $active_language,
string  $title,
string  $description 
)
Parameters
ilPropertyFormGUI$form
string$active_language
Returns
bool

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

References getTranslation().

247  {
248  $translation = $this->getTranslation($active_language);
249  if (!$translation instanceof ilAdvancedMDRecordTranslation) {
250  return false;
251  }
252  $translation->setTitle($title);
253  $translation->setDescription($description);
254  $translation->update();
255  }
Class ilAdvancedMDRecordTranslation.
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilAdvancedMDRecordTranslations::$db
private

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

◆ $default_language

ilAdvancedMDRecordTranslations::$default_language = ''
private

◆ $instances

ilAdvancedMDRecordTranslations::$instances = null
staticprivate

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

◆ $lng

ilAdvancedMDRecordTranslations::$lng
private

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

◆ $record

ilAdvancedMDRecordTranslations::$record
private

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

◆ $record_id

ilAdvancedMDRecordTranslations::$record_id
private

◆ $translations

ilAdvancedMDRecordTranslations::$translations = []
private

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

Referenced by getTranslations().


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