ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  protected $db;
18 
22  protected $lng;
23 
27  public function __construct($a_glo_ref_id)
28  {
29  global $DIC;
30 
31  $this->db = $DIC->database();
32  $this->lng = $DIC->language();
33  $this->glo_id = ilObject::_lookupObjectId($a_glo_ref_id);
34  $this->glo_ref_id = $a_glo_ref_id;
35  }
36 
37 
41  public function getAllFields()
42  {
43  $fields = array();
44  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
45  $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("glo", $this->glo_ref_id, "term");
46 
47  foreach ($recs as $record_obj) {
48  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
49  foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def) {
50  $fields[$def->getFieldId()] = array(
51  "id" => $def->getFieldId(),
52  "title" => $def->getTitle(),
53  "type" => $def->getType()
54  );
55  }
56  }
57 
58  return $fields;
59  }
60 
67  public function getColumnOrder()
68  {
69  $ilDB = $this->db;
70  $lng = $this->lng;
71 
72  $columns = array();
73 
74  $set = $ilDB->query(
75  "SELECT * FROM glo_advmd_col_order " .
76  " WHERE glo_id = " . $ilDB->quote($this->glo_id, "integer") .
77  " ORDER BY order_nr"
78  );
79  $order = array();
80  while ($rec = $ilDB->fetchAssoc($set)) {
81  $order[$rec["field_id"]] = $rec["order_nr"];
82  }
83  //var_dump($order);
84  // add term at beginning, if not included
85  if (!isset($order[0])) {
86  $columns[] = array("id" => 0,
87  "text" => $lng->txt("cont_term"));
88  }
89 
90  $fields = $this->getAllFields();
91 
92  // add all fields that have been already sorted
93  foreach ($order as $id => $order_nr) {
94  if (isset($fields[$id])) {
95  $columns[] = array("id" => $id,
96  "text" => $fields[$id]["title"]);
97  unset($fields[$id]);
98  } elseif ($id == 0) {
99  $columns[] = array("id" => 0,
100  "text" => $lng->txt("cont_term"));
101  }
102  }
103 
104  // add all fields that have not been sorted
105  foreach ($fields as $f) {
106  $columns[] = array("id" => $f["id"],
107  "text" => $f["title"]);
108  }
109 
110  return $columns;
111  }
112 
119  public function saveColumnOrder($a_cols)
120  {
121  $ilDB = $this->db;
122 
123  $ilDB->manipulate(
124  "DELETE FROM glo_advmd_col_order WHERE " .
125  " glo_id = " . $ilDB->quote($this->glo_id, "integer")
126  );
127 
128  $nr = 10;
129  $set = array();
130  foreach ($a_cols as $c) {
131  //var_dump($c);
132  if (!isset($set[$c["id"]])) {
133  $ilDB->manipulate("INSERT INTO glo_advmd_col_order " .
134  "(glo_id, field_id, order_nr) VALUES (" .
135  $ilDB->quote($this->glo_id, "integer") . "," .
136  $ilDB->quote($c["id"], "integer") . "," .
137  $ilDB->quote($nr+=10, "integer") .
138  ")");
139  $set[$c["id"]] = $c["id"];
140  }
141  }
142  }
143 
150  public static function writeColumnOrder($a_glo_id, $a_field_id, $a_order_nr)
151  {
152  global $DIC;
153 
154  $ilDB = $DIC->database();
155 
156  $ilDB->replace(
157  "glo_advmd_col_order",
158  array("glo_id" => array("integer", $a_glo_id),
159  "field_id" => array("integer", $a_field_id)),
160  array("order_nr" => array("integer", $a_order_nr))
161  );
162  }
163 }
global $DIC
Definition: saml.php:7
static writeColumnOrder($a_glo_id, $a_field_id, $a_order_nr)
Write single column order.
if(!array_key_exists('StateId', $_REQUEST)) $id
static _getSelectedRecordsByObject($a_obj_type, $a_ref_id, $a_sub_type="")
Get selected records by object.
static _lookupObjectId($a_ref_id)
lookup object id
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
Create styles array
The data for the language used.
getAllFields()
Get all advanced metadata fields.
global $ilDB
$def
Definition: croninfo.php:21
if(! $in) $columns
Definition: Utf8Test.php:45