ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilAdvancedMDValues Class Reference
+ Collaboration diagram for ilAdvancedMDValues:

Public Member Functions

 __construct ($a_record_id, $a_obj_id, $a_sub_type="-", $a_sub_id=0)
 Constructor. More...
 
 getDefinitions ()
 Get record field definitions. More...
 
 getADTGroup ()
 Init ADT group for current record. More...
 
 isDisabled ($a_element_id)
 Is element disabled? More...
 
 read ()
 Get record values. More...
 
 write (array $a_additional_data=null)
 Write record values. More...
 

Static Public Member Functions

static getInstancesForObjectId ($a_obj_id, $a_obj_type=null, $a_sub_type="-", $a_sub_id=0)
 Get instances for given object id. More...
 
static findByObjectId ($a_obj_id)
 Find all entries for object (regardless of sub-type/sub-id) More...
 
static _deleteByFieldId ($a_field_id, ilADT $a_adt)
 Delete values by field_id. More...
 
static _deleteByObjId ($a_obj_id)
 Delete by objekt id. More...
 
static preloadByObjIds (array $a_obj_ids)
 Preload list gui data. More...
 
static preloadedRead ($a_type, $a_obj_id)
 
static _cloneValues ($a_source_id, $a_target_id, $a_sub_type=null, $a_source_sub_id=null, $a_target_sub_id=null)
 Clone Advanced Meta Data. More...
 
static _appendXMLByObjId (ilXmlWriter $a_xml_writer, $a_obj_id)
 Get xml of object values. More...
 
static queryForRecords ($a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key, array $a_amet_filter=null)
 Query data for given object records. More...
 

Protected Member Functions

 getActiveRecord ()
 Init ADT DB Bridge (aka active record helper class) More...
 

Protected Attributes

 $record_id
 
 $obj_id
 
 $sub_id
 
 $sub_type
 
 $defs
 
 $adt_group
 
 $active_record
 
 $disabled
 

Static Protected Attributes

static $preload_obj_records
 

Detailed Description

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 15 of file class.ilAdvancedMDValues.php.

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDValues::__construct (   $a_record_id,
  $a_obj_id,
  $a_sub_type = "-",
  $a_sub_id = 0 
)

Constructor.

Parameters
int$a_record_id
string$a_obj_id
string$a_sub_type
int$a_sub_id
Returns
self

Definition at line 39 of file class.ilAdvancedMDValues.php.

40  {
41  $this->record_id = (int)$a_record_id;
42  $this->obj_id = (int)$a_obj_id;
43  $this->sub_type = $a_sub_type ? $a_sub_type : "-";
44  $this->sub_id = (int)$a_sub_id;
45  }

Member Function Documentation

◆ _appendXMLByObjId()

static ilAdvancedMDValues::_appendXMLByObjId ( ilXmlWriter  $a_xml_writer,
  $a_obj_id 
)
static

Get xml of object values.

Parameters
ilXmlWriter$a_xml_writer
int$a_obj_id

Definition at line 373 of file class.ilAdvancedMDValues.php.

References $defs, ilObject\_lookupType(), ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by ilCourseXMLWriter\__buildAdvancedMetaData().

374  {
375  $a_xml_writer->xmlStartTag('AdvancedMetaData');
376 
377  self::preloadByObjIds(array($a_obj_id));
378  $values_records = self::preloadedRead(ilObject::_lookupType($a_obj_id), $a_obj_id);
379 
380  foreach($values_records as $values_record)
381  {
382  $defs = $values_record->getDefinitions();
383  foreach($values_record->getADTGroup()->getElements() as $element_id => $element)
384  {
385  $def = $defs[$element_id];
386 
387  $value = null;
388  if(!$element->isNull())
389  {
390  $value = $def->getValueForXML($element);
391  }
392 
393  $a_xml_writer->xmlElement(
394  'Value',
395  array('id' => $def->getImportId()),
396  $value
397  );
398  }
399  }
400 
401  $a_xml_writer->xmlEndTag('AdvancedMetaData');
402  }
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
xmlEndTag($tag)
Writes an endtag.
static _lookupType($a_id, $a_reference=false)
lookup object type
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _cloneValues()

static ilAdvancedMDValues::_cloneValues (   $a_source_id,
  $a_target_id,
  $a_sub_type = null,
  $a_source_sub_id = null,
  $a_target_sub_id = null 
)
static

Clone Advanced Meta Data.

Parameters
intsource obj_id
inttarget obj_id
stringsub_type (both source/target)
intsource sub_id
inttarget sub_id

Definition at line 325 of file class.ilAdvancedMDValues.php.

References $ilLog, ilADTActiveRecordByType\cloneByPrimary(), and ilADTFactory\getInstance().

Referenced by ilObject\cloneObject(), and ilObjWiki\createWikiPage().

326  {
327  global $ilLog;
328 
329  $source_primary = array("obj_id"=>array("integer", $a_source_id));
330  $target_primary = array("obj_id"=>array("integer", $a_target_id));
331 
332  // sub-type support
333  if($a_sub_type &&
334  $a_source_sub_id &&
335  $a_target_sub_id)
336  {
337  $source_primary["sub_type"] = array("text", $a_sub_type);
338  $source_primary["sub_id"] = array("integer", $a_source_sub_id);
339  $target_primary["sub_type"] = array("text", $a_sub_type);
340  $target_primary["sub_id"] = array("integer", $a_target_sub_id);
341  }
342 
343  ilADTFactory::getInstance()->initActiveRecordByType();
345  "adv_md_values",
346  array(
347  "obj_id" => "integer",
348  "sub_type" => "text",
349  "sub_id" => "integer",
350  "field_id" => "integer"
351  ),
352  $source_primary,
353  $target_primary,
354  array("disabled"=>"integer"));
355 
356  if(!$has_cloned)
357  {
358  $ilLog->write(__METHOD__.': No advanced meta data found.');
359  }
360  else
361  {
362  $ilLog->write(__METHOD__.': Start cloning advanced meta data.');
363  }
364  return true;
365  }
static getInstance()
Get singleton.
static cloneByPrimary($a_table, array $a_primary_def, array $a_source_primary, array $a_target_primary, array $a_additional=null)
Clone values by (partial) primary key.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _deleteByFieldId()

static ilAdvancedMDValues::_deleteByFieldId (   $a_field_id,
ilADT  $a_adt 
)
static

Delete values by field_id.

Typically called after deleting a field

Parameters
int$a_field_id
ilADT$a_adt

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

References ilADTActiveRecordByType\deleteByPrimary(), ilADTFactory\getInstance(), and ilADT\getType().

Referenced by ilAdvancedMDFieldDefinition\delete().

216  {
217  ilADTFactory::getInstance()->initActiveRecordByType();
219  "adv_md_values",
220  array("field_id"=>array("integer", $a_field_id)),
221  $a_adt->getType());
222  }
getType()
Get type (from class/instance)
Definition: class.ilADT.php:51
static getInstance()
Get singleton.
static deleteByPrimary($a_table, array $a_primary, $a_type=null)
Delete values by (partial) primary key.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _deleteByObjId()

static ilAdvancedMDValues::_deleteByObjId (   $a_obj_id)
static

Delete by objekt id.

Parameters
int$a_obj_id

Definition at line 229 of file class.ilAdvancedMDValues.php.

References ilADTActiveRecordByType\deleteByPrimary(), and ilADTFactory\getInstance().

Referenced by ilObject\delete().

230  {
231  ilADTFactory::getInstance()->initActiveRecordByType();
233  "adv_md_values",
234  array("obj_id"=>array("integer", $a_obj_id)));
235  }
static getInstance()
Get singleton.
static deleteByPrimary($a_table, array $a_primary, $a_type=null)
Delete values by (partial) primary key.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findByObjectId()

static ilAdvancedMDValues::findByObjectId (   $a_obj_id)
static

Find all entries for object (regardless of sub-type/sub-id)

Parameters
int$a_obj_id
Returns
array

Definition at line 145 of file class.ilAdvancedMDValues.php.

References ilADTFactory\initActiveRecordByType(), and ilADTActiveRecordByType\readByPrimary().

Referenced by ilAdvancedMetaDataExporter\getXmlRepresentation().

146  {
147  include_once "Services/ADT/classes/class.ilADTFactory.php";
149  return ilADTActiveRecordByType::readByPrimary("adv_md_values", array("obj_id"=>array("integer", $a_obj_id)));
150  }
static initActiveRecordByType()
Init active record by type.
static readByPrimary($a_table, array $a_primary, $a_type=null)
Read directly.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getActiveRecord()

ilAdvancedMDValues::getActiveRecord ( )
protected

Init ADT DB Bridge (aka active record helper class)

Returns
ilADTActiveRecordByType

Definition at line 106 of file class.ilAdvancedMDValues.php.

References $active_record, getADTGroup(), and ilADTFactory\getInstance().

Referenced by read(), and write().

107  {
108  if(!$this->active_record instanceof ilADTActiveRecordByType)
109  {
110  include_once "Services/ADT/classes/class.ilADTFactory.php";
111  $factory = ilADTFactory::getInstance();
112 
113  $adt_group_db = $factory->getDBBridgeForInstance($this->getADTGroup());
114 
115  $primary = array(
116  "obj_id" => array("integer", $this->obj_id),
117  "sub_type" => array("text", $this->sub_type),
118  "sub_id" => array("integer", $this->sub_id)
119  );
120  $adt_group_db->setPrimary($primary);
121  $adt_group_db->setTable("adv_md_values");
122 
123  // multi-enum fakes single in adv md
124  foreach($adt_group_db->getElements() as $element)
125  {
126  if($element->getADT()->getType() == "MultiEnum")
127  {
128  $element->setFakeSingle(true);
129  }
130  }
131 
132  $this->active_record = $factory->getActiveRecordByTypeInstance($adt_group_db);
133  $this->active_record->setElementIdColumn("field_id", "integer");
134  }
135 
136  return $this->active_record;
137  }
ADT Active Record by type helper class.
static getInstance()
Get singleton.
getADTGroup()
Init ADT group for current record.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getADTGroup()

ilAdvancedMDValues::getADTGroup ( )

Init ADT group for current record.

Returns
ilADTGroup

Definition at line 92 of file class.ilAdvancedMDValues.php.

References $adt_group, ilAdvancedMDFieldDefinition\getADTGroupForDefinitions(), and getDefinitions().

Referenced by getActiveRecord().

93  {
94  if(!$this->adt_group instanceof ilADTGroup)
95  {
97  }
98  return $this->adt_group;
99  }
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
getDefinitions()
Get record field definitions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefinitions()

ilAdvancedMDValues::getDefinitions ( )

Get record field definitions.

Returns
array

Definition at line 78 of file class.ilAdvancedMDValues.php.

References $defs, and ilAdvancedMDFieldDefinition\getInstancesByRecordId().

Referenced by getADTGroup().

79  {
80  if(!is_array($this->defs))
81  {
82  $this->defs = ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->record_id);
83  }
84  return $this->defs;
85  }
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstancesForObjectId()

static ilAdvancedMDValues::getInstancesForObjectId (   $a_obj_id,
  $a_obj_type = null,
  $a_sub_type = "-",
  $a_sub_id = 0 
)
static

Get instances for given object id.

Parameters
int$a_obj_id
string$a_obj_type
Returns
array

Definition at line 54 of file class.ilAdvancedMDValues.php.

References $res, ilAdvancedMDRecord\_getSelectedRecordsByObject(), and ilObject\_lookupType().

Referenced by ilECSUtils\getAdvancedMDValuesForObjId(), ilAdvancedMDValueParser\handlerBeginTag(), ilRemoteObjectBase\importMetadataFromJson(), ilAdvancedMDRecordGUI\parseInfoPage(), and ilObjOrgUnit\setOrgUnitTypeId().

55  {
56  $res = array();
57 
58  if(!$a_obj_type)
59  {
60  $a_obj_type = ilObject::_lookupType($a_obj_id);
61  }
62 
63  include_once "Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
64  foreach(ilAdvancedMDRecord::_getSelectedRecordsByObject($a_obj_type, $a_obj_id, $a_sub_type) as $record)
65  {
66  $id = $record->getRecordId();
67  $res[$id] = new self($id, $a_obj_id, $a_sub_type, $a_sub_id);
68  }
69 
70  return $res;
71  }
static _getSelectedRecordsByObject($a_obj_type, $a_obj_id, $a_sub_type="")
Get selected records by object.
static _lookupType($a_id, $a_reference=false)
lookup object type
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDisabled()

ilAdvancedMDValues::isDisabled (   $a_element_id)

Is element disabled?

Parameters
string$a_element_id
Returns
bool

Definition at line 165 of file class.ilAdvancedMDValues.php.

166  {
167  if(is_array($this->disabled))
168  {
169  return in_array($a_element_id, $this->disabled);
170  }
171  }

◆ preloadByObjIds()

static ilAdvancedMDValues::preloadByObjIds ( array  $a_obj_ids)
static

Preload list gui data.

Parameters
array$a_obj_ids

Definition at line 248 of file class.ilAdvancedMDValues.php.

References $ilDB, $query, $row, ilADTFactory\getInstance(), and ilADTActiveRecordByType\preloadByPrimary().

Referenced by ilObjectListGUIPreloader\preload().

