ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilBiblTranslationFactory Class Reference

Class ilBiblTranslationFactory. More...

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

Public Member Functions

 __construct (protected \ilBiblFieldFactoryInterface $field_factory)
 ilBiblTranslationFactory constructor. More...
 
 translate (ilBiblFieldInterface $field)
 Translates a field in the current users language in tho folowing order: More...
 
 translateAttribute (ilBiblAttributeInterface $attribute)
 
 translateAttributeString (int $type_id, ilBiblAttributeInterface $attribute)
 
 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, string $language_key)
 @inheritDoc More...
 
 getAllTranslationsForField (ilBiblFieldInterface $field)
 @inheritDoc More...
 
 getAllTranslationsForFieldAsArray (ilBiblFieldInterface $field)
 @inheritDoc More...
 
 findById (int $id)
 @inheritDoc More...
 
 deleteById (int $id)
 @inheritDoc More...
 
 translate (ilBiblFieldInterface $field)
 Translates a field in the current users language in tho folowing order: More...
 
 translateAttribute (ilBiblAttributeInterface $attribute)
 
 translateAttributeString (int $type_id, ilBiblAttributeInterface $attribute)
 
 getFieldFactory ()
 
 translationExistsForFieldAndUsersLanguage (ilBiblFieldInterface $field)
 
 translationExistsForFieldAndSystemsLanguage (ilBiblFieldInterface $field)
 
 translationExistsForField (ilBiblFieldInterface $field)
 
 getInstanceForFieldAndUsersLanguage (ilBiblFieldInterface $field)
 
 getInstanceForFieldAndSystemsLanguage (ilBiblFieldInterface $field)
 
 findArCreateInstanceForFieldAndlanguage (ilBiblFieldInterface $field, string $language_key)
 
 getAllTranslationsForField (ilBiblFieldInterface $field)
 
 getAllTranslationsForFieldAsArray (ilBiblFieldInterface $field)
 
 findById (int $id)
 
 deleteById (int $id)
 

Protected Attributes

Container $dic
 

Private Member Functions

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

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBiblTranslationFactory::__construct ( protected \ilBiblFieldFactoryInterface  $field_factory)

ilBiblTranslationFactory constructor.

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

33 {
34 global $DIC;
35 $this->dic = $DIC;
36 }
global $DIC
Definition: shib_login.php:26

References $DIC.

Member Function Documentation

◆ deleteById()

ilBiblTranslationFactory::deleteById ( int  $id)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

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

192 : bool
193 {
194 self::findById($id)->delete();
195
196 return true;
197 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

◆ findArCreateInstanceForFieldAndlanguage()

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

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

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

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

References ilBiblFieldInterface\getId().

+ Here is the call graph for this function:

◆ findById()

ilBiblTranslationFactory::findById ( int  $id)

@inheritDoc

@noinspection PhpIncompatibleReturnTypeInspection

Implements ilBiblTranslationFactoryInterface.

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

184 {
187 }
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.

References $id, and ActiveRecord\findOrFail().

+ Here is the call graph for this function:

◆ getAllTranslationsForField()

ilBiblTranslationFactory::getAllTranslationsForField ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

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

162 : array
163 {
164 return $this->getCollectionOfTranslationsForField($field)->get();
165 }

◆ getAllTranslationsForFieldAsArray()

ilBiblTranslationFactory::getAllTranslationsForFieldAsArray ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

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

170 : array
171 {
172 return $this->getCollectionOfTranslationsForField($field)->getArray();
173 }

◆ getCollectionOfTranslationsForField()

ilBiblTranslationFactory::getCollectionOfTranslationsForField ( ilBiblFieldInterface  $field)
private

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

176 {
177 return ilBiblTranslation::where(['field_id' => $field->getId()])->orderBy('language_key');
178 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static where($where, $operator=null)

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

Referenced by getInstanceForFieldAndSystemsLanguage(), getInstanceForFieldAndUsersLanguage(), and translationExistsForField().

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

◆ getFieldFactory()

ilBiblTranslationFactory::getFieldFactory ( )

Implements ilBiblTranslationFactoryInterface.

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

72 {
73 return $this->field_factory;
74 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Referenced by translateAttributeString(), and translateInCore().

+ Here is the caller graph for this function:

◆ getInstanceForFieldAndSystemsLanguage()

ilBiblTranslationFactory::getInstanceForFieldAndSystemsLanguage ( ilBiblFieldInterface  $field)

@inheritDoc

@noinspection PhpIncompatibleReturnTypeInspection

Implements ilBiblTranslationFactoryInterface.

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

128 {
129 global $DIC;
130 $lng = $DIC->language()->getDefaultLanguage();
131
133 return $this->getCollectionOfTranslationsForField($field)
134 ->where(["language_key" => $lng,])
135 ->first();
136 }
global $lng
Definition: privfeed.php:31

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

@noinspection PhpIncompatibleReturnTypeInspection

Implements ilBiblTranslationFactoryInterface.

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

115 {
116 global $DIC;
117
119 return $this->getCollectionOfTranslationsForField($field)
120 ->where(["language_key" => $DIC->user()->getCurrentLanguage(),])
121 ->first();
122 }

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)

Translates a field in the current users language in tho folowing order:

  • if standard-field, user ILIAS ilLanguage
  • if a explicit translation in the users language is available, use this
  • if a translation is only for the systems language, us this
  • return string like "bib_year"

Implements ilBiblTranslationFactoryInterface.

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

38 : 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 }
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)

Implements ilBiblTranslationFactoryInterface.

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

55 : string
56 {
57 $field = $this->field_factory->findOrCreateFieldOfAttribute($attribute);
58
59 return $this->translate($field);
60 }
translate(ilBiblFieldInterface $field)
Translates a field in the current users language in tho folowing order:

References translate().

+ Here is the call graph for this function:

◆ translateAttributeString()

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

Implements ilBiblTranslationFactoryInterface.

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

63 : string
64 {
65 $field = $this->getFieldFactory()
66 ->findOrCreateFieldByTypeAndIdentifier($type_id, $attribute->getIdentifier());
67
68 return $this->translate($field);
69 }

References getFieldFactory(), and translate().

+ Here is the call graph for this function:

◆ translateInCore()

ilBiblTranslationFactory::translateInCore ( ilBiblFieldInterface  $field)
private

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

76 : 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 }

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 106 of file class.ilBiblTranslationFactory.php.

106 : bool
107 {
108 return $this->getCollectionOfTranslationsForField($field)->hasSets();
109 }

References getCollectionOfTranslationsForField().

+ Here is the call graph for this function:

◆ translationExistsForFieldAndSystemsLanguage()

ilBiblTranslationFactory::translationExistsForFieldAndSystemsLanguage ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblTranslationFactoryInterface.

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

98 : bool
99 {
100 return !is_null($this->getInstanceForFieldAndSystemsLanguage($field));
101 }

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 90 of file class.ilBiblTranslationFactory.php.

90 : bool
91 {
92 return !is_null($this->getInstanceForFieldAndUsersLanguage($field));
93 }

References getInstanceForFieldAndUsersLanguage().

Referenced by translate().

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

Field Documentation

◆ $dic

Container ilBiblTranslationFactory::$dic
protected

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


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