ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilGlossaryAdvMetaDataAdapter.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  protected int $glo_ref_id;
26  protected int $glo_id;
27  protected ilDBInterface $db;
28  protected ilLanguage $lng;
29 
30  public function __construct(
31  int $a_glo_ref_id
32  ) {
33  global $DIC;
34 
35  $this->db = $DIC->database();
36  $this->lng = $DIC->language();
37  $this->glo_id = ilObject::_lookupObjectId($a_glo_ref_id);
38  $this->glo_ref_id = $a_glo_ref_id;
39  }
40 
41  public function getActiveRecords(): array
42  {
43  return ilAdvancedMDRecord::_getSelectedRecordsByObject("glo", $this->glo_ref_id, "term");
44  }
45 
49  public function getAllFields(): array
50  {
51  $fields = array();
52  $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("glo", $this->glo_ref_id, "term");
53 
54  foreach ($recs as $record_obj) {
55  foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def) {
56  $fields[$def->getFieldId()] = array(
57  "id" => $def->getFieldId(),
58  "title" => $def->getTitle(),
59  "type" => $def->getType()
60  );
61  }
62  }
63 
64  return $fields;
65  }
66 
70  public function getColumnOrder(): array
71  {
72  $ilDB = $this->db;
73  $lng = $this->lng;
74 
75  $columns = array();
76 
77  $set = $ilDB->query(
78  "SELECT * FROM glo_advmd_col_order " .
79  " WHERE glo_id = " . $ilDB->quote($this->glo_id, "integer") .
80  " ORDER BY order_nr"
81  );
82  $order = array();
83  while ($rec = $ilDB->fetchAssoc($set)) {
84  $order[$rec["field_id"]] = $rec["order_nr"];
85  }
86  // add term at beginning, if not included
87  if (!isset($order[0])) {
88  $columns[] = array("id" => 0,
89  "text" => $lng->txt("cont_term"));
90  }
91 
92  $fields = $this->getAllFields();
93 
94  // add all fields that have been already sorted
95  foreach ($order as $id => $order_nr) {
96  if (isset($fields[$id])) {
97  $columns[] = array("id" => $id,
98  "text" => $fields[$id]["title"]);
99  unset($fields[$id]);
100  } elseif ($id == 0) {
101  $columns[] = array("id" => 0,
102  "text" => $lng->txt("cont_term"));
103  }
104  }
105 
106  // add all fields that have not been sorted
107  foreach ($fields as $f) {
108  $columns[] = array("id" => $f["id"],
109  "text" => $f["title"]);
110  }
111 
112  return $columns;
113  }
114 
120  public function saveColumnOrder(array $a_cols): void
121  {
122  $ilDB = $this->db;
123 
124  $ilDB->manipulate(
125  "DELETE FROM glo_advmd_col_order WHERE " .
126  " glo_id = " . $ilDB->quote($this->glo_id, "integer")
127  );
128 
129  $nr = 10;
130  $set = array();
131  foreach ($a_cols as $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 
147  public static function writeColumnOrder(
148  int $a_glo_id,
149  int $a_field_id,
150  int $a_order_nr
151  ): void {
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 }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static writeColumnOrder(int $a_glo_id, int $a_field_id, int $a_order_nr)
Write single column order.
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
$c
Definition: deliver.php:25
global $DIC
Definition: shib_login.php:26
static _lookupObjectId(int $ref_id)
getAllFields()
Get all advanced metadata fields.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
saveColumnOrder(array $a_cols)
Save column order.