249  {
250  global $ilDB;
251 
252  // preload values
253  ilADTFactory::getInstance()->initActiveRecordByType();
255  "adv_md_values",
256  array("obj_id"=>array("integer", $a_obj_ids)));
257 
258 
259  // preload record ids for object types
260 
261  self::$preload_obj_records = array();
262 
263  // get active records for object types
264  $query = "SELECT amro.*".
265  " FROM adv_md_record_objs amro".
266  " JOIN adv_md_record amr ON (amr.record_id = amro.record_id)".
267  " WHERE active = ".$ilDB->quote(1, "integer");
268  $set = $ilDB->query($query);
269  while($row = $ilDB->fetchAssoc($set))
270  {
271  self::$preload_obj_records[$row["obj_type"]][] = array($row["record_id"], $row["optional"]);
272  }
273  }
static getInstance()
Get singleton.
static preloadByPrimary($a_table, array $a_primary)
Read values by (partial) primary key.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ preloadedRead()

static ilAdvancedMDValues::preloadedRead (   $a_type,
  $a_obj_id 
)
static

Definition at line 275 of file class.ilAdvancedMDValues.php.

References $record_id, $res, and ilAdvancedMDRecord\_getSelectedRecordsByObject().

Referenced by ilAdvancedMDSubstitution\getParsedSubstitutions().

276  {
277  $res = array();
278 
279  if(isset(self::$preload_obj_records[$a_type]))
280  {
281  foreach(self::$preload_obj_records[$a_type] as $item)
282  {
283  $record_id = $item[0];
284 
285  // record is optional, check activation for object
286  if($item[1])
287  {
288  $found = false;
289  include_once "Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
290  foreach(ilAdvancedMDRecord::_getSelectedRecordsByObject($a_type, $a_obj_id) as $record)
291  {
292  if($record->getRecordId() == $item[0])
293  {
294  $found = true;
295  }
296  }
297  if(!$found)
298  {
299  continue;
300  }
301  }
302 
303  $res[$record_id] = new self($record_id, $a_obj_id);
304  $res[$record_id]->read();
305  }
306  }
307 
308  return $res;
309  }
static _getSelectedRecordsByObject($a_obj_type, $a_obj_id, $a_sub_type="")
Get selected records by object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ queryForRecords()

static ilAdvancedMDValues::queryForRecords (   $a_obj_id,
  $a_subtype,
  $a_records,
  $a_obj_id_key,
  $a_obj_subid_key,
array  $a_amet_filter = null 
)
static

Query data for given object records.

Parameters

Definition at line 415 of file class.ilAdvancedMDValues.php.

References $active_record, $adt_group, $defs, $obj_id, $record_id, $results, $sub_id, ilAdvancedMDRecord\_getSelectedRecordsByObject(), ilObject\_lookupType(), ilAdvancedMDFieldDefinition\getADTGroupForDefinitions(), ilADTFactory\getInstance(), ilAdvancedMDFieldDefinition\getInstancesByRecordId(), and ilADTActiveRecordByType\preloadByPrimary().

Referenced by ilBookingObjectsTableGUI\getItems(), ilBookingReservationsTableGUI\getItems(), and ilGlossaryTerm\getTermList().

