ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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)
 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 360 of file class.ilAdvancedMDValues.php.

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

Referenced by ilCourseXMLWriter\__buildAdvancedMetaData().

361  {
362  $a_xml_writer->xmlStartTag('AdvancedMetaData');
363 
364  self::preloadByObjIds(array($a_obj_id));
365  $values_records = self::preloadedRead(ilObject::_lookupType($a_obj_id), $a_obj_id);
366 
367  foreach($values_records as $values_record)
368  {
369  $defs = $values_record->getDefinitions();
370  foreach($values_record->getADTGroup()->getElements() as $element_id => $element)
371  {
372  $def = $defs[$element_id];
373 
374  $value = null;
375  if(!$element->isNull())
376  {
377  $value = $def->getValueForXML($element);
378  }
379 
380  $a_xml_writer->xmlElement(
381  'Value',
382  array('id' => $def->getImportId()),
383  $value
384  );
385  }
386  }
387 
388  $a_xml_writer->xmlEndTag('AdvancedMetaData');
389  }
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 312 of file class.ilAdvancedMDValues.php.

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

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

313  {
314  global $ilLog;
315 
316  $source_primary = array("obj_id"=>array("integer", $a_source_id));
317  $target_primary = array("obj_id"=>array("integer", $a_target_id));
318 
319  // sub-type support
320  if($a_sub_type &&
321  $a_source_sub_id &&
322  $a_target_sub_id)
323  {
324  $source_primary["sub_type"] = array("text", $a_sub_type);
325  $source_primary["sub_id"] = array("integer", $a_source_sub_id);
326  $target_primary["sub_type"] = array("text", $a_sub_type);
327  $target_primary["sub_id"] = array("integer", $a_target_sub_id);
328  }
329 
330  ilADTFactory::getInstance()->initActiveRecordByType();
332  "adv_md_values",
333  array(
334  "obj_id" => "integer",
335  "sub_type" => "text",
336  "sub_id" => "integer",
337  "field_id" => "integer"
338  ),
339  $source_primary,
340  $target_primary,
341  array("disabled"=>"integer"));
342 
343  if(!$has_cloned)
344  {
345  $ilLog->write(__METHOD__.': No advanced meta data found.');
346  }
347  else
348  {
349  $ilLog->write(__METHOD__.': Start cloning advanced meta data.');
350  }
351  return true;
352  }
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 222 of file class.ilAdvancedMDValues.php.

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

Referenced by ilAdvancedMDFieldDefinition\delete().

223  {
224  ilADTFactory::getInstance()->initActiveRecordByType();
226  "adv_md_values",
227  array("field_id"=>array("integer", $a_field_id)),
228  $a_adt->getType());
229  }
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 236 of file class.ilAdvancedMDValues.php.

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

Referenced by ilObject\delete().

237  {
238  ilADTFactory::getInstance()->initActiveRecordByType();
240  "adv_md_values",
241  array("obj_id"=>array("integer", $a_obj_id)));
242  }
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 152 of file class.ilAdvancedMDValues.php.

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

Referenced by ilAdvancedMetaDataExporter\getXmlRepresentation().

153  {
154  include_once "Services/ADT/classes/class.ilADTFactory.php";
156  return ilADTActiveRecordByType::readByPrimary("adv_md_values", array("obj_id"=>array("integer", $a_obj_id)));
157  }
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 113 of file class.ilAdvancedMDValues.php.

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

Referenced by read(), and write().

