ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilBiblAttributeFactory.php
Go to the documentation of this file.
1<?php
9{
10
14 protected $field_factory;
15
16
18 {
19 $this->field_factory = $field_factory;
20 }
21
22
26 public function getPossibleValuesForFieldAndObject(ilBiblFieldInterface $field, $object_id)
27 {
28 global $DIC;
29 $q = "SELECT DISTINCT(a.value) FROM il_bibl_data AS d
30JOIN il_bibl_entry AS e ON e.data_id = d.id
31JOIN il_bibl_attribute AS a on a.entry_id = e.id
32WHERE a.name = %s AND d.id = %s";
33
34 $res = $DIC->database()->queryF($q, ['text', 'integer'], [
35 $field->getIdentifier(),
36 $object_id,
37 ]);
38 $result = [];
39 while ($data = $DIC->database()->fetchObject($res)) {
40 $result[$data->value] = $data->value;
41 }
42
43 return $result;
44 }
45
46
51 {
52 return ilBiblAttribute::where(['entry_id' => $entry->getId()])->get();
53 }
54
55
59 public function sortAttributes(array $attributes)
60 {
64 $sorted = [];
65 $type_id = $this->field_factory->getType()->getId();
66 $max = 0;
67 foreach ($attributes as $attribute) {
68 if (!$attribute->getName()) {
69 continue;
70 }
71 $field = $this->field_factory->findOrCreateFieldByTypeAndIdentifier($type_id, $attribute->getName());
72 $position = (int) $field->getPosition();
73 $position = $position ? $position : $max + 1;
74
75 $max = ($position > $max ? $position : $max);
76 $sorted[$position] = $attribute;
77 }
78
79 ksort($sorted);
80
81 return $sorted;
82 }
83
84
88 public function createAttribute($name, $value, $entry_id)
89 {
90 $ilBiblAttribute = new ilBiblAttribute();
91 $ilBiblAttribute->setName($name);
92 $ilBiblAttribute->setValue($value);
93 $ilBiblAttribute->setEntryId($entry_id);
94 $ilBiblAttribute->store();
95
96 $this->field_factory->findOrCreateFieldOfAttribute($ilBiblAttribute);
97 }
98}
$result
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
Class ilBiblAttributeFactory.
getAttributesForEntry(ilBiblEntryInterface $entry)
@inheritDoc
createAttribute($name, $value, $entry_id)
@inheritDoc
__construct(ilBiblFieldFactoryInterface $field_factory)
getPossibleValuesForFieldAndObject(ilBiblFieldInterface $field, $object_id)
@inheritDoc
Class ilBiblAttribute.
Interface ilBiblAttributeFactoryInterface.
sortAttributes(array $attributes)
Interface ilBiblEntryInterface.
Interface ilBiblFieldFactoryInterface.
Interface ilBiblEntryInterface.
if($format !==null) $name
Definition: metadata.php:230
$attributes
Definition: metadata.php:231
foreach($_POST as $key=> $value) $res
$data
Definition: storeScorm.php:23
$DIC
Definition: xapitoken.php:46