416  {
417  $results = array();
418 
419  if (!is_array($a_obj_id))
420  {
421  $a_obj_id = array($a_obj_id);
422  }
423 
424  $sub_obj_ids = array();
425  foreach($a_records as $rec)
426  {
427  $sub_obj_ids[] = $rec[$a_obj_subid_key];
428  }
429 
430  // preload adv data for object id(s)
431  ilADTFactory::getInstance()->initActiveRecordByType();
433  array(
434  "obj_id" => array("integer", $a_obj_id),
435  "sub_type" => array("text", $a_subtype),
436  "sub_id" => array("integer", $sub_obj_ids)
437  ));
438 
439  $record_groups = array();
440 
441  foreach($a_records as $rec)
442  {
443  $obj_id = $rec[$a_obj_id_key];
444  $sub_id = $rec[$a_obj_subid_key];
445 
446  // only active amet records for glossary
448  {
449  $record_id = $adv_record->getRecordId();
450 
451  if(!isset($record_groups[$record_id]))
452  {
455  $record_groups[$record_id] = ilADTFactory::getInstance()->getDBBridgeForInstance($record_groups[$record_id]);
456  $record_groups[$record_id]->setTable("adv_md_values");
457  }
458 
459  // prepare ADT group for record id
460  $record_groups[$record_id]->setPrimary(array(
461  "obj_id" => array("integer", $obj_id),
462  "sub_type" => array("text", $a_subtype),
463  "sub_id" => array("integer", $sub_id)
464  ));
465 
466  // multi-enum fakes single in adv md
467  foreach($record_groups[$record_id]->getElements() as $element)
468  {
469  if($element->getADT()->getType() == "MultiEnum")
470  {
471  $element->setFakeSingle(true);
472  }
473  }
474 
475  // read (preloaded) data
476  $active_record = new ilADTActiveRecordByType($record_groups[$record_id]);
477  $active_record->setElementIdColumn("field_id", "integer");
478  $active_record->read();
479 
480  $adt_group = $record_groups[$record_id]->getADT();
481 
482  // filter against amet values
483  if($a_amet_filter)
484  {
485  foreach($a_amet_filter as $field_id => $element)
486  {
487  if($adt_group->hasElement($field_id))
488  {
489  if(!$element->isInCondition($adt_group->getElement($field_id)))
490  {
491  continue(3);
492  }
493  }
494  }
495  }
496 
497  // add amet values to glossary term record
498  foreach($adt_group->getElements() as $element_id => $element)
499  {
500  if(!$element->isNull())
501  {
502  // we are reusing the ADT group for all $a_records, so we need to clone
503  $pb = ilADTFactory::getInstance()->getPresentationBridgeForInstance(clone $element);
504  $rec["md_".$element_id] = $pb->getSortable();
505  $rec["md_".$element_id."_presentation"] = $pb;
506 
507  }
508  else
509  {
510  $rec["md_".$element_id] = null;
511  }
512  }
513  }
514 
515  $results[] = $rec;
516  }
517 
518  return $results;
519  }
ADT Active Record by type helper class.
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
static getInstance()
Get singleton.
static preloadByPrimary($a_table, array $a_primary)
Read values by (partial) primary key.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
static _getSelectedRecordsByObject($a_obj_type, $a_obj_id, $a_sub_type="")
Get selected records by object.
$results
static _lookupType($a_id, $a_reference=false)
lookup object type
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilAdvancedMDValues::read ( )

Get record values.

Definition at line 181 of file class.ilAdvancedMDValues.php.

References $data, and getActiveRecord().

182  {
183  $this->disabled = array();
184 
185  $tmp = $this->getActiveRecord()->read(true);
186  if($tmp)
187  {
188  foreach($tmp as $element_id => $data)
189  {
190  if($data["disabled"])
191  {
192  $this->disabled[] = $element_id;
193  }
194  }
195  }
196  }
$data
getActiveRecord()
Init ADT DB Bridge (aka active record helper class)
+ Here is the call graph for this function:

◆ write()

ilAdvancedMDValues::write ( array  $a_additional_data = null)

Write record values.

Parameters
array$a_additional_data

Definition at line 203 of file class.ilAdvancedMDValues.php.

References getActiveRecord().

204  {
205  $this->getActiveRecord()->write($a_additional_data);
206  }
getActiveRecord()
Init ADT DB Bridge (aka active record helper class)
+ Here is the call graph for this function:

Field Documentation

◆ $active_record

ilAdvancedMDValues::$active_record
protected

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

Referenced by getActiveRecord(), and queryForRecords().

◆ $adt_group

ilAdvancedMDValues::$adt_group
protected

Definition at line 23 of file class.ilAdvancedMDValues.php.

Referenced by getADTGroup(), and queryForRecords().

◆ $defs

ilAdvancedMDValues::$defs
protected

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

Referenced by _appendXMLByObjId(), getDefinitions(), and queryForRecords().

◆ $disabled

ilAdvancedMDValues::$disabled
protected

Definition at line 26 of file class.ilAdvancedMDValues.php.

◆ $obj_id

ilAdvancedMDValues::$obj_id
protected

Definition at line 18 of file class.ilAdvancedMDValues.php.

Referenced by queryForRecords().

◆ $preload_obj_records

ilAdvancedMDValues::$preload_obj_records
staticprotected

Definition at line 28 of file class.ilAdvancedMDValues.php.

◆ $record_id

ilAdvancedMDValues::$record_id
protected

Definition at line 17 of file class.ilAdvancedMDValues.php.

Referenced by preloadedRead(), and queryForRecords().

◆ $sub_id

ilAdvancedMDValues::$sub_id
protected

Definition at line 19 of file class.ilAdvancedMDValues.php.

Referenced by queryForRecords().

◆ $sub_type

ilAdvancedMDValues::$sub_type
protected

Definition at line 20 of file class.ilAdvancedMDValues.php.


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