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

References $DIC, and $field_factory.

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

Member Function Documentation

◆ deleteById()

ilBiblTranslationFactory::deleteById (   $id)

Implements ilBiblTranslationFactoryInterface.

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

References $id.

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

◆ findArCreateInstanceForFieldAndlanguage()

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

Implements ilBiblTranslationFactoryInterface.

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

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

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  }
Class ilBiblTranslation.
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ Here is the call graph for this function:

◆ findById()

ilBiblTranslationFactory::findById (   $id)

Implements ilBiblTranslationFactoryInterface.

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

References $id, and ActiveRecord\findOrFail().

213  {
215  }
if(!array_key_exists('StateId', $_REQUEST)) $id
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...
+ Here is the call graph for this function:

◆ getAllTranslationsForField()

ilBiblTranslationFactory::getAllTranslationsForField ( ilBiblFieldInterface  $field)

Implements ilBiblTranslationFactoryInterface.

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

References getCollectionOfTranslationsForField().

184  {
185  return $this->getCollectionOfTranslationsForField($field)->get();
186  }
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ Here is the call graph for this function:

◆ getAllTranslationsForFieldAsArray()

ilBiblTranslationFactory::getAllTranslationsForFieldAsArray ( ilBiblFieldInterface  $field)

Implements ilBiblTranslationFactoryInterface.

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

References getCollectionOfTranslationsForField().

193  {
194  return $this->getCollectionOfTranslationsForField($field)->getArray();
195  }
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ Here is the call graph for this function:

◆ getCollectionOfTranslationsForField()

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

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

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

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

204  {
205  return ilBiblTranslation::where([ 'field_id' => $field->getId() ])->orderBy('language_key');
206  }
static where($where, $operator=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFieldFactory()

ilBiblTranslationFactory::getFieldFactory ( )
Returns

Implements ilBiblTranslationFactoryInterface.

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

References $field_factory.

Referenced by translateAttributeString(), and translateInCore().

+ Here is the caller graph for this function:

◆ getInstanceForFieldAndSystemsLanguage()

ilBiblTranslationFactory::getInstanceForFieldAndSystemsLanguage ( ilBiblFieldInterface  $field)

Implements ilBiblTranslationFactoryInterface.

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

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

Referenced by translate(), and translationExistsForFieldAndSystemsLanguage().

150  {
151  global $DIC;
152  $lng = $DIC->language()->getDefaultLanguage();
153 
154  return $this->getCollectionOfTranslationsForField($field)
155  ->where([ "language_key" => $lng, ])
156  ->first();
157  }
global $DIC
Definition: saml.php:7
$lng
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstanceForFieldAndUsersLanguage()

ilBiblTranslationFactory::getInstanceForFieldAndUsersLanguage ( ilBiblFieldInterface  $field)

Implements ilBiblTranslationFactoryInterface.

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

References $DIC, and getCollectionOfTranslationsForField().

Referenced by translate(), and translationExistsForFieldAndUsersLanguage().

137  {
138  global $DIC;
139 
140  return $this->getCollectionOfTranslationsForField($field)
141  ->where([ "language_key" => $DIC->user()->getCurrentLanguage(), ])
142  ->first();
143  }
global $DIC
Definition: saml.php:7
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ 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.

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

Referenced by translateAttribute(), and translateAttributeString().

40  {
41  if ($this->translationExistsForFieldAndUsersLanguage($field)) {
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  }
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 60 of file class.ilBiblTranslationFactory.php.

References translate().

61  {
62  $field = $this->field_factory->findOrCreateFieldOfAttribute($attribute);
63 
64  return $this->translate($field);
65  }
translate(ilBiblFieldInterface $field)
+ Here is the call graph for this function:

◆ translateAttributeString()

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

Implements ilBiblTranslationFactoryInterface.

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

References getFieldFactory(), and translate().

72  {
73  $field = $this->getFieldFactory()
74  ->findOrCreateFieldByTypeAndIdentifier($type_id, $attribute->getIdentifier());
75 
76  return $this->translate($field);
77  }
translate(ilBiblFieldInterface $field)
+ 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.

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

Referenced by translate().

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  }
+ 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 127 of file class.ilBiblTranslationFactory.php.

References getCollectionOfTranslationsForField().

128  {
129  return $this->getCollectionOfTranslationsForField($field)->hasSets();
130  }
getCollectionOfTranslationsForField(ilBiblFieldInterface $field)
+ Here is the call graph for this function:

◆ translationExistsForFieldAndSystemsLanguage()

ilBiblTranslationFactory::translationExistsForFieldAndSystemsLanguage ( ilBiblFieldInterface  $field)

Implements ilBiblTranslationFactoryInterface.

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

References getInstanceForFieldAndSystemsLanguage().

Referenced by translate().

119  {
120  return !is_null($this->getInstanceForFieldAndSystemsLanguage($field));
121  }
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 109 of file class.ilBiblTranslationFactory.php.

References getInstanceForFieldAndUsersLanguage().

Referenced by translate().

110  {
111  return !is_null($this->getInstanceForFieldAndUsersLanguage($field));
112  }
getInstanceForFieldAndUsersLanguage(ilBiblFieldInterface $field)
+ 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: