ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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)
 
 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.

References $DIC.

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

Member Function Documentation

◆ deleteById()

ilBiblTranslationFactory::deleteById ( int  $id)

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

◆ findArCreateInstanceForFieldAndlanguage()

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

Implements ilBiblTranslationFactoryInterface.

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

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

145  $inst = $this->getCollectionOfTranslationsForField($field)
146  ->where(["language_key" => $language_key,])
147  ->get();
148 
149  if ($inst === []) {
150  $inst = new ilBiblTranslation();
151  $inst->setFieldId($field->getId());
152  $inst->setLanguageKey($language_key);
153  $inst->create();
154  }
155 
156  return $inst;
157  }
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...
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ Here is the call graph for this function:

◆ findById()

ilBiblTranslationFactory::findById ( int  $id)

PhpIncompatibleReturnTypeInspection

Implements ilBiblTranslationFactoryInterface.

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

References ActiveRecord\findOrFail().

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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ getAllTranslationsForField()

ilBiblTranslationFactory::getAllTranslationsForField ( ilBiblFieldInterface  $field)

Implements ilBiblTranslationFactoryInterface.

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

References getCollectionOfTranslationsForField().

162  : array
163  {
164  return $this->getCollectionOfTranslationsForField($field)->get();
165  }
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ Here is the call graph for this function:

◆ getAllTranslationsForFieldAsArray()

ilBiblTranslationFactory::getAllTranslationsForFieldAsArray ( ilBiblFieldInterface  $field)

Implements ilBiblTranslationFactoryInterface.

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

References getCollectionOfTranslationsForField().

170  : array
171  {
172  return $this->getCollectionOfTranslationsForField($field)->getArray();
173  }
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ Here is the call graph for this function:

◆ getCollectionOfTranslationsForField()

ilBiblTranslationFactory::getCollectionOfTranslationsForField ( ilBiblFieldInterface  $field)
private

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

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

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

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)
+ 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.

Referenced by translateAttributeString(), and translateInCore().

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...
+ Here is the caller graph for this function:

◆ getInstanceForFieldAndSystemsLanguage()

ilBiblTranslationFactory::getInstanceForFieldAndSystemsLanguage ( ilBiblFieldInterface  $field)

PhpIncompatibleReturnTypeInspection

Implements ilBiblTranslationFactoryInterface.

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

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

Referenced by translate(), and translationExistsForFieldAndSystemsLanguage().

128  {
129  global $DIC;
130  $lng = $DIC->language()->getDefaultLanguage();
131 
133  return $this->getCollectionOfTranslationsForField($field)
134  ->where(["language_key" => $lng,])
135  ->first();
136  }
global $DIC
Definition: shib_login.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstanceForFieldAndUsersLanguage()

ilBiblTranslationFactory::getInstanceForFieldAndUsersLanguage ( ilBiblFieldInterface  $field)

PhpIncompatibleReturnTypeInspection

Implements ilBiblTranslationFactoryInterface.

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

References $DIC, and getCollectionOfTranslationsForField().

Referenced by translate(), and translationExistsForFieldAndUsersLanguage().

115  {
116  global $DIC;
117 
119  return $this->getCollectionOfTranslationsForField($field)
120  ->where(["language_key" => $DIC->user()->getCurrentLanguage(),])
121  ->first();
122  }
global $DIC
Definition: shib_login.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ 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.

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

Referenced by translateAttribute(), and translateAttributeString().

38  : string
39  {
40  if ($this->translationExistsForFieldAndUsersLanguage($field)) {
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  }
translationExistsForFieldAndUsersLanguage(ilBiblFieldInterface $field)
translationExistsForFieldAndSystemsLanguage(ilBiblFieldInterface $field)
getInstanceForFieldAndUsersLanguage(ilBiblFieldInterface $field)
getInstanceForFieldAndSystemsLanguage(ilBiblFieldInterface $field)
translateInCore(ilBiblFieldInterface $field)
+ 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.

References translate().

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:
+ 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.

References getFieldFactory(), and translate().

63  : string
64  {
65  $field = $this->getFieldFactory()
66  ->findOrCreateFieldByTypeAndIdentifier($type_id, $attribute->getIdentifier());
67 
68  return $this->translate($field);
69  }
translate(ilBiblFieldInterface $field)
Translates a field in the current users language in tho folowing order:
+ Here is the call graph for this function:

◆ translateInCore()

ilBiblTranslationFactory::translateInCore ( ilBiblFieldInterface  $field)
private

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

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

Referenced by translate().

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  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ translationExistsForField()

ilBiblTranslationFactory::translationExistsForField ( ilBiblFieldInterface  $field)

Implements ilBiblTranslationFactoryInterface.

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

References getCollectionOfTranslationsForField().

106  : bool
107  {
108  return $this->getCollectionOfTranslationsForField($field)->hasSets();
109  }
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ Here is the call graph for this function:

◆ translationExistsForFieldAndSystemsLanguage()

ilBiblTranslationFactory::translationExistsForFieldAndSystemsLanguage ( ilBiblFieldInterface  $field)

Implements ilBiblTranslationFactoryInterface.

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

References getInstanceForFieldAndSystemsLanguage().

Referenced by translate().

98  : bool
99  {
100  return !is_null($this->getInstanceForFieldAndSystemsLanguage($field));
101  }
getInstanceForFieldAndSystemsLanguage(ilBiblFieldInterface $field)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ translationExistsForFieldAndUsersLanguage()

ilBiblTranslationFactory::translationExistsForFieldAndUsersLanguage ( ilBiblFieldInterface  $field)

Implements ilBiblTranslationFactoryInterface.

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

References getInstanceForFieldAndUsersLanguage().

Referenced by translate().

90  : bool
91  {
92  return !is_null($this->getInstanceForFieldAndUsersLanguage($field));
93  }
getInstanceForFieldAndUsersLanguage(ilBiblFieldInterface $field)
+ 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: