ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilBiblAttributeFactory Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilBiblAttributeFactory:
+ Collaboration diagram for ilBiblAttributeFactory:

Public Member Functions

 __construct (protected \ilBiblFieldFactoryInterface $field_factory)
 
 getPossibleValuesForFieldAndObject (ilBiblFieldInterface $field, int $object_id)
 
 getAttributesForEntry (ilBiblEntryInterface $entry)
 
 sortAttributesArray (array $attributes)
 
 sortAttributes (array $attributes)
 
 createAttribute (string $name, string $value, int $entry_id)
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilBiblAttributeFactory

Author
: Benjamin Seglias bs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 23 of file class.ilBiblAttributeFactory.php.

Constructor & Destructor Documentation

◆ __construct()

ilBiblAttributeFactory::__construct ( protected \ilBiblFieldFactoryInterface  $field_factory)

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

References $DIC.

28  {
29  global $DIC;
30  $this->db = $DIC->database();
31  }
global $DIC
Definition: shib_login.php:26

Member Function Documentation

◆ createAttribute()

ilBiblAttributeFactory::createAttribute ( string  $name,
string  $value,
int  $entry_id 
)

Implements ilBiblAttributeFactoryInterface.

Definition at line 100 of file class.ilBiblAttributeFactory.php.

100  : bool
101  {
102  $ilBiblAttribute = new ilBiblAttribute();
103  $ilBiblAttribute->setName($name);
104  $ilBiblAttribute->setValue($value);
105  $ilBiblAttribute->setEntryId($entry_id);
106  $ilBiblAttribute->store();
107 
108  $this->field_factory->findOrCreateFieldOfAttribute($ilBiblAttribute);
109 
110  return true;
111  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getAttributesForEntry()

ilBiblAttributeFactory::getAttributesForEntry ( ilBiblEntryInterface  $entry)

Implements ilBiblAttributeFactoryInterface.

Definition at line 58 of file class.ilBiblAttributeFactory.php.

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

58  : array
59  {
60  return ilBiblAttribute::where(['entry_id' => $entry->getId()])->get();
61  }
static where($where, $operator=null)
+ Here is the call graph for this function:

◆ getPossibleValuesForFieldAndObject()

ilBiblAttributeFactory::getPossibleValuesForFieldAndObject ( ilBiblFieldInterface  $field,
int  $object_id 
)

Implements ilBiblAttributeFactoryInterface.

Definition at line 36 of file class.ilBiblAttributeFactory.php.

References $data, $q, $res, and ilBiblFieldInterface\getIdentifier().

36  : array
37  {
38  $q = "SELECT DISTINCT(a.value) FROM il_bibl_data AS d
39 JOIN il_bibl_entry AS e ON e.data_id = d.id
40 JOIN il_bibl_attribute AS a on a.entry_id = e.id
41 WHERE a.name = %s AND d.id = %s";
42 
43  $res = $this->db->queryF($q, ['text', 'integer'], [
44  $field->getIdentifier(),
45  $object_id,
46  ]);
47  $result = [];
48  while ($data = $this->db->fetchObject($res)) {
49  $result[$data->value] = $data->value;
50  }
51 
52  return $result;
53  }
$res
Definition: ltiservices.php:66
$q
Definition: shib_logout.php:23
+ Here is the call graph for this function:

◆ sortAttributes()

ilBiblAttributeFactory::sortAttributes ( array  $attributes)
Parameters

Implements ilBiblAttributeFactoryInterface.

Definition at line 75 of file class.ilBiblAttributeFactory.php.

75  : array
76  {
77  $sorted = [];
78  $type_id = $this->field_factory->getType()->getId();
79  $max = 0;
80  foreach ($attributes as $attribute) {
81  if (!$attribute->getName()) {
82  continue;
83  }
84  $field = $this->field_factory->findOrCreateFieldByTypeAndIdentifier($type_id, $attribute->getName());
85  $position = $field->getPosition();
86  $position = $position ?: $max + 1;
87 
88  $max = (max($position, $max));
89  $sorted[$position] = $attribute;
90  }
91 
92  ksort($sorted);
93 
94  return $sorted;
95  }

◆ sortAttributesArray()

ilBiblAttributeFactory::sortAttributesArray ( array  $attributes)

Implements ilBiblAttributeFactoryInterface.

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

63  : array
64  {
65  $type_id = $this->field_factory->getType()->getId();
66  uksort($attributes, function ($key_a, $key_b) use ($type_id): int {
67  $field_a = $this->field_factory->findOrCreateFieldByTypeAndIdentifier($type_id, $key_a);
68  $field_b = $this->field_factory->findOrCreateFieldByTypeAndIdentifier($type_id, $key_b);
69 
70  return $field_a->getPosition() - $field_b->getPosition();
71  });
72 
73  return $attributes;
74  }

Field Documentation

◆ $db

ilDBInterface ilBiblAttributeFactory::$db
protected

Definition at line 25 of file class.ilBiblAttributeFactory.php.


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