ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
class.ilGlossaryAdvMetaDataAdapter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
17  function __construct($a_glo_id)
18  {
19  $this->glo_id = $a_glo_id;
20  }
21 
22 
26  function getAllFields()
27  {
28  $fields = array();
29  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
30  $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("glo", $this->glo_id, "term");
31 
32  foreach($recs as $record_obj)
33  {
34  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
35  foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def)
36  {
37  $fields[$def->getFieldId()] = array(
38  "id" => $def->getFieldId(),
39  "title" => $def->getTitle(),
40  "type" => $def->getType()
41  );
42  }
43  }
44 
45  return $fields;
46  }
47 
54  function getColumnOrder()
55  {
56  global $ilDB, $lng;
57 
58  $columns = array();
59 
60  $set = $ilDB->query("SELECT * FROM glo_advmd_col_order ".
61  " WHERE glo_id = ".$ilDB->quote($this->glo_id, "integer").
62  " ORDER BY order_nr"
63  );
64  $order = array();
65  while ($rec = $ilDB->fetchAssoc($set))
66  {
67  $order[$rec["field_id"]] = $rec["order_nr"];
68  }
69 //var_dump($order);
70  // add term at beginning, if not included
71  if (!isset($order[0]))
72  {
73  $columns[] = array("id" => 0,
74  "text" => $lng->txt("cont_term"));
75  }
76 
77  $fields = $this->getAllFields();
78 
79  // add all fields that have been already sorted
80  foreach ($order as $id => $order_nr)
81  {
82  if (isset($fields[$id]))
83  {
84  $columns[] = array("id" => $id,
85  "text" => $fields[$id]["title"]);
86  unset($fields[$id]);
87  }
88  else if ($id == 0)
89  {
90  $columns[] = array("id" => 0,
91  "text" => $lng->txt("cont_term"));
92  }
93  }
94 
95  // add all fields that have not been sorted
96  foreach ($fields as $f)
97  {
98  $columns[] = array("id" => $f["id"],
99  "text" => $f["title"]);
100  }
101 
102  return $columns;
103  }
104 
111  function saveColumnOrder($a_cols)
112  {
113  global $ilDB;
114 
115  $ilDB->manipulate("DELETE FROM glo_advmd_col_order WHERE ".
116  " glo_id = ".$ilDB->quote($this->glo_id, "integer")
117  );
118 
119  $nr = 10;
120  $set = array();
121  foreach ($a_cols as $c)
122  {
123 //var_dump($c);
124  if (!isset($set[$c["id"]]))
125  {
126  $ilDB->manipulate("INSERT INTO glo_advmd_col_order ".
127  "(glo_id, field_id, order_nr) VALUES (".
128  $ilDB->quote($this->glo_id, "integer").",".
129  $ilDB->quote($c["id"], "integer").",".
130  $ilDB->quote($nr+=10, "integer").
131  ")");
132  $set[$c["id"]] = $c["id"];
133  }
134  }
135  }
136 
143  static function writeColumnOrder($a_glo_id, $a_field_id, $a_order_nr)
144  {
145  global $ilDB;
146 
147  $ilDB->replace("glo_advmd_col_order",
148  array("glo_id" => array("integer", $a_glo_id),
149  "field_id" => array("integer", $a_field_id)),
150  array("order_nr" => array("integer", $a_order_nr))
151  );
152  }
153 }
154 
155 ?>
static writeColumnOrder($a_glo_id, $a_field_id, $a_order_nr)
Write single column order.
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.
getAllFields()
Get all advanced metadata fields.
global $lng
Definition: privfeed.php:40
global $ilDB
if(! $in) $columns
Definition: Utf8Test.php:46