ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilBiblFieldFactory 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 ilBiblFieldFactory:
+ Collaboration diagram for ilBiblFieldFactory:

Public Member Functions

 __construct (protected \ilBiblTypeInterface $type)
 ilBiblFieldFactory constructor. More...
 
 getType ()
 
 getFieldByTypeAndIdentifier (int $type, string $identifier)
 
Parameters
int$typeMUST be ilBiblTypeFactoryInterface::DATA_TYPE_RIS or ilBiblTypeFactoryInterface::DATA_TYPE_BIBTEX
Exceptions

ilException if a wrong $type is passed or field is not found More...

 
 findOrCreateFieldByTypeAndIdentifier (int $type, string $identifier)
 
Parameters
int$typeMUST be ilBiblTypeFactoryInterface::DATA_TYPE_RIS or ilBiblTypeFactoryInterface::DATA_TYPE_BIBTEX
Exceptions

ilException if a wrong $type is passed More...

 
 getAvailableFieldsForObjId (int $obj_id)
 @inheritDoc More...
 
 filterAllFieldsForType (ilBiblTypeInterface $type, ?ilBiblTableQueryInfoInterface $queryInfo=null)
 @inheritDoc More...
 
 filterAllFieldsForTypeAsArray (ilBiblTypeInterface $type, ?ilBiblTableQueryInfoInterface $queryInfo=null)
 @inheritDoc More...
 
 findOrCreateFieldOfAttribute (ilBiblAttributeInterface $attribute)
 @inheritDoc More...
 
 forcePosition (ilBiblFieldInterface $field)
 @inheritDoc More...
 
- Public Member Functions inherited from ilBiblFieldFactoryInterface
 getFieldByTypeAndIdentifier (int $type, string $identifier)
 
 findOrCreateFieldByTypeAndIdentifier (int $type, string $identifier)
 
 getAvailableFieldsForObjId (int $obj_id)
 
 filterAllFieldsForType (ilBiblTypeInterface $type, ?ilBiblTableQueryInfoInterface $queryInfo=null)
 
 filterAllFieldsForTypeAsArray (ilBiblTypeInterface $type, ?ilBiblTableQueryInfoInterface $queryInfo=null)
 
 getType ()
 
 findById (int $id)
 
 findOrCreateFieldOfAttribute (ilBiblAttributeInterface $attribute)
 
 forcePosition (ilBiblFieldInterface $field)
 

Private Member Functions

 getNextFreePosition (ilBiblFieldInterface $field)
 
 getARInstance (int $type, string $identifier)
 
 getCollectionForFilter (ilBiblTypeInterface $type, ?ilBiblTableQueryInfoInterface $queryInfo=null)
 

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 ilBiblFieldFactory

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 24 of file class.ilBiblFieldFactory.php.

Constructor & Destructor Documentation

◆ __construct()

ilBiblFieldFactory::__construct ( protected \ilBiblTypeInterface  $type)

ilBiblFieldFactory constructor.

Definition at line 29 of file class.ilBiblFieldFactory.php.

30 {
31 }

Member Function Documentation

◆ filterAllFieldsForType()

ilBiblFieldFactory::filterAllFieldsForType ( ilBiblTypeInterface  $type,
?ilBiblTableQueryInfoInterface  $queryInfo = null 
)

@inheritDoc

Implements ilBiblFieldFactoryInterface.

Definition at line 124 of file class.ilBiblFieldFactory.php.

124 : array
125 {
126 return $this->getCollectionForFilter($type, $queryInfo)->get();
127 }
getCollectionForFilter(ilBiblTypeInterface $type, ?ilBiblTableQueryInfoInterface $queryInfo=null)

References getCollectionForFilter().

+ Here is the call graph for this function:

◆ filterAllFieldsForTypeAsArray()

ilBiblFieldFactory::filterAllFieldsForTypeAsArray ( ilBiblTypeInterface  $type,
?ilBiblTableQueryInfoInterface  $queryInfo = null 
)

@inheritDoc

Implements ilBiblFieldFactoryInterface.

Definition at line 133 of file class.ilBiblFieldFactory.php.

133 : array
134 {
135 return $this->getCollectionForFilter($type, $queryInfo)->getArray();
136 }

References getCollectionForFilter().

+ Here is the call graph for this function:

◆ findOrCreateFieldByTypeAndIdentifier()

ilBiblFieldFactory::findOrCreateFieldByTypeAndIdentifier ( int  $type,
string  $identifier 
)

Parameters
int$typeMUST be ilBiblTypeFactoryInterface::DATA_TYPE_RIS or ilBiblTypeFactoryInterface::DATA_TYPE_BIBTEX
Exceptions

ilException if a wrong $type is passed

Implements ilBiblFieldFactoryInterface.

Definition at line 79 of file class.ilBiblFieldFactory.php.

80 {
81 $inst = $this->getARInstance($type, $identifier);
82 if ($inst === null) {
83 $inst = new ilBiblField();
84 $inst->setIdentifier($identifier);
85 $inst->setDataType($type);
86 $inst->setIsStandardField($this->getType()->isStandardField($identifier));
87 $inst->create();
88 }
89 $inst->setDataType($type);
90 $inst->setIdentifier($identifier);
91 $inst->setIsStandardField($this->getType()->isStandardField($identifier));
92 $inst->update();
93
94 return $inst;
95 }
getARInstance(int $type, string $identifier)
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...

References getARInstance(), and getType().

Referenced by getAvailableFieldsForObjId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findOrCreateFieldOfAttribute()

ilBiblFieldFactory::findOrCreateFieldOfAttribute ( ilBiblAttributeInterface  $attribute)

@inheritDoc

Implements ilBiblFieldFactoryInterface.

Definition at line 142 of file class.ilBiblFieldFactory.php.

143 {
144 $field = ilBiblField::where(['identifier' => $attribute->getName()])->first();
145 if ($field === null) {
146 $field = new ilBiblField();
147 $field->setIdentifier($attribute->getName());
148 $field->setDataType($this->type->getId());
149 $field->setIsStandardField($this->type->isStandardField($attribute->getName()));
150 $field->create();
151 } else {
152 $field->setDataType($this->type->getId());
153 $field->update();
154 }
155
156 return $field;
157 }
static where($where, $operator=null)

References ilBiblAttributeInterface\getName(), and ActiveRecord\where().

+ Here is the call graph for this function:

◆ forcePosition()

ilBiblFieldFactory::forcePosition ( ilBiblFieldInterface  $field)

@inheritDoc

Implements ilBiblFieldFactoryInterface.

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

163 : int
164 {
165 global $DIC;
166 $tablename = ilBiblField::TABLE_NAME;
167 $q = "UPDATE {$tablename} SET position = position + 1 WHERE data_type = %s AND position >= %s;";
168 $DIC->database()->manipulateF(
169 $q,
170 ['integer', 'integer'],
171 [
172 $field->getDataType(),
173 $field->getPosition(),
174 ]
175 );
176 $field->store();
177 $DIC->database()->query("SET @i=0");
178 $DIC->database()->manipulateF(
179 "UPDATE {$tablename} SET position = (@i := @i + 1) WHERE data_type = %s ORDER BY position",
180 ['integer'],
181 [
182 $field->getDataType(),
183 ]
184 );
185
186 return (int) $field->getPosition();
187 }
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23

References $DIC, $q, ilBiblFieldInterface\getDataType(), ilBiblFieldInterface\getPosition(), ilBiblFieldInterface\store(), and ilBiblField\TABLE_NAME.

+ Here is the call graph for this function:

◆ getARInstance()

ilBiblFieldFactory::getARInstance ( int  $type,
string  $identifier 
)
private

Definition at line 209 of file class.ilBiblFieldFactory.php.

209 : ?\ilBiblField
210 {
211 return ilBiblField::where(["identifier" => $identifier, "data_type" => $type])->first();
212 }

References ActiveRecord\where().

Referenced by findOrCreateFieldByTypeAndIdentifier(), and getFieldByTypeAndIdentifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAvailableFieldsForObjId()

ilBiblFieldFactory::getAvailableFieldsForObjId ( int  $obj_id)

@inheritDoc

Implements ilBiblFieldFactoryInterface.

Definition at line 101 of file class.ilBiblFieldFactory.php.

101 : array
102 {
103 global $DIC;
104 $sql
105 = "SELECT DISTINCT(il_bibl_attribute.name), il_bibl_data.file_type FROM il_bibl_data
106 JOIN il_bibl_entry ON il_bibl_entry.data_id = il_bibl_data.id
107 JOIN il_bibl_attribute ON il_bibl_attribute.entry_id = il_bibl_entry.id
108 WHERE il_bibl_data.id = %s;";
109
110 $result = $DIC->database()->queryF($sql, ['integer'], [$obj_id]);
111
112 $data = [];
113 while ($d = $DIC->database()->fetchObject($result)) {
114 $data[] = $this->findOrCreateFieldByTypeAndIdentifier($d->file_type, $d->name);
115 }
116
117 return $data;
118 }
findOrCreateFieldByTypeAndIdentifier(int $type, string $identifier)
ilException if a wrong $type is passed

References Vendor\Package\$d, $data, $DIC, and findOrCreateFieldByTypeAndIdentifier().

+ Here is the call graph for this function:

◆ getCollectionForFilter()

ilBiblFieldFactory::getCollectionForFilter ( ilBiblTypeInterface  $type,
?ilBiblTableQueryInfoInterface  $queryInfo = null 
)
private

Definition at line 215 of file class.ilBiblFieldFactory.php.

216 {
217 $collection = ilBiblField::getCollection();
218
219 $collection->where(['data_type' => $type->getId()]);
220
221 if ($queryInfo !== null) {
222 $sorting_column = $queryInfo->getSortingColumn() !== '' && $queryInfo->getSortingColumn() !== '0' ? $queryInfo->getSortingColumn() : null;
223 $offset = $queryInfo->getOffset();
224 $sorting_direction = $queryInfo->getSortingDirection();
225 $limit = $queryInfo->getLimit();
226 if ($sorting_column) {
227 $collection->orderBy($sorting_column, $sorting_direction);
228 }
229 $collection->limit($offset, $limit);
230
231 foreach ($queryInfo->getFilters() as $queryFilter) {
232 $collection->where([$queryFilter->getFieldName() => $queryFilter->getFieldValue()], $queryFilter->getOperator());
233 }
234 }
235
236 return $collection;
237 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ActiveRecord\getCollection(), and ilBiblTypeInterface\getId().

Referenced by filterAllFieldsForType(), and filterAllFieldsForTypeAsArray().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFieldByTypeAndIdentifier()

ilBiblFieldFactory::getFieldByTypeAndIdentifier ( int  $type,
string  $identifier 
)

Parameters
int$typeMUST be ilBiblTypeFactoryInterface::DATA_TYPE_RIS or ilBiblTypeFactoryInterface::DATA_TYPE_BIBTEX
Exceptions

ilException if a wrong $type is passed or field is not found

@noinspection PhpIncompatibleReturnTypeInspection

Implements ilBiblFieldFactoryInterface.

Definition at line 64 of file class.ilBiblFieldFactory.php.

65 {
66 $inst = $this->getARInstance($type, $identifier);
67 if ($inst === null) {
68 throw new ilException("bibliografic identifier {$identifier} not found");
69 }
70
72 return $inst;
73 }
Base class for ILIAS Exception handling.

References getARInstance().

+ Here is the call graph for this function:

◆ getNextFreePosition()

ilBiblFieldFactory::getNextFreePosition ( ilBiblFieldInterface  $field)
private
Parameters
ilBiblFieldInterface$field
Returns
int

Definition at line 197 of file class.ilBiblFieldFactory.php.

197 : int
198 {
199 global $DIC;
200 $tablename = ilBiblField::TABLE_NAME;
201 $q = "SELECT MAX(position) + 1 as next_position FROM {$tablename} WHERE data_type = %s;";
202 $res = $DIC->database()->queryF($q, ['integer'], [$field->getDataType()]);
203 $data = $DIC->database()->fetchObject($res);
204
205 return (int) $data->next_position;
206 }
$res
Definition: ltiservices.php:69

References $data, $DIC, $q, $res, ilBiblFieldInterface\getDataType(), and ilBiblField\TABLE_NAME.

+ Here is the call graph for this function:

◆ getType()

ilBiblFieldFactory::getType ( )

Implements ilBiblFieldFactoryInterface.

Definition at line 37 of file class.ilBiblFieldFactory.php.

38 {
39 return $this->type;
40 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Referenced by findOrCreateFieldByTypeAndIdentifier().

+ Here is the caller graph for this function:

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