ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilAdvancedMDFieldTranslations Class Reference

Class ilAdvancedMDFieldTranslations. More...

+ Collaboration diagram for ilAdvancedMDFieldTranslations:

Public Member Functions

 getRecordId ()
 
 getDefaultLanguage ()
 
 getActivatedLanguages (int $field_id, bool $with_default=true)
 
 isConfigured (int $field_id, string $lang_key)
 
 getTranslation (int $field_id, string $lang_key)
 
 getTranslations (int $field_id)
 
 getDefaultTranslation (int $field_id)
 
 read ()
 
 getFormTranslationInfo (int $field_id, string $active_language)
 
 modifyTranslationInfoForTitle (int $field_id, ilPropertyFormGUI $form, ilTextInputGUI $title, string $active_language)
 
 modifyTranslationInfoForDescription (int $field_id, ilPropertyFormGUI $form, ilTextAreaInputGUI $description, string $active_language)
 
 updateFromForm (int $field_id, string $active_language, ilPropertyFormGUI $form)
 
 getTitleForLanguage (int $field_id, string $language)
 
 getDescriptionForLanguage (int $field_id, string $language)
 

Static Public Member Functions

static getInstanceByRecordId (int $record_id)
 

Private Member Functions

 __construct (int $record_id)
 

Private Attributes

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

Static Private Attributes

static array $instances = []
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDFieldTranslations::__construct ( int  $record_id)
private

Definition at line 57 of file class.ilAdvancedMDFieldTranslations.php.

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

58  {
59  global $DIC;
60 
61  $this->db = $DIC->database();
62  $this->lng = $DIC->language();
63  $this->lng->loadLanguageModule('meta');
64 
65  $this->record_id = $record_id;
66  $this->record_translations = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record_id);
67  $this->read();
68  }
global $DIC
Definition: shib_login.php:26
+ Here is the call graph for this function:

Member Function Documentation

◆ getActivatedLanguages()

ilAdvancedMDFieldTranslations::getActivatedLanguages ( int  $field_id,
bool  $with_default = true 
)
Parameters
int$field_id
bool$with_default
Returns
array<int, string>

Definition at line 93 of file class.ilAdvancedMDFieldTranslations.php.

References getTranslations().

93  : array
94  {
95  $activated = [];
96  foreach ($this->getTranslations($field_id) as $language => $translation) {
97  if ($language == self::getDefaultLanguage() && !$with_default) {
98  continue;
99  }
100  $activated[] = $language;
101  }
102  return $activated;
103  }
+ Here is the call graph for this function:

◆ getDefaultLanguage()

ilAdvancedMDFieldTranslations::getDefaultLanguage ( )

◆ getDefaultTranslation()

ilAdvancedMDFieldTranslations::getDefaultTranslation ( int  $field_id)
Returns
ilAdvancedMDRecordTranslation | null

Definition at line 135 of file class.ilAdvancedMDFieldTranslations.php.

References $default_language, getTranslations(), and null.

Referenced by modifyTranslationInfoForDescription(), and modifyTranslationInfoForTitle().

136  {
137  foreach ($this->getTranslations($field_id) as $translation) {
138  if ($translation->getLangKey() == $this->default_language) {
139  return $translation;
140  }
141  }
142  return null;
143  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Class ilAdvancedMDFieldTranslation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDescriptionForLanguage()

ilAdvancedMDFieldTranslations::getDescriptionForLanguage ( int  $field_id,
string  $language 
)

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

References getDefaultLanguage(), and getTranslation().

261  : string
262  {
263  if ($this->getTranslation($field_id, $language) && strlen($this->getTranslation(
264  $field_id,
265  $language
266  )->getDescription())) {
267  return $this->getTranslation($field_id, $language)->getDescription();
268  }
269  if ($this->getTranslation($field_id, $this->getDefaultLanguage()) &&
270  strlen($this->getTranslation($field_id, $this->getDefaultLanguage())->getDescription())
271  ) {
272  return $this->getTranslation($field_id, $this->getDefaultLanguage())->getDescription();
273  }
274  if ($this->definitions[$field_id] instanceof ilAdvancedMDFieldDefinition) {
275  return $this->definitions[$field_id]->getDescription();
276  }
277  return '';
278  }
getTranslation(int $field_id, string $lang_key)
+ Here is the call graph for this function:

◆ getFormTranslationInfo()

ilAdvancedMDFieldTranslations::getFormTranslationInfo ( int  $field_id,
string  $active_language 
)

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

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

174  : string
175  {
176  if (count($this->getTranslations($field_id)) <= 1) {
177  return '';
178  }
179 
180  $txt = '';
181  $txt = $this->lng->txt('md_adv_int_current') . ' ' . $this->lng->txt('meta_l_' . $active_language);
182  $txt .= ', ';
183  foreach ($this->getTranslations($field_id) as $translation) {
184  if ($translation->getLangKey() == $this->getDefaultLanguage()) {
185  $txt .= ($this->lng->txt('md_adv_int_default') . ' ' . $this->lng->txt('meta_l_' . $translation->getLangKey()));
186  break;
187  }
188  }
189  return $txt;
190  }
$txt
Definition: error.php:31
+ Here is the call graph for this function:

◆ getInstanceByRecordId()

◆ getRecordId()

ilAdvancedMDFieldTranslations::getRecordId ( )

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

References $record_id.

Referenced by read().

78  : int
79  {
80  return $this->record_id;
81  }
+ Here is the caller graph for this function:

◆ getTitleForLanguage()

ilAdvancedMDFieldTranslations::getTitleForLanguage ( int  $field_id,
string  $language 
)

Definition at line 241 of file class.ilAdvancedMDFieldTranslations.php.

References getDefaultLanguage(), ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), and getTranslation().

Referenced by ILIAS\Cache\Services\SubObjectModes\DataTable\Supplier\initColumn(), and ILIAS\Cache\Services\SubObjectModes\Filter\Supplier\initFilterInput().

241  : string
242  {
243  if ($this->getTranslation($field_id, $language) && strlen($this->getTranslation(
244  $field_id,
245  $language
246  )->getTitle())) {
247  return $this->getTranslation($field_id, $language)->getTitle();
248  }
249  if (
250  $this->getTranslation($field_id, $this->getDefaultLanguage()) &&
251  strlen(($this->getTranslation($field_id, $this->getDefaultLanguage())->getTitle()))
252  ) {
253  return $this->getTranslation($field_id, $this->getDefaultLanguage())->getTitle();
254  }
255  if ($this->definitions[$field_id] instanceof ilAdvancedMDFieldDefinition) {
256  return $this->definitions[$field_id]->getTitle();
257  }
258  return '';
259  }
getTranslation(int $field_id, string $lang_key)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTranslation()

ilAdvancedMDFieldTranslations::getTranslation ( int  $field_id,
string  $lang_key 
)

Definition at line 113 of file class.ilAdvancedMDFieldTranslations.php.

References isConfigured(), and null.

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

114  {
115  if (!$this->isConfigured($field_id, $lang_key)) {
116  return null;
117  }
118  return $this->translations[$field_id][$lang_key];
119  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isConfigured(int $field_id, string $lang_key)
Class ilAdvancedMDFieldTranslation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTranslations()

ilAdvancedMDFieldTranslations::getTranslations ( int  $field_id)
Returns
array<string, ilAdvancedMDFieldTranslation>

Definition at line 124 of file class.ilAdvancedMDFieldTranslations.php.

Referenced by getActivatedLanguages(), getDefaultTranslation(), and getFormTranslationInfo().

124  : array
125  {
126  if (isset($this->translations[$field_id])) {
127  return $this->translations[$field_id];
128  }
129  return [];
130  }
+ Here is the caller graph for this function:

◆ isConfigured()

ilAdvancedMDFieldTranslations::isConfigured ( int  $field_id,
string  $lang_key 
)

Definition at line 105 of file class.ilAdvancedMDFieldTranslations.php.

Referenced by getTranslation().

105  : bool
106  {
107  if (!$this->record_translations->isConfigured($lang_key)) {
108  return false;
109  }
110  return isset($this->translations[$field_id][$lang_key]);
111  }
+ Here is the caller graph for this function:

◆ modifyTranslationInfoForDescription()

ilAdvancedMDFieldTranslations::modifyTranslationInfoForDescription ( int  $field_id,
ilPropertyFormGUI  $form,
ilTextAreaInputGUI  $description,
string  $active_language 
)

Definition at line 211 of file class.ilAdvancedMDFieldTranslations.php.

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

216  : void {
217  if (!strlen($active_language)) {
218  return;
219  }
220  $show_info = ($active_language !== $this->getDefaultLanguage() && $this->getDefaultLanguage());
221  $default = $this->getDefaultTranslation($field_id);
222  if ($default instanceof ilAdvancedMDFieldTranslation && $show_info) {
223  $description->setInfo($default->getLangKey() . ': ' . $default->getDescription());
224  }
225  if ($this->getTranslation($field_id, $active_language) instanceof ilAdvancedMDFieldTranslation) {
226  $description->setValue($this->getTranslation($field_id, $active_language)->getDescription());
227  }
228  }
getTranslation(int $field_id, string $lang_key)
Class ilAdvancedMDFieldTranslation.
+ Here is the call graph for this function:

◆ modifyTranslationInfoForTitle()

ilAdvancedMDFieldTranslations::modifyTranslationInfoForTitle ( int  $field_id,
ilPropertyFormGUI  $form,
ilTextInputGUI  $title,
string  $active_language 
)

Definition at line 192 of file class.ilAdvancedMDFieldTranslations.php.

References getDefaultLanguage(), getDefaultTranslation(), ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), getTranslation(), ilFormPropertyGUI\setInfo(), and ilTextInputGUI\setValue().