114  {
115  if(!$this->active_record instanceof ilADTActiveRecordByType)
116  {
117  include_once "Services/ADT/classes/class.ilADTFactory.php";
118  $factory = ilADTFactory::getInstance();
119 
120  $adt_group_db = $factory->getDBBridgeForInstance($this->getADTGroup());
121 
122  $primary = array(
123  "obj_id" => array("integer", $this->obj_id),
124  "sub_type" => array("text", $this->sub_type),
125  "sub_id" => array("integer", $this->sub_id)
126  );
127  $adt_group_db->setPrimary($primary);
128  $adt_group_db->setTable("adv_md_values");
129 
130  // multi-enum fakes single in adv md
131  foreach($adt_group_db->getElements() as $element)
132  {
133  if($element->getADT()->getType() == "MultiEnum")
134  {
135  $element->setFakeSingle(true);
136  }
137  }
138 
139  $this->active_record = $factory->getActiveRecordByTypeInstance($adt_group_db);
140  $this->active_record->setElementIdColumn("field_id", "integer");
141  }
142 
143  return $this->active_record;
144  }
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 99 of file class.ilAdvancedMDValues.php.

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

Referenced by getActiveRecord().

100  {
101  if(!$this->adt_group instanceof ilADTGroup)
102  {
104  }
105  return $this->adt_group;
106  }
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 85 of file class.ilAdvancedMDValues.php.

References $defs, and ilAdvancedMDFieldDefinition\getInstancesByRecordId().

Referenced by getADTGroup().

86  {
87  if(!is_array($this->defs))
88  {
89  $this->defs = ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->record_id);
90  }
91  return $this->defs;
92  }
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 
)
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 $ilDB, $query, $res, $row, and ilObject\_lookupType().

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

55  {
56  global $ilDB;
57 
58  $res = array();
59 
60  if(!$a_obj_type)
61  {
62  $a_obj_type = ilObject::_lookupType($a_obj_id);
63  }
64 
65  // get active records for object type
66  $query = "SELECT amro.record_id".
67  " FROM adv_md_record_objs amro".
68  " JOIN adv_md_record amr ON (amr.record_id = amro.record_id)".
69  " WHERE active = ".$ilDB->quote(1, "integer").
70  " AND obj_type = ".$ilDB->quote($a_obj_type, "text");
71  $set = $ilDB->query($query);
72  while($row = $ilDB->fetchAssoc($set))
73  {
74  $res[$row["record_id"]] = new self($row["record_id"], $a_obj_id);
75  }
76 
77  return $res;
78  }
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilDB
+ 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 172 of file class.ilAdvancedMDValues.php.

173  {
174  if(is_array($this->disabled))
175  {
176  return in_array($a_element_id, $this->disabled);
177  }
178  }

◆ preloadByObjIds()

static ilAdvancedMDValues::preloadByObjIds ( array  $a_obj_ids)
static

Preload list gui data.

Parameters
array$a_obj_ids

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

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

Referenced by ilObjectListGUIPreloader\preload().

256  {
257  global $ilDB;
258 
259  // preload values
260  ilADTFactory::getInstance()->initActiveRecordByType();
262  "adv_md_values",
263  array("obj_id"=>array("integer", $a_obj_ids)));
264 
265 
266  // preload record ids for object types
267 
268  self::$preload_obj_records = array();
269 
270  // get active records for object types
271  $query = "SELECT amro.*".
272  " FROM adv_md_record_objs amro".
273  " JOIN adv_md_record amr ON (amr.record_id = amro.record_id)".
274  " WHERE active = ".$ilDB->quote(1, "integer");
275  $set = $ilDB->query($query);
276  while($row = $ilDB->fetchAssoc($set))
277  {
278  self::$preload_obj_records[$row["obj_type"]][] = $row["record_id"];
279  }
280  }
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 282 of file class.ilAdvancedMDValues.php.

References $record_id, and $res.

Referenced by ilAdvancedMDSubstitution\getParsedSubstitutions().

283  {
284  $res = array();
285 
286  if(isset(self::$preload_obj_records[$a_type]))
287  {
288  foreach(self::$preload_obj_records[$a_type] as $record_id)
289  {
290  $res[$record_id] = new self($record_id, $a_obj_id);
291  $res[$record_id]->read();
292  }
293  }
294 
295  return $res;
296  }
+ 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 402 of file class.ilAdvancedMDValues.php.

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

Referenced by ilGlossaryTerm\getTermList().

