ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilBiblAttributeFactory.php
Go to the documentation of this file.
1 <?php
23 {
24  protected ilDBInterface $db;
25 
26  public function __construct(protected \ilBiblFieldFactoryInterface $field_factory)
27  {
28  global $DIC;
29  $this->db = $DIC->database();
30  }
31 
35  public function getPossibleValuesForFieldAndObject(ilBiblFieldInterface $field, int $object_id): array
36  {
37  $q = "SELECT DISTINCT(a.value) FROM il_bibl_data AS d
38 JOIN il_bibl_entry AS e ON e.data_id = d.id
39 JOIN il_bibl_attribute AS a on a.entry_id = e.id
40 WHERE a.name = %s AND d.id = %s";
41 
42  $res = $this->db->queryF($q, ['text', 'integer'], [
43  $field->getIdentifier(),
44  $object_id,
45  ]);
46  $result = [];
47  while ($data = $this->db->fetchObject($res)) {
48  $result[$data->value] = $data->value;
49  }
50 
51  return $result;
52  }
53 
57  public function getAttributesForEntry(ilBiblEntryInterface $entry): array
58  {
59  return ilBiblAttribute::where(['entry_id' => $entry->getId()])->get();
60  }
61 
65  public function sortAttributes(array $attributes): array
66  {
67  $sorted = [];
68  $type_id = $this->field_factory->getType()->getId();
69  $max = 0;
70  foreach ($attributes as $attribute) {
71  if (!$attribute->getName()) {
72  continue;
73  }
74  $field = $this->field_factory->findOrCreateFieldByTypeAndIdentifier($type_id, $attribute->getName());
75  $position = $field->getPosition();
76  $position = $position ?: $max + 1;
77 
78  $max = (max($position, $max));
79  $sorted[$position] = $attribute;
80  }
81 
82  ksort($sorted);
83 
84  return $sorted;
85  }
86 
90  public function createAttribute(string $name, string $value, int $entry_id): bool
91  {
92  $ilBiblAttribute = new ilBiblAttribute();
93  $ilBiblAttribute->setName($name);
94  $ilBiblAttribute->setValue($value);
95  $ilBiblAttribute->setEntryId($entry_id);
96  $ilBiblAttribute->store();
97 
98  $this->field_factory->findOrCreateFieldOfAttribute($ilBiblAttribute);
99 
100  return true;
101  }
102 }
$res
Definition: ltiservices.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPossibleValuesForFieldAndObject(ilBiblFieldInterface $field, int $object_id)
static where($where, $operator=null)
createAttribute(string $name, string $value, int $entry_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:22
__construct(protected \ilBiblFieldFactoryInterface $field_factory)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAttributesForEntry(ilBiblEntryInterface $entry)
$q
Definition: shib_logout.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...