197  : void {
198  if (!strlen($active_language)) {
199  return;
200  }
201  $show_info = ($active_language !== $this->getDefaultLanguage() && $this->getDefaultLanguage());
202  $default = $this->getDefaultTranslation($field_id);
203  if ($default instanceof ilAdvancedMDFieldTranslation && $show_info) {
204  $title->setInfo($default->getLangKey() . ': ' . $default->getTitle());
205  }
206  if ($this->getTranslation($field_id, $active_language) instanceof ilAdvancedMDFieldTranslation) {
207  $title->setValue($this->getTranslation($field_id, $active_language)->getTitle());
208  }
209  }
getTranslation(int $field_id, string $lang_key)
Class ilAdvancedMDFieldTranslation.
+ Here is the call graph for this function:

◆ read()

ilAdvancedMDFieldTranslations::read ( )

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

References $res, ilAdvancedMDRecord\_getInstanceByRecordId(), ilDBConstants\FETCHMODE_OBJECT, ilAdvancedMDFieldDefinition\getInstancesByRecordId(), getRecordId(), ILIAS\Repository\int(), null, and ilDBConstants\T_INTEGER.

Referenced by __construct().

145  : void
146  {
147  $query = 'select fi.field_id tfield, de.field_id ofield, fi.title, fi.description, ri.lang_code ' .
148  'from adv_md_record_int ri join adv_mdf_definition de on ri.record_id = de.record_id ' .
149  'left join adv_md_field_int fi on (ri.lang_code = fi.lang_code and de.field_id = fi.field_id) ' .
150  'where ri.record_id = ' . $this->db->quote($this->getRecordId(), ilDBConstants::T_INTEGER);
151  $res = $this->db->query($query);
152 
153  $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id);
154  $this->default_language = $this->record->getDefaultLanguage();
155 
156  $this->translations = [];
157  $this->definitions = ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->record_id, false);
158  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
159  $this->translations[$row->ofield][$row->lang_code] = new ilAdvancedMDFieldTranslation(
160  (int) $row->ofield,
161  (string) $row->title,
162  (string) $row->description,
163  (string) $row->lang_code
164  );
165  if ((string) $row->lang_code == $this->default_language && $row->tfield == null) {
166  $this->translations[(int) $row->ofield][(string) $row->lang_code]->setTitle($this->definitions[(int) $row->ofield]->getTitle());
167  $this->translations[(int) $row->ofield][(string) $row->lang_code]->setDescription(
168  $this->definitions[(int) $row->ofield]->getDescription()
169  );
170  }
171  }
172  }
$res
Definition: ltiservices.php:66
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _getInstanceByRecordId(int $a_record_id)
Class ilAdvancedMDFieldTranslation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateFromForm()

ilAdvancedMDFieldTranslations::updateFromForm ( int  $field_id,
string  $active_language,
ilPropertyFormGUI  $form 
)

Definition at line 230 of file class.ilAdvancedMDFieldTranslations.php.

References ilPropertyFormGUI\getInput(), and getTranslation().

230  : void
231  {
232  $translation = $this->getTranslation($field_id, $active_language);
233  if (!$translation instanceof ilAdvancedMDFieldTranslation) {
234  return;
235  }
236  $translation->setTitle($form->getInput('title'));
237  $translation->setDescription($form->getInput('description'));
238  $translation->update();
239  }
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getTranslation(int $field_id, string $lang_key)
Class ilAdvancedMDFieldTranslation.
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilAdvancedMDFieldTranslations::$db
private

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

◆ $default_language

string ilAdvancedMDFieldTranslations::$default_language = ''
private

◆ $definitions

array ilAdvancedMDFieldTranslations::$definitions
private

Definition at line 37 of file class.ilAdvancedMDFieldTranslations.php.

◆ $instances

array ilAdvancedMDFieldTranslations::$instances = []
staticprivate

Definition at line 29 of file class.ilAdvancedMDFieldTranslations.php.

◆ $lng

ilLanguage ilAdvancedMDFieldTranslations::$lng
private

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

◆ $record

ilAdvancedMDRecord ilAdvancedMDFieldTranslations::$record
private

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

◆ $record_id

int ilAdvancedMDFieldTranslations::$record_id
private

◆ $record_translations

ilAdvancedMDRecordTranslations ilAdvancedMDFieldTranslations::$record_translations
private

Definition at line 44 of file class.ilAdvancedMDFieldTranslations.php.

◆ $translations

array ilAdvancedMDFieldTranslations::$translations = []
private

Definition at line 42 of file class.ilAdvancedMDFieldTranslations.php.


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