403  {
404  $result = array();
405 
406  if (!is_array($a_obj_id))
407  {
408  $a_obj_id = array($a_obj_id);
409  }
410 
411  $sub_obj_ids = array();
412  foreach($a_records as $rec)
413  {
414  $sub_obj_ids[] = $rec[$a_obj_subid_key];
415  }
416 
417  // preload adv data for object id(s)
418  ilADTFactory::getInstance()->initActiveRecordByType();
420  array(
421  "obj_id" => array("integer", $a_obj_id),
422  "sub_type" => array("text", $a_subtype),
423  "sub_id" => array("integer", $sub_obj_ids)
424  ));
425 
426  $record_groups = array();
427 
428  foreach($a_records as $rec)
429  {
430  $obj_id = $rec[$a_obj_id_key];
431  $sub_id = $rec[$a_obj_subid_key];
432 
433  // only active amet records for glossary
435  {
436  $record_id = $adv_record->getRecordId();
437 
438  if(!isset($record_groups[$record_id]))
439  {
442  $record_groups[$record_id] = ilADTFactory::getInstance()->getDBBridgeForInstance($record_groups[$record_id]);
443  $record_groups[$record_id]->setTable("adv_md_values");
444  }
445 
446  // prepare ADT group for record id
447  $record_groups[$record_id]->setPrimary(array(
448  "obj_id" => array("integer", $obj_id),
449  "sub_type" => array("text", $a_subtype),
450  "sub_id" => array("integer", $sub_id)
451  ));
452 
453  // multi-enum fakes single in adv md
454  foreach($record_groups[$record_id]->getElements() as $element)
455  {
456  if($element->getADT()->getType() == "MultiEnum")
457  {
458  $element->setFakeSingle(true);
459  }
460  }
461 
462  // read (preloaded) data
463  $active_record = new ilADTActiveRecordByType($record_groups[$record_id]);
464  $active_record->setElementIdColumn("field_id", "integer");
465  $active_record->read();
466 
467  $adt_group = $record_groups[$record_id]->getADT();
468 
469  // filter against amet values
470  if($a_amet_filter)
471  {
472  foreach($a_amet_filter as $field_id => $element)
473  {
474  if($adt_group->hasElement($field_id))
475  {
476  if(!$element->isInCondition($adt_group->getElement($field_id)))
477  {
478  continue(3);
479  }
480  }
481  }
482  }
483 
484  // add amet values to glossary term record
485  foreach($adt_group->getElements() as $element_id => $element)
486  {
487  if(!$element->isNull())
488  {
489  // we are reusing the ADT group for all $a_records, so we need to clone
490  $pb = ilADTFactory::getInstance()->getPresentationBridgeForInstance(clone $element);
491  $rec["md_".$element_id] = $pb->getSortable();
492  $rec["md_".$element_id."_presentation"] = $pb;
493 
494  }
495  else
496  {
497  $rec["md_".$element_id] = null;
498  }
499  }
500  }
501 
502  $results[] = $rec;
503  }
504 
505  return $results;
506  }
ADT Active Record by type helper class.
$result
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 188 of file class.ilAdvancedMDValues.php.

References $data, and getActiveRecord().

Referenced by ilWikiAdvMetaDataBlockGUI\fillDataSection(), and ilObjOrgUnitGUI\parseInfoScreen().

189  {
190  $this->disabled = array();
191 
192  $tmp = $this->getActiveRecord()->read(true);
193  if($tmp)
194  {
195  foreach($tmp as $element_id => $data)
196  {
197  if($data["disabled"])
198  {
199  $this->disabled[] = $element_id;
200  }
201  }
202  }
203  }
getActiveRecord()
Init ADT DB Bridge (aka active record helper class)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write()

ilAdvancedMDValues::write ( array  $a_additional_data = null)

Write record values.

Parameters
array$a_additional_data

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

References getActiveRecord().

211  {
212  $this->getActiveRecord()->write($a_additional_data);
213  }
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: