ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
ilAdvancedMDValues Class Reference
+ Collaboration diagram for ilAdvancedMDValues:

Static Public Member Functions

static _getValuesByObjId ($a_obj_id)
 Get all values of an object. More...
 
static _cloneValues ($a_source_id, $a_target_id)
 Clone Advanced Meta Data. More...
 
static _appendXMLByObjId (ilXmlWriter $xml_writer, $a_obj_id)
 Get xml of object values. More...
 
static _preloadValuesByObjIds ($obj_ids)
 preload object values More...
 
static _deleteByFieldId ($a_field_id)
 Delete values by field_id. More...
 
static _deleteByObjId ($a_obj_id)
 Delete by objekt id. More...
 
static _getValuesByObjIdAndSubtype ($a_obj_id, $a_subtype)
 Get all values of an object per subtype Uses internal cache. More...
 
static queryForRecords ($a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key, $a_amet_filter="")
 Query data for given object records. More...
 

Static Private Attributes

static $cached_values = array()
 

Detailed Description

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

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

Member Function Documentation

◆ _appendXMLByObjId()

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

Get xml of object values.

public

Parameters
objectinstance of ilXmlWriter
int$a_obj_id

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

References $query, $res, $row, ilAdvancedMDValue\_getInstance(), ilObject\_lookupType(), DB_FETCHMODE_OBJECT, ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by ilCourseXMLWriter\__buildAdvancedMetaData().

95  {
96  global $ilDB;
97 
98  $type = ilObject::_lookupType($a_obj_id);
99 
100  // Get active field_definitions
101  $query = "SELECT field_id FROM adv_md_record amr ".
102  "JOIN adv_md_record_objs amro ON amr.record_id = amro.record_id ".
103  "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id ".
104  "WHERE active = 1 ".
105  "AND obj_type = ".$ilDB->quote($type ,'text')." ";
106 
107  $xml_writer->xmlStartTag('AdvancedMetaData');
108 
109  $res = $ilDB->query($query);
110  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
111  {
112  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
113  $value = ilAdvancedMDValue::_getInstance($a_obj_id,$row->field_id);
114  $value->appendXML($xml_writer);
115  }
116  $xml_writer->xmlEndTag('AdvancedMetaData');
117  }
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlEndTag($tag)
Writes an endtag.
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getInstance($a_obj_id, $a_field_id, $a_sub_type="", $a_sub_id=0)
Get instance.
+ 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 
)
static

Clone Advanced Meta Data.

public

Parameters
intsource obj_id
inttarget obj_id

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

References $ilLog, ilAdvancedMDFieldDefinition\_getActiveDefinitionsByObjType(), and ilObject\_lookupType().

Referenced by ilObject\cloneObject().

57  {
58  global $ilLog;
59 
60  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
61  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
62 
63 
65  {
66  $ilLog->write(__METHOD__.': No advanced meta data found.');
67  return true;
68  }
69 
70  $ilLog->write(__METHOD__.': Start cloning advanced meta data.');
71 
72  foreach(self::_getValuesByObjId($a_source_id) as $field_id => $value)
73  {
74  if(!in_array($field_id,$defs))
75  {
76  continue;
77  }
78  $new_value = new ilAdvancedMDValue($field_id,$a_target_id);
79  $new_value->setValue($value);
80  $new_value->save();
81 
82  }
83  return true;
84  }
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getActiveDefinitionsByObjType($a_type)
get active definitions by obj type
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _deleteByFieldId()

static ilAdvancedMDValues::_deleteByFieldId (   $a_field_id)
static

Delete values by field_id.

Typically called after deleting a field

public

Parameters
intfield id

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

References $query, and $res.

Referenced by ilAdvancedMDFieldDefinition\_deleteByRecordId(), and ilAdvancedMDFieldDefinition\delete().

152  {
153  global $ilDB;
154 
155  $query = "DELETE FROM adv_md_values ".
156  "WHERE field_id = ".$ilDB->quote($a_field_id ,'integer')." ";
157  $res = $ilDB->manipulate($query);
158  }
+ Here is the caller graph for this function:

◆ _deleteByObjId()

static ilAdvancedMDValues::_deleteByObjId (   $a_obj_id)
static

Delete by objekt id.

public

Parameters
intobj_id

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

References $query, and $res.

169  {
170  global $ilDB;
171 
172  $query = "DELETE FROM adv_md_values ".
173  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
174  $res = $ilDB->manipulate($query);
175  }

◆ _getValuesByObjId()

static ilAdvancedMDValues::_getValuesByObjId (   $a_obj_id)
static

Get all values of an object.

Uses internal cache.

public

Parameters
intobj_id

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

References $query, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by ilECSObjectSettings\addMetadataToJson(), ilECSSettingsGUI\exportImported(), ilECSSettingsGUI\exportReleased(), ilECSReleasedContentTableGUI\fillRow(), ilECSImportedContentTableGUI\fillRow(), and ilAdvancedMDSubstitution\getParsedSubstitutions().

28  {
29  global $ilDB;
30 
31  if(isset(self::$cached_values[$a_obj_id]))
32  {
33  return self::$cached_values[$a_obj_id];
34  }
35  $query = "SELECT field_id,value FROM adv_md_values ".
36  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
37  $res = $ilDB->query($query);
38 
39  self::$cached_values[$a_obj_id] = array();
40  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
41  {
42  self::$cached_values[$a_obj_id][$row->field_id] = $row->value;
43  }
44  return self::$cached_values[$a_obj_id];
45  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
+ Here is the caller graph for this function:

◆ _getValuesByObjIdAndSubtype()

static ilAdvancedMDValues::_getValuesByObjIdAndSubtype (   $a_obj_id,
  $a_subtype 
)
static

Get all values of an object per subtype Uses internal cache.

public

Parameters
intobj_id

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

References $result.

187  {
188  global $ilDB;
189 
190  $result = array();
191  $set = $ilDB->query($q = "SELECT field_id, value, sub_type, sub_id FROM adv_md_values ".
192  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
193  "AND sub_type = ".$ilDB->quote($a_subtype,'text')
194  );
195  while ($rec = $ilDB->fetchAssoc($set))
196  {
197  $result[] = $rec;
198  }
199 
200  return $result;
201  }
$result

◆ _preloadValuesByObjIds()

static ilAdvancedMDValues::_preloadValuesByObjIds (   $obj_ids)
static

preload object values

public

Parameters
arrayobj_ids

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

References $query, $res, $row, and DB_FETCHMODE_OBJECT.

128  {
129  global $ilDB;
130 
131  $query = "SELECT obj_id,field_id,value FROM adv_md_values ".
132  "WHERE ".$ilDB->in('obj_id',$obj_ids,false,'integer');
133 
134  $res = $ilDB->query($query);
135  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
136  {
137  self::$cached_values[$row->obj_id][$row->field_id] = $row->value;
138  }
139  return true;
140  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11

◆ queryForRecords()

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

Query data for given object records.

Parameters

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

References $result, $results, ilAdvancedMDFieldDefinition\_lookupFieldType(), IL_CAL_DATE, IL_CAL_UNIX, ilAdvancedMDFieldDefinition\TYPE_DATE, and ilAdvancedMDFieldDefinition\TYPE_DATETIME.

Referenced by ilGlossaryTerm\getTermList().

210  {
211  $result = $val = array();
212  if (!is_array($a_obj_id))
213  {
214  $a_obj_id = array($a_obj_id);
215  }
216 
217  // read amet data
218  foreach ($a_obj_id as $obj_id)
219  {
220  $values = self::_getValuesByObjIdAndSubtype($obj_id, $a_subtype);
221  foreach ($values as $v)
222  {
223  $val[$obj_id][$v["sub_id"]][$v["field_id"]] = $v;
224  }
225  }
226 //var_dump($a_amet_filter);
227  // add amet data to records
228  foreach ($a_records as $rec)
229  {
230  // check filter
231  $skip = false;
232  if (is_array($a_amet_filter))
233  {
234  foreach ($a_amet_filter as $fk => $fv)
235  {
236  if (!$skip && substr($fk, 0, 3) == "md_")
237  {
238  $fka = explode("_", $fk);
239  $fka = $fka[1];
240 
241  if (is_array($fv))
242  {
244 
245  // #12511 - currently supports only date/datetime
246  if (($advmd_type == ilAdvancedMDFieldDefinition::TYPE_DATE ||
248  array_key_exists("from", $fv) &&
249  array_key_exists("to", $fv) &&
250  ($fv["from"] !== null || $fv["to"] !== null))
251  {
252  if (!isset($val[$rec[$a_obj_id_key]][$rec[$a_obj_subid_key]][$fka]["value"]))
253  {
254  $skip = true;
255  }
256  else
257  {
258  $from = $fv["from"];
259  $to = $fv["to"];
260  $md_val = $val[$rec[$a_obj_id_key]][$rec[$a_obj_subid_key]][$fka]["value"];
261 
263  {
264  $from = $from ? $from->get(IL_CAL_UNIX) : null;
265  $to = $to ? $to->get(IL_CAL_UNIX) : null;
266  }
267  else
268  {
269  $from = $from ? $from->get(IL_CAL_DATE) : null;
270  $to = $to ? $to->get(IL_CAL_DATE) : null;
271  $md_val = date("Y-m-d", $md_val);
272  }
273 
274  if($from && $to)
275  {
276  if($md_val < $from || $md_val > $to)
277  {
278  $skip = true;
279  }
280  }
281  else if($from)
282  {
283  if($md_val < $from)
284  {
285  $skip = true;
286  }
287  }
288  else
289  {
290  if($md_val > $to)
291  {
292  $skip = true;
293  }
294  }
295  }
296  }
297  }
298  else if($fv != "")
299  {
300  if (!isset($val[$rec[$a_obj_id_key]][$rec[$a_obj_subid_key]][$fka]["value"]))
301  {
302  $skip = true;
303  }
304  else
305  {
306  $md_val = $val[$rec[$a_obj_id_key]][$rec[$a_obj_subid_key]][$fka]["value"];
307  if (trim($md_val) != trim($fv))
308  {
309  $skip = true;
310  }
311  }
312  }
313  }
314  }
315  }
316  if ($skip)
317  {
318  continue;
319  }
320 
321 
322  if (is_array($val[$rec[$a_obj_id_key]][$rec[$a_obj_subid_key]]))
323  {
324  foreach ($val[$rec[$a_obj_id_key]][$rec[$a_obj_subid_key]] as $k => $v)
325  {
326  $rec["md_".$k] = $v["value"];
327  }
328  }
329  $results[] = $rec;
330  }
331 
332  return $results;
333  }
$result
const IL_CAL_UNIX
$results
static _lookupFieldType($a_field_id)
Lookup field type.
const IL_CAL_DATE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $cached_values

ilAdvancedMDValues::$cached_values = array()
staticprivate

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


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