ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBiblTranslationFactory.php
Go to the documentation of this file.
1<?php
2
20
26{
27 protected Container $dic;
28
32 public function __construct(protected \ilBiblFieldFactoryInterface $field_factory)
33 {
34 global $DIC;
35 $this->dic = $DIC;
36 }
37
38 public function translate(ilBiblFieldInterface $field): string
39 {
41 return $this->getInstanceForFieldAndUsersLanguage($field)->getTranslation();
42 }
44 return $this->getInstanceForFieldAndSystemsLanguage($field)->getTranslation();
45 }
46
47 $core_translation = $this->translateInCore($field);
48 if (!str_starts_with($core_translation, "-")) {
49 return $core_translation;
50 }
51
52 return $field->getIdentifier();
53 }
54
55 public function translateAttribute(ilBiblAttributeInterface $attribute): string
56 {
57 $field = $this->field_factory->findOrCreateFieldOfAttribute($attribute);
58
59 return $this->translate($field);
60 }
61
62
63 public function translateAttributeString(int $type_id, ilBiblAttributeInterface $attribute): string
64 {
65 $field = $this->getFieldFactory()
66 ->findOrCreateFieldByTypeAndIdentifier($type_id, $attribute->getIdentifier());
67
68 return $this->translate($field);
69 }
70
72 {
73 return $this->field_factory;
74 }
75
76 private function translateInCore(ilBiblFieldInterface $field): string
77 {
78 $prefix = $this->getFieldFactory()->getType()->getStringRepresentation();
79 $middle = "default";
80 $identifier = $field->getIdentifier();
81
82 $topic = implode("_", [$prefix, $middle, $identifier]);
83
84 return $this->dic->language()->txt(strtolower($topic));
85 }
86
91 {
92 return !is_null($this->getInstanceForFieldAndUsersLanguage($field));
93 }
94
99 {
100 return !is_null($this->getInstanceForFieldAndSystemsLanguage($field));
101 }
102
107 {
108 return $this->getCollectionOfTranslationsForField($field)->hasSets();
109 }
110
115 {
116 global $DIC;
117
119 return $this->getCollectionOfTranslationsForField($field)
120 ->where(["language_key" => $DIC->user()->getCurrentLanguage(),])
121 ->first();
122 }
123
128 {
129 global $DIC;
130 $lng = $DIC->language()->getDefaultLanguage();
131
133 return $this->getCollectionOfTranslationsForField($field)
134 ->where(["language_key" => $lng,])
135 ->first();
136 }
137
143 string $language_key
145 $inst = $this->getCollectionOfTranslationsForField($field)
146 ->where(["language_key" => $language_key,])
147 ->first();
148
149 if ($inst === null) {
150 $inst = new ilBiblTranslation();
151 $inst->setFieldId($field->getId());
152 $inst->setLanguageKey($language_key);
153 $inst->create();
154 }
155
156 return $inst;
157 }
158
163 {
164 return $this->getCollectionOfTranslationsForField($field)->get();
165 }
166
171 {
172 return $this->getCollectionOfTranslationsForField($field)->getArray();
173 }
174
176 {
177 return ilBiblTranslation::where(['field_id' => $field->getId()])->orderBy('language_key');
178 }
179
184 {
187 }
188
192 public function deleteById(int $id): bool
193 {
194 self::findById($id)->delete();
195
196 return true;
197 }
198}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static where($where, $operator=null)
static findOrFail($primary_key, array $add_constructor_args=[])
Tries to find the object and throws an Exception if object is not found, instead of returning null.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Class ilBiblTranslationFactory.
__construct(protected \ilBiblFieldFactoryInterface $field_factory)
ilBiblTranslationFactory constructor.
translateAttribute(ilBiblAttributeInterface $attribute)
translationExistsForFieldAndSystemsLanguage(ilBiblFieldInterface $field)
@inheritDoc
translateInCore(ilBiblFieldInterface $field)
findArCreateInstanceForFieldAndlanguage(ilBiblFieldInterface $field, string $language_key)
@inheritDoc
getAllTranslationsForField(ilBiblFieldInterface $field)
@inheritDoc
getInstanceForFieldAndUsersLanguage(ilBiblFieldInterface $field)
@inheritDoc
translationExistsForFieldAndUsersLanguage(ilBiblFieldInterface $field)
@inheritDoc
getInstanceForFieldAndSystemsLanguage(ilBiblFieldInterface $field)
@inheritDoc
translateAttributeString(int $type_id, ilBiblAttributeInterface $attribute)
translate(ilBiblFieldInterface $field)
Translates a field in the current users language in tho folowing order:
translationExistsForField(ilBiblFieldInterface $field)
@inheritDoc
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
getAllTranslationsForFieldAsArray(ilBiblFieldInterface $field)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26