ILIAS  release_7 Revision v7.30-3-g800a261c036
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)
 
 updateTranslations (string $active_language, string $title, string $description)
 
 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

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

Static Private Attributes

static $instances = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDFieldTranslations::__construct ( int  $record_id)
private

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

59 {
60 global $DIC;
61
62 $this->db = $DIC->database();
63 $this->lng = $DIC->language();
64 $this->lng->loadLanguageModule('meta');
65
66 $this->record_id = $record_id;
67 $this->record_translations = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record_id);
68 $this->read();
69 }
global $DIC
Definition: goto.php:24

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

+ Here is the call graph for this function:

Member Function Documentation

◆ getActivatedLanguages()

ilAdvancedMDFieldTranslations::getActivatedLanguages ( int  $field_id,
bool  $with_default = true 
)

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

101 {
102 $activated = [];
103 foreach ($this->getTranslations($field_id) as $language => $translation)
104 {
105 if ($language == self::getDefaultLanguage() && !$with_default) {
106 continue;
107 }
108 $activated[] = $language;
109 }
110 return $activated;
111 }

References getTranslations().

+ Here is the call graph for this function:

◆ getDefaultLanguage()

ilAdvancedMDFieldTranslations::getDefaultLanguage ( )
Returns
string

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

References $default_language.

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

+ Here is the caller graph for this function:

◆ getDefaultTranslation()

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

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

155 {
156 foreach ($this->getTranslations($field_id) as $translation) {
157 if ($translation->getLangKey() == $this->default_language) {
158 return $translation;
159 }
160 }
161 return null;
162 }
Class ilAdvancedMDFieldTranslation.

References getTranslations().

Referenced by modifyTranslationInfoForDescription(), and modifyTranslationInfoForTitle().

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

◆ getDescriptionForLanguage()

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

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

311 {
312 if ($this->getTranslation($field_id, $language) && strlen($this->getTranslation($field_id, $language)->getDescription())) {
313 return $this->getTranslation($field_id, $language)->getDescription();
314 }
315 if ($this->getTranslation($field_id, $this->getDefaultLanguage()) &&
316 strlen($this->getTranslation($field_id, $this->getDefaultLanguage())->getDescription())
317 ) {
318 return $this->getTranslation($field_id, $this->getDefaultLanguage())->getDescription();
319 }
320 if ($this->definitions[$field_id] instanceof ilAdvancedMDFieldDefinition) {
321 return $this->definitions[$field_id]->getDescription();
322 }
323 return '';
324 }
getTranslation(int $field_id, string $lang_key)

References getDefaultLanguage(), and getTranslation().

+ Here is the call graph for this function:

◆ getFormTranslationInfo()

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

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

197 : string
198 {
199 if (count($this->getTranslations($field_id)) <= 1) {
200 return '';
201 }
202
203 $txt = '';
204 $txt = $this->lng->txt('md_adv_int_current'). ' ' . $this->lng->txt('meta_l_' . $active_language);
205 $txt .= ', ';
206 foreach ($this->getTranslations($field_id) as $translation) {
207 if ($translation->getLangKey() == $this->getDefaultLanguage()) {
208 $txt .= ($this->lng->txt('md_adv_int_default') . ' ' . $this->lng->txt('meta_l_' . $translation->getLangKey()));
209 break;
210 }
211 }
212 return $txt;
213 }
$txt
Definition: error.php:13

References $txt, and getTranslations().

+ Here is the call graph for this function:

◆ getInstanceByRecordId()

◆ getRecordId()

ilAdvancedMDFieldTranslations::getRecordId ( )
Returns
int

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

86 : int
87 {
88 return $this->record_id;
89 }

References $record_id.

Referenced by read().

+ Here is the caller graph for this function:

◆ getTitleForLanguage()

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

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

290 : string
291 {
292 if ($this->getTranslation($field_id, $language) && strlen($this->getTranslation($field_id, $language)->getTitle())) {
293 return $this->getTranslation($field_id, $language)->getTitle();
294 }
295 if (
296 $this->getTranslation($field_id, $this->getDefaultLanguage()) &&
297 strlen(($this->getTranslation($field_id, $this->getDefaultLanguage())->getTitle()))
298 ) {
299 return $this->getTranslation($field_id, $this->getDefaultLanguage())->getTitle();
300 }
301 if ($this->definitions[$field_id] instanceof ilAdvancedMDFieldDefinition) {
302 return $this->definitions[$field_id]->getTitle();
303 }
304 return '';
305 }

References getDefaultLanguage(), and getTranslation().

+ Here is the call graph for this function:

◆ getTranslation()

ilAdvancedMDFieldTranslations::getTranslation ( int  $field_id,
string  $lang_key 
)
Parameters
string$lang_key
Returns
ilAdvancedMDRecordTranslation|null

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

133 {
134 if (!$this->isConfigured($field_id, $lang_key)) {
135 return null;
136 }
137 return $this->translations[$field_id][$lang_key];
138 }
isConfigured(int $field_id, string $lang_key)

References isConfigured().

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

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

◆ getTranslations()

ilAdvancedMDFieldTranslations::getTranslations ( int  $field_id)
Returns
ilAdvancedMDFieldTranslation[]

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

144 {
145 if (isset($this->translations[$field_id])) {
146 return $this->translations[$field_id];
147 }
148 return [];
149 }

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

+ Here is the caller graph for this function:

◆ isConfigured()

ilAdvancedMDFieldTranslations::isConfigured ( int  $field_id,
string  $lang_key 
)
Parameters
int$field_id
string$lang_key
Returns
bool

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

120 {
121 if (!$this->record_translations->isConfigured($lang_key)) {
122 return false;
123 }
124 return isset($this->translations[$field_id][$lang_key]);
125 }

Referenced by getTranslation().

+ Here is the caller graph for this function:

◆ modifyTranslationInfoForDescription()

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

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

239 {
240 if (!strlen($active_language)) {
241 return;
242 }
243 $show_info = ($active_language !== $this->getDefaultLanguage() && $this->getDefaultLanguage());
244 $default = $this->getDefaultTranslation($field_id);
245 if ($default instanceof ilAdvancedMDFieldTranslation && $show_info) {
246 $description->setInfo($default->getLangKey() . ': ' . $default->getDescription());
247 }
248 if ($this->getTranslation($field_id, $active_language) instanceof ilAdvancedMDFieldTranslation) {
249 $description->setValue($this->getTranslation($field_id, $active_language)->getDescription());
250 }
251 }
setInfo($a_info)
Set Information Text.
setValue($a_value)
Set Value.

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

+ Here is the call graph for this function:

◆ modifyTranslationInfoForTitle()

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

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

220 {
221 if (!strlen($active_language)) {
222 return;
223 }
224 $show_info = ($active_language !== $this->getDefaultLanguage() && $this->getDefaultLanguage());
225 $default = $this->getDefaultTranslation($field_id);
226 if ($default instanceof ilAdvancedMDFieldTranslation && $show_info) {
227 $title->setInfo($default->getLangKey() . ': ' . $default->getTitle());
228 }
229 if ($this->getTranslation($field_id, $active_language) instanceof ilAdvancedMDFieldTranslation) {
230 $title->setValue($this->getTranslation($field_id, $active_language)->getTitle());
231 }
232 }
setValue($a_value)
Set Value.

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

+ Here is the call graph for this function:

◆ read()

ilAdvancedMDFieldTranslations::read ( )

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

165 {
166 $query = 'select fi.field_id tfield, de.field_id ofield, fi.title, fi.description, ri.lang_code ' .
167 'from adv_md_record_int ri join adv_mdf_definition de on ri.record_id = de.record_id ' .
168 'left join adv_md_field_int fi on (ri.lang_code = fi.lang_code and de.field_id = fi.field_id) ' .
169 'where ri.record_id = ' . $this->db->quote($this->getRecordId(), ilDBConstants::T_INTEGER);
170 $res = $this->db->query($query);
171
172 $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id);
173 $this->default_language = $this->record->getDefaultLanguage();
174
175 $this->translations = [];
176 $this->definitions = ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->record_id, false);
177 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
178 $this->translations[$row->ofield][$row->lang_code] = new ilAdvancedMDFieldTranslation(
179 (int) $row->ofield,
180 (string) $row->title,
181 (string) $row->description,
182 (string) $row->lang_code
183 );
184 if (
185 $row->lang_code == $this->default_language &&
186 $row->tfield == null
187 ) {
188 $this->translations[$row->ofield][$row->lang_code]->setTitle($this->definitions[$row->ofield]->getTitle());
189 $this->translations[$row->ofield][$row->lang_code]->setDescription((string) $this->definitions[$row->ofield]->getDescription());
190 }
191 }
192 }
static getInstancesByRecordId($a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
$query
foreach($_POST as $key=> $value) $res

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

Referenced by __construct().

+ 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 
)
Parameters
int$field_id
string$active_language
ilPropertyFormGUI$form

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

259 {
260 $translation = $this->getTranslation($field_id, $active_language);
261 if (!$translation instanceof ilAdvancedMDFieldTranslation) {
262 return;
263 }
264 $translation->setTitle($form->getInput('title'));
265 $translation->setDescription($form->getInput('description'));
266 $translation->update();
267 return;
268 }
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.

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

+ Here is the call graph for this function:

◆ updateTranslations()

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

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

276 {
277 $translation = $this->getTranslation($active_language);
278 if (!$translation instanceof ilAdvancedMDRecordTranslation) {
279 return false;
280 }
281 $translation->setTitle($title);
282 $translation->setDescription($description);
283 $translation->update();
284 }
Class ilAdvancedMDRecordTranslation.

References getTranslation().

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilAdvancedMDFieldTranslations::$db
private

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

◆ $default_language

ilAdvancedMDFieldTranslations::$default_language = ''
private

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

Referenced by getDefaultLanguage().

◆ $definitions

ilAdvancedMDFieldTranslations::$definitions
private

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

◆ $instances

ilAdvancedMDFieldTranslations::$instances = null
staticprivate

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

◆ $lng

ilAdvancedMDFieldTranslations::$lng
private

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

◆ $record

ilAdvancedMDFieldTranslations::$record
private

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

◆ $record_id

ilAdvancedMDFieldTranslations::$record_id
private

◆ $record_translations

ilAdvancedMDFieldTranslations::$record_translations = []
private

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

◆ $translations

ilAdvancedMDFieldTranslations::$translations = []
private

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


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