ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilBiblTranslationFactory Class Reference

Class ilBiblTranslationFactory. More...

+ Inheritance diagram for ilBiblTranslationFactory:
+ Collaboration diagram for ilBiblTranslationFactory:

Public Member Functions

 __construct (ilBiblFieldFactoryInterface $field_factory)
 ilBiblTranslationFactory constructor. More...
 
 translate (ilBiblFieldInterface $field)
 
 translateAttribute (ilBiblAttributeInterface $attribute)
 @inheritDoc More...
 
 translateAttributeString ($type_id, ilBiblAttributeInterface $attribute)
 @inheritDoc More...
 
 getFieldFactory ()
 
 translationExistsForFieldAndUsersLanguage (ilBiblFieldInterface $field)
 @inheritDoc More...
 
 translationExistsForFieldAndSystemsLanguage (ilBiblFieldInterface $field)
 @inheritDoc More...
 
 translationExistsForField (ilBiblFieldInterface $field)
 @inheritDoc More...
 
 getInstanceForFieldAndUsersLanguage (ilBiblFieldInterface $field)
 @inheritDoc More...
 
 getInstanceForFieldAndSystemsLanguage (ilBiblFieldInterface $field)
 @inheritDoc More...
 
 findArCreateInstanceForFieldAndlanguage (ilBiblFieldInterface $field, $language_key)
 @inheritDoc More...
 
 getAllTranslationsForField (ilBiblFieldInterface $field)
 @inheritDoc More...
 
 getAllTranslationsForFieldAsArray (ilBiblFieldInterface $field)
 @inheritDoc More...
 
 findById ($id)
 @inheritDoc More...
 
 deleteById ($id)
 @inheritDoc More...
 
 translate (ilBiblFieldInterface $field)
 Translates a field in the current users language in tho folowing order: More...
 
 translateAttribute (ilBiblAttributeInterface $attribute)
 
 translateAttributeString ($type_id, ilBiblAttributeInterface $attribute)
 
 getFieldFactory ()
 
 translationExistsForFieldAndUsersLanguage (ilBiblFieldInterface $field)
 
 translationExistsForFieldAndSystemsLanguage (ilBiblFieldInterface $field)
 
 translationExistsForField (ilBiblFieldInterface $field)
 
 getInstanceForFieldAndUsersLanguage (ilBiblFieldInterface $field)
 
 getInstanceForFieldAndSystemsLanguage (ilBiblFieldInterface $field)
 
 findArCreateInstanceForFieldAndlanguage (ilBiblFieldInterface $field, $language_key)
 
 getAllTranslationsForField (ilBiblFieldInterface $field)
 
 getAllTranslationsForFieldAsArray (ilBiblFieldInterface $field)
 
 findById ($id)
 
 deleteById ($id)
 

Protected Attributes

 $dic
 
 $field_factory
 

Private Member Functions

 translateInCore (ilBiblFieldInterface $field)
 
 getCollectionOfTranslationsForField (ilBiblFieldInterface $field)
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBiblTranslationFactory::__construct ( ilBiblFieldFactoryInterface  $field_factory)

ilBiblTranslationFactory constructor.

Parameters
\ilBiblFieldFactoryInterface$field_factory

Definition at line 26 of file class.ilBiblTranslationFactory.php.

27 {
28 global $DIC;
29 $this->dic = $DIC;
30 $this->field_factory = $field_factory;
31 }
global $DIC
Definition: saml.php:7

References $DIC, and $field_factory.

Member Function Documentation

◆ deleteById()

ilBiblTranslationFactory::deleteById (   $id)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

Definition at line 221 of file class.ilBiblTranslationFactory.php.

222 {
223 self::findById($id)->delete();
224
225 return true;
226 }
if(!array_key_exists('StateId', $_REQUEST)) $id

References $id, and findById().

+ Here is the call graph for this function:

◆ findArCreateInstanceForFieldAndlanguage()

ilBiblTranslationFactory::findArCreateInstanceForFieldAndlanguage ( ilBiblFieldInterface  $field,
  $language_key 
)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

Definition at line 163 of file class.ilBiblTranslationFactory.php.

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 }
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
Class ilBiblTranslation.

References getCollectionOfTranslationsForField(), and ilBiblFieldInterface\getId().

+ Here is the call graph for this function:

◆ findById()

ilBiblTranslationFactory::findById (   $id)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

Definition at line 212 of file class.ilBiblTranslationFactory.php.

213 {
215 }
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.

References $id, and ActiveRecord\findOrFail().

Referenced by deleteById().

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

◆ getAllTranslationsForField()

ilBiblTranslationFactory::getAllTranslationsForField ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

Definition at line 183 of file class.ilBiblTranslationFactory.php.

184 {
185 return $this->getCollectionOfTranslationsForField($field)->get();
186 }

References getCollectionOfTranslationsForField().

+ Here is the call graph for this function:

◆ getAllTranslationsForFieldAsArray()

ilBiblTranslationFactory::getAllTranslationsForFieldAsArray ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

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

193 {
194 return $this->getCollectionOfTranslationsForField($field)->getArray();
195 }

References getCollectionOfTranslationsForField().

+ Here is the call graph for this function:

◆ getCollectionOfTranslationsForField()

ilBiblTranslationFactory::getCollectionOfTranslationsForField ( ilBiblFieldInterface  $field)
private
Parameters
\ilBiblFieldInterface$field
Returns
\ActiveRecordList

Definition at line 203 of file class.ilBiblTranslationFactory.php.

204 {
205 return ilBiblTranslation::where([ 'field_id' => $field->getId() ])->orderBy('language_key');
206 }
static where($where, $operator=null)

References ilBiblFieldInterface\getId(), and ActiveRecord\where().

Referenced by findArCreateInstanceForFieldAndlanguage(), getAllTranslationsForField(), getAllTranslationsForFieldAsArray(), getInstanceForFieldAndSystemsLanguage(), getInstanceForFieldAndUsersLanguage(), and translationExistsForField().

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

◆ getFieldFactory()

ilBiblTranslationFactory::getFieldFactory ( )
Returns
\ilBiblFieldFactoryInterface

Implements ilBiblTranslationFactoryInterface.

Definition at line 83 of file class.ilBiblTranslationFactory.php.

84 {
86 }

References $field_factory.

Referenced by translateAttributeString(), and translateInCore().

+ Here is the caller graph for this function:

◆ getInstanceForFieldAndSystemsLanguage()

ilBiblTranslationFactory::getInstanceForFieldAndSystemsLanguage ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

Definition at line 149 of file class.ilBiblTranslationFactory.php.

150 {
151 global $DIC;
152 $lng = $DIC->language()->getDefaultLanguage();
153
154 return $this->getCollectionOfTranslationsForField($field)
155 ->where([ "language_key" => $lng, ])
156 ->first();
157 }
$lng

References $DIC, $lng, and getCollectionOfTranslationsForField().

Referenced by translate(), and translationExistsForFieldAndSystemsLanguage().

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

◆ getInstanceForFieldAndUsersLanguage()

ilBiblTranslationFactory::getInstanceForFieldAndUsersLanguage ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

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

137 {
138 global $DIC;
139
140 return $this->getCollectionOfTranslationsForField($field)
141 ->where([ "language_key" => $DIC->user()->getCurrentLanguage(), ])
142 ->first();
143 }

References $DIC, and getCollectionOfTranslationsForField().

Referenced by translate(), and translationExistsForFieldAndUsersLanguage().

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

◆ translate()

ilBiblTranslationFactory::translate ( ilBiblFieldInterface  $field)
Parameters
\ilBiblFieldInterface$field
Returns
string

Implements ilBiblTranslationFactoryInterface.

Definition at line 39 of file class.ilBiblTranslationFactory.php.

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 }
translationExistsForFieldAndSystemsLanguage(ilBiblFieldInterface $field)
@inheritDoc
translateInCore(ilBiblFieldInterface $field)
getInstanceForFieldAndUsersLanguage(ilBiblFieldInterface $field)
@inheritDoc
translationExistsForFieldAndUsersLanguage(ilBiblFieldInterface $field)
@inheritDoc
getInstanceForFieldAndSystemsLanguage(ilBiblFieldInterface $field)
@inheritDoc

References ilBiblFieldInterface\getIdentifier(), getInstanceForFieldAndSystemsLanguage(), getInstanceForFieldAndUsersLanguage(), translateInCore(), translationExistsForFieldAndSystemsLanguage(), and translationExistsForFieldAndUsersLanguage().

Referenced by translateAttribute(), and translateAttributeString().

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

◆ translateAttribute()

ilBiblTranslationFactory::translateAttribute ( ilBiblAttributeInterface  $attribute)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

Definition at line 60 of file class.ilBiblTranslationFactory.php.

61 {
62 $field = $this->field_factory->findOrCreateFieldOfAttribute($attribute);
63
64 return $this->translate($field);
65 }
translate(ilBiblFieldInterface $field)

References translate().

+ Here is the call graph for this function:

◆ translateAttributeString()

ilBiblTranslationFactory::translateAttributeString (   $type_id,
ilBiblAttributeInterface  $attribute 
)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

Definition at line 71 of file class.ilBiblTranslationFactory.php.

72 {
73 $field = $this->getFieldFactory()
74 ->findOrCreateFieldByTypeAndIdentifier($type_id, $attribute->getIdentifier());
75
76 return $this->translate($field);
77 }

References getFieldFactory(), and translate().

+ Here is the call graph for this function:

◆ translateInCore()

ilBiblTranslationFactory::translateInCore ( ilBiblFieldInterface  $field)
private
Parameters
\ilBiblFieldInterface$field
Returns
string

Definition at line 94 of file class.ilBiblTranslationFactory.php.

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 }

References getFieldFactory(), and ilBiblFieldInterface\getIdentifier().

Referenced by translate().

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

◆ translationExistsForField()

ilBiblTranslationFactory::translationExistsForField ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

Definition at line 127 of file class.ilBiblTranslationFactory.php.

128 {
129 return $this->getCollectionOfTranslationsForField($field)->hasSets();
130 }

References getCollectionOfTranslationsForField().

+ Here is the call graph for this function:

◆ translationExistsForFieldAndSystemsLanguage()

ilBiblTranslationFactory::translationExistsForFieldAndSystemsLanguage ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

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

119 {
120 return !is_null($this->getInstanceForFieldAndSystemsLanguage($field));
121 }

References getInstanceForFieldAndSystemsLanguage().

Referenced by translate().

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

◆ translationExistsForFieldAndUsersLanguage()

ilBiblTranslationFactory::translationExistsForFieldAndUsersLanguage ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

Definition at line 109 of file class.ilBiblTranslationFactory.php.

110 {
111 return !is_null($this->getInstanceForFieldAndUsersLanguage($field));
112 }

References getInstanceForFieldAndUsersLanguage().

Referenced by translate().

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

Field Documentation

◆ $dic

ilBiblTranslationFactory::$dic
protected

Definition at line 14 of file class.ilBiblTranslationFactory.php.

◆ $field_factory

ilBiblTranslationFactory::$field_factory
protected

Definition at line 18 of file class.ilBiblTranslationFactory.php.

Referenced by __construct(), and getFieldFactory().


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