ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 
118  public function saveColumnOrder(array $a_cols): void
119  {
120  $ilDB = $this->db;
121 
122  $ilDB->manipulate(
123  "DELETE FROM glo_advmd_col_order WHERE " .
124  " glo_id = " . $ilDB->quote($this->glo_id, "integer")
125  );
126 
127  $nr = 10;
128  $set = array();
129  foreach ($a_cols as $c) {
130  if (!isset($set[$c["id"]])) {
131  $ilDB->manipulate("INSERT INTO glo_advmd_col_order " .
132  "(glo_id, field_id, order_nr) VALUES (" .
133  $ilDB->quote($this->glo_id, "integer") . "," .
134  $ilDB->quote($c["id"], "integer") . "," .
135  $ilDB->quote($nr += 10, "integer") .
136  ")");
137  $set[$c["id"]] = $c["id"];
138  }
139  }
140  }
141 
145  public static function writeColumnOrder(
146  int $a_glo_id,
147  int $a_field_id,
148  int $a_order_nr
149  ): void {
150  global $DIC;
151 
152  $ilDB = $DIC->database();
153 
154  $ilDB->replace(
155  "glo_advmd_col_order",
156  array("glo_id" => array("integer", $a_glo_id),
157  "field_id" => array("integer", $a_field_id)),
158  array("order_nr" => array("integer", $a_order_nr))
159  );
160  }
161 }
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.
global $DIC
Definition: feed.php:28
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.