ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBiblTranslationFactory.php
Go to the documentation of this file.
1<?php
2
9{
10
14 protected $dic;
18 protected $field_factory;
19
20
27 {
28 global $DIC;
29 $this->dic = $DIC;
30 $this->field_factory = $field_factory;
31 }
32
33
39 public function translate(ilBiblFieldInterface $field)
40 {
42 return $this->getInstanceForFieldAndUsersLanguage($field)->getTranslation();
43 }
45 return $this->getInstanceForFieldAndSystemsLanguage($field)->getTranslation();
46 }
47
48 $core_translation = $this->translateInCore($field);
49 if (strpos($core_translation, "-") !== 0) {
50 return $core_translation;
51 }
52
53 return $field->getIdentifier();
54 }
55
56
60 public function translateAttribute(ilBiblAttributeInterface $attribute)
61 {
62 $field = $this->field_factory->findOrCreateFieldOfAttribute($attribute);
63
64 return $this->translate($field);
65 }
66
67
71 public function translateAttributeString($type_id, ilBiblAttributeInterface $attribute)
72 {
73 $field = $this->getFieldFactory()
74 ->findOrCreateFieldByTypeAndIdentifier($type_id, $attribute->getIdentifier());
75
76 return $this->translate($field);
77 }
78
79
83 public function getFieldFactory()
84 {
86 }
87
88
94 private function translateInCore(ilBiblFieldInterface $field)
95 {
96 $prefix = $this->getFieldFactory()->getType()->getStringRepresentation();
97 $middle = "default";
98 $identifier = $field->getIdentifier();
99
100 $topic = implode("_", [ $prefix, $middle, $identifier ]);
101
102 return $this->dic->language()->txt(strtolower($topic));
103 }
104
105
110 {
111 return !is_null($this->getInstanceForFieldAndUsersLanguage($field));
112 }
113
114
119 {
120 return !is_null($this->getInstanceForFieldAndSystemsLanguage($field));
121 }
122
123
128 {
129 return $this->getCollectionOfTranslationsForField($field)->hasSets();
130 }
131
132
137 {
138 global $DIC;
139
140 return $this->getCollectionOfTranslationsForField($field)
141 ->where([ "language_key" => $DIC->user()->getCurrentLanguage(), ])
142 ->first();
143 }
144
145
150 {
151 global $DIC;
152 $lng = $DIC->language()->getDefaultLanguage();
153
154 return $this->getCollectionOfTranslationsForField($field)
155 ->where([ "language_key" => $lng, ])
156 ->first();
157 }
158
159
164 {
165 $inst = $this->getCollectionOfTranslationsForField($field)
166 ->where([ "language_key" => $language_key, ])
167 ->get();
168
169 if (!$inst) {
170 $inst = new ilBiblTranslation();
171 $inst->setFieldId($field->getId());
172 $inst->setLanguageKey($language_key);
173 $inst->create();
174 }
175
176 return $inst;
177 }
178
179
184 {
185 return $this->getCollectionOfTranslationsForField($field)->get();
186 }
187
188
193 {
194 return $this->getCollectionOfTranslationsForField($field)->getArray();
195 }
196
197
204 {
205 return ilBiblTranslation::where([ 'field_id' => $field->getId() ])->orderBy('language_key');
206 }
207
208
212 public function findById($id)
213 {
215 }
216
217
221 public function deleteById($id)
222 {
223 self::findById($id)->delete();
224
225 return true;
226 }
227}
static where($where, $operator=null)
static findOrFail($primary_key, array $add_constructor_args=array())
Tries to find the object and throws an Exception if object is not found, instead of returning null.
An exception for terminatinating execution or to throw for unit testing.
Class ilBiblTranslationFactory.
translateAttribute(ilBiblAttributeInterface $attribute)
@inheritDoc
translationExistsForFieldAndSystemsLanguage(ilBiblFieldInterface $field)
@inheritDoc
translateInCore(ilBiblFieldInterface $field)
translateAttributeString($type_id, ilBiblAttributeInterface $attribute)
@inheritDoc
__construct(ilBiblFieldFactoryInterface $field_factory)
ilBiblTranslationFactory constructor.
getAllTranslationsForField(ilBiblFieldInterface $field)
@inheritDoc
findArCreateInstanceForFieldAndlanguage(ilBiblFieldInterface $field, $language_key)
@inheritDoc
getInstanceForFieldAndUsersLanguage(ilBiblFieldInterface $field)
@inheritDoc
translationExistsForFieldAndUsersLanguage(ilBiblFieldInterface $field)
@inheritDoc
getInstanceForFieldAndSystemsLanguage(ilBiblFieldInterface $field)
@inheritDoc
translate(ilBiblFieldInterface $field)
translationExistsForField(ilBiblFieldInterface $field)
@inheritDoc
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
getAllTranslationsForFieldAsArray(ilBiblFieldInterface $field)
@inheritDoc
Class ilBiblTranslation.
if(!array_key_exists('StateId', $_REQUEST)) $id
Interface ilBiblAttributeInterface.
Interface ilBiblFieldFactoryInterface.
Interface ilBiblEntryInterface.
global $DIC
Definition: saml.php:7
$lng