ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilGlossaryAdvMetaDataAdapter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
11 {
15  protected $db;
16 
20  protected $lng;
21 
25  public function __construct($a_glo_ref_id)
26  {
27  global $DIC;
28 
29  $this->db = $DIC->database();
30  $this->lng = $DIC->language();
31  $this->glo_id = ilObject::_lookupObjectId($a_glo_ref_id);
32  $this->glo_ref_id = $a_glo_ref_id;
33  }
34 
35 
39  public function getAllFields()
40  {
41  $fields = array();
42  $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("glo", $this->glo_ref_id, "term");
43 
44  foreach ($recs as $record_obj) {
45  foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def) {
46  $fields[$def->getFieldId()] = array(
47  "id" => $def->getFieldId(),
48  "title" => $def->getTitle(),
49  "type" => $def->getType()
50  );
51  }
52  }
53 
54  return $fields;
55  }
56 
63  public function getColumnOrder()
64  {
65  $ilDB = $this->db;
66  $lng = $this->lng;
67 
68  $columns = array();
69 
70  $set = $ilDB->query(
71  "SELECT * FROM glo_advmd_col_order " .
72  " WHERE glo_id = " . $ilDB->quote($this->glo_id, "integer") .
73  " ORDER BY order_nr"
74  );
75  $order = array();
76  while ($rec = $ilDB->fetchAssoc($set)) {
77  $order[$rec["field_id"]] = $rec["order_nr"];
78  }
79  //var_dump($order);
80  // add term at beginning, if not included
81  if (!isset($order[0])) {
82  $columns[] = array("id" => 0,
83  "text" => $lng->txt("cont_term"));
84  }
85 
86  $fields = $this->getAllFields();
87 
88  // add all fields that have been already sorted
89  foreach ($order as $id => $order_nr) {
90  if (isset($fields[$id])) {
91  $columns[] = array("id" => $id,
92  "text" => $fields[$id]["title"]);
93  unset($fields[$id]);
94  } elseif ($id == 0) {
95  $columns[] = array("id" => 0,
96  "text" => $lng->txt("cont_term"));
97  }
98  }
99 
100  // add all fields that have not been sorted
101  foreach ($fields as $f) {
102  $columns[] = array("id" => $f["id"],
103  "text" => $f["title"]);
104  }
105 
106  return $columns;
107  }
108 
115  public function saveColumnOrder($a_cols)
116  {
117  $ilDB = $this->db;
118 
119  $ilDB->manipulate(
120  "DELETE FROM glo_advmd_col_order WHERE " .
121  " glo_id = " . $ilDB->quote($this->glo_id, "integer")
122  );
123 
124  $nr = 10;
125  $set = array();
126  foreach ($a_cols as $c) {
127  //var_dump($c);
128  if (!isset($set[$c["id"]])) {
129  $ilDB->manipulate("INSERT INTO glo_advmd_col_order " .
130  "(glo_id, field_id, order_nr) VALUES (" .
131  $ilDB->quote($this->glo_id, "integer") . "," .
132  $ilDB->quote($c["id"], "integer") . "," .
133  $ilDB->quote($nr += 10, "integer") .
134  ")");
135  $set[$c["id"]] = $c["id"];
136  }
137  }
138  }
139 
146  public static function writeColumnOrder($a_glo_id, $a_field_id, $a_order_nr)
147  {
148  global $DIC;
149 
150  $ilDB = $DIC->database();
151 
152  $ilDB->replace(
153  "glo_advmd_col_order",
154  array("glo_id" => array("integer", $a_glo_id),
155  "field_id" => array("integer", $a_field_id)),
156  array("order_nr" => array("integer", $a_order_nr))
157  );
158  }
159 }
static writeColumnOrder($a_glo_id, $a_field_id, $a_order_nr)
Write single column order.
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.
getAllFields()
Get all advanced metadata fields.
global $ilDB
$DIC
Definition: xapitoken.php:46
if(! $in) $columns
Definition: Utf8Test.php:45