ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilBiblFieldFactory Class Reference

Class ilBiblFieldFactory. More...

+ Inheritance diagram for ilBiblFieldFactory:
+ Collaboration diagram for ilBiblFieldFactory:

Public Member Functions

 __construct (\ilBiblTypeInterface $type)
 ilBiblFieldFactory constructor. More...
 
 getType ()
 
Returns
\ilBiblTypeInterface
More...
 
 getFieldByTypeAndIdentifier (int $type, string $identifier)
 
Parameters
int$typeMUST be ilBiblTypeFactoryInterface::DATA_TYPE_RIS or ilBiblTypeFactoryInterface::DATA_TYPE_BIBTEX
string$identifier
Returns
\ilBiblFieldInterface
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
string$identifier
Returns
\ilBiblFieldInterface
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)
 

Protected Attributes

 $type
 

Private Member Functions

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

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBiblFieldFactory::__construct ( \ilBiblTypeInterface  $type)

ilBiblFieldFactory constructor.

Parameters
\ilBiblTypeInterface$type

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

23 {
24 $this->type = $type;
25 }

References $type.

Member Function Documentation

◆ checkType()

ilBiblFieldFactory::checkType (   $type)
private
Parameters
$type
Exceptions

ilException

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

222 {
223 switch ($type) {
226 break;
227 default:
228 throw new ilException("bibliografic type not found");
229 }
230 }
Base class for ILIAS Exception handling.

References $type, ilBiblTypeFactoryInterface\DATA_TYPE_BIBTEX, and ilBiblTypeFactoryInterface\DATA_TYPE_RIS.

Referenced by findOrCreateFieldByTypeAndIdentifier(), and getFieldByTypeAndIdentifier().

+ Here is the caller graph for this function:

◆ filterAllFieldsForType()

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

@inheritDoc

Implements ilBiblFieldFactoryInterface.

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

119 : array
120 {
121 return $this->getCollectionForFilter($type, $queryInfo)->get();
122 }
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 128 of file class.ilBiblFieldFactory.php.

128 : array
129 {
130 return $this->getCollectionForFilter($type, $queryInfo)->getArray();
131 }

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
string$identifier
Returns
\ilBiblFieldInterface
Exceptions

ilException if a wrong $type is passed

Implements ilBiblFieldFactoryInterface.

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

74 {
75 $this->checkType($type);
76 $inst = $this->getARInstance($type, $identifier);
77 if (!$inst) {
78 $inst = new ilBiblField();
79 $inst->setIdentifier($identifier);
80 $inst->setDataType($type);
81 $inst->setIsStandardField((bool) $this->getType()->isStandardField($identifier));
82 $inst->create();
83 }
84 $inst->setDataType($type);
85 $inst->setIdentifier($identifier);
86 $inst->setIsStandardField((bool) $this->getType()->isStandardField($identifier));
87 $inst->update();
88
89 return $inst;
90 }
getType()
\ilBiblTypeInterface
getARInstance($type, $identifier)
Class ilField.
Interface ilBiblEntryInterface.

References $type, checkType(), 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 137 of file class.ilBiblFieldFactory.php.

138 {
139 $field = ilBiblField::where(['identifier' => $attribute->getName()])->first();
140 if ($field === null) {
141 $field = new ilBiblField();
142 $field->setIdentifier($attribute->getName());
143 $field->setDataType($this->type->getId());
144 $field->setIsStandardField($this->type->isStandardField($attribute->getName()));
145 $field->create();
146 } else {
147 $field->setDataType($this->type->getId());
148 $field->update();
149 }
150
151 return $field;
152 }
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 158 of file class.ilBiblFieldFactory.php.

158 : int
159 {
160 global $DIC;
161 $tablename = ilBiblField::TABLE_NAME;
162 $q = "UPDATE {$tablename} SET position = position + 1 WHERE data_type = %s AND position >= %s;";
163 $DIC->database()->manipulateF(
164 $q,
165 ['integer', 'integer'],
166 [
167 $field->getDataType(),
168 $field->getPosition(),
169 ]
170 );
171 $field->store();
172 $DIC->database()->query("SET @i=0");
173 $DIC->database()->manipulateF(
174 "UPDATE {$tablename} SET position = (@i := @i + 1) WHERE data_type = %s ORDER BY position",
175 ['integer'],
176 [
177 $field->getDataType(),
178 ]
179 );
180
181 return (int) $field->getPosition();
182 }
store()
Stores the Object, creates a newone in Db if non existing or updates an existing.
$DIC
Definition: xapitoken.php:46

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

+ Here is the call graph for this function:

◆ getARInstance()

ilBiblFieldFactory::getARInstance (   $type,
  $identifier 
)
private
Parameters
int$type
string$identifier
Returns
\ilBiblField

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

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

References $type, and 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 96 of file class.ilBiblFieldFactory.php.

96 : array
97 {
98 global $DIC;
99 $sql
100 = "SELECT DISTINCT(il_bibl_attribute.name), il_bibl_data.file_type FROM il_bibl_data
101 JOIN il_bibl_entry ON il_bibl_entry.data_id = il_bibl_data.id
102 JOIN il_bibl_attribute ON il_bibl_attribute.entry_id = il_bibl_entry.id
103 WHERE il_bibl_data.id = %s;";
104
105 $result = $DIC->database()->queryF($sql, ['integer'], [$obj_id]);
106
107 $data = [];
108 while ($d = $DIC->database()->fetchObject($result)) {
109 $data[] = $this->findOrCreateFieldByTypeAndIdentifier($d->file_type, $d->name);
110 }
111
112 return $data;
113 }
$result
findOrCreateFieldByTypeAndIdentifier(int $type, string $identifier)
\ilBiblFieldInterface ilException if a wrong $type is passed
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$data
Definition: storeScorm.php:23

References $d, $data, $DIC, $result, and findOrCreateFieldByTypeAndIdentifier().

+ Here is the call graph for this function:

◆ getCollectionForFilter()

ilBiblFieldFactory::getCollectionForFilter ( ilBiblTypeInterface  $type,
ilBiblTableQueryInfoInterface  $queryInfo = null 
)
private
Parameters
\ilBiblTypeInterface$type
\ilBiblTableQueryInfoInterface$queryInfo
Returns
\ActiveRecordList

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

240 {
241 $collection = ilBiblField::getCollection();
242
243 $collection->where(array('data_type' => $type->getId()));
244
245 if ($queryInfo) {
246 $sorting_column = $queryInfo->getSortingColumn() ? $queryInfo->getSortingColumn() : null;
247 $offset = $queryInfo->getOffset() ? $queryInfo->getOffset() : 0;
248 $sorting_direction = $queryInfo->getSortingDirection();
249 $limit = $queryInfo->getLimit();
250 if ($sorting_column) {
251 $collection->orderBy($sorting_column, $sorting_direction);
252 }
253 $collection->limit($offset, $limit);
254
255 foreach ($queryInfo->getFilters() as $queryFilter) {
256 switch ($queryFilter->getFieldName()) {
257 default:
258 $collection->where(array($queryFilter->getFieldName() => $queryFilter->getFieldValue()), $queryFilter->getOperator());
259 break;
260 }
261 }
262 }
263
264 return $collection;
265 }

References $type, and ActiveRecord\getCollection().

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
string$identifier
Returns
\ilBiblFieldInterface
Exceptions

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

Implements ilBiblFieldFactoryInterface.

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

59 {
60 $this->checkType($type);
61 $inst = $this->getARInstance($type, $identifier);
62 if (!$inst) {
63 throw new ilException("bibliografic identifier {$identifier} not found");
64 }
65
66 return $inst;
67 }

References checkType(), and getARInstance().

+ Here is the call graph for this function:

◆ getNextFreePosition()

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

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

192 : int
193 {
194 global $DIC;
195 $tablename = ilBiblField::TABLE_NAME;
196 $q = "SELECT MAX(position) + 1 as next_position FROM {$tablename} WHERE data_type = %s;";
197 $res = $DIC->database()->queryF($q, ['integer'], [$field->getDataType()]);
198 $data = $DIC->database()->fetchObject($res);
199
200 return (int) $data->next_position;
201 }
foreach($_POST as $key=> $value) $res

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

+ Here is the call graph for this function:

◆ getType()

ilBiblFieldFactory::getType ( )

Returns
\ilBiblTypeInterface

Implements ilBiblFieldFactoryInterface.

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

32 {
33 return $this->type;
34 }
Interface ilBiblTypeInterface.

References $type.

Referenced by findOrCreateFieldByTypeAndIdentifier().

+ Here is the caller graph for this function:

Field Documentation

◆ $type

ilBiblFieldFactory::$type
protected

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