ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBiblAttributeFactory.php
Go to the documentation of this file.
1<?php
9{
10
14 protected $field_factory;
15
17 {
18 $this->field_factory = $field_factory;
19 }
20
21
25 public function getPossibleValuesForFieldAndObject(ilBiblFieldInterface $field, $object_id)
26 {
27 global $DIC;
28 $q = "SELECT DISTINCT(a.value) FROM il_bibl_data AS d
29JOIN il_bibl_entry AS e ON e.data_id = d.id
30JOIN il_bibl_attribute AS a on a.entry_id = e.id
31WHERE a.name = %s AND d.id = %s";
32
33 $res = $DIC->database()->queryF($q, [ 'text', 'integer' ], [
34 $field->getIdentifier(),
35 $object_id,
36 ]);
37 $result = [];
38 while ($data = $DIC->database()->fetchObject($res)) {
39 $result[$data->value] = $data->value;
40 }
41
42 return $result;
43 }
44
45
50 {
51 return ilBiblAttribute::where([ 'entry_id' => $entry->getId() ])->get();
52 }
53
54
58 public function sortAttributes(array $attributes)
59 {
63 $sorted = [];
64 $type_id = $this->field_factory->getType()->getId();
65 $max = 0;
66 foreach ($attributes as $attribute) {
67 if (!$attribute->getName()) {
68 continue;
69 }
70 $field = $this->field_factory->findOrCreateFieldByTypeAndIdentifier($type_id, $attribute->getName());
71 $position = (int) $field->getPosition();
72 $position = $position ? $position : $max + 1;
73
74 $max = ($position > $max ? $position : $max);
75 $sorted[$position] = $attribute;
76 }
77
78 ksort($sorted);
79
80 return $sorted;
81 }
82
83
87 public function createAttribute($name, $value, $entry_id)
88 {
89 $ilBiblAttribute = new ilBiblAttribute();
90 $ilBiblAttribute->setName($name);
91 $ilBiblAttribute->setValue($value);
92 $ilBiblAttribute->setEntryId($entry_id);
93 $ilBiblAttribute->store();
94
95 $this->field_factory->findOrCreateFieldOfAttribute($ilBiblAttribute);
96 }
97}
$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.
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
Interface ilBiblAttributeFactoryInterface.
sortAttributes(array $attributes)
Interface ilBiblEntryInterface.
Interface ilBiblFieldFactoryInterface.
Interface ilBiblEntryInterface.
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$data
Definition: bench.php:6