ILIAS  release_8 Revision v8.24
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
45 public function getAllFields(): array
46 {
47 $fields = array();
48 $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("glo", $this->glo_ref_id, "term");
49
50 foreach ($recs as $record_obj) {
51 foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def) {
52 $fields[$def->getFieldId()] = array(
53 "id" => $def->getFieldId(),
54 "title" => $def->getTitle(),
55 "type" => $def->getType()
56 );
57 }
58 }
59
60 return $fields;
61 }
62
66 public function getColumnOrder(): array
67 {
70
71 $columns = array();
72
73 $set = $ilDB->query(
74 "SELECT * FROM glo_advmd_col_order " .
75 " WHERE glo_id = " . $ilDB->quote($this->glo_id, "integer") .
76 " ORDER BY order_nr"
77 );
78 $order = array();
79 while ($rec = $ilDB->fetchAssoc($set)) {
80 $order[$rec["field_id"]] = $rec["order_nr"];
81 }
82 //var_dump($order);
83 // add term at beginning, if not included
84 if (!isset($order[0])) {
85 $columns[] = array("id" => 0,
86 "text" => $lng->txt("cont_term"));
87 }
88
89 $fields = $this->getAllFields();
90
91 // add all fields that have been already sorted
92 foreach ($order as $id => $order_nr) {
93 if (isset($fields[$id])) {
94 $columns[] = array("id" => $id,
95 "text" => $fields[$id]["title"]);
96 unset($fields[$id]);
97 } elseif ($id == 0) {
98 $columns[] = array("id" => 0,
99 "text" => $lng->txt("cont_term"));
100 }
101 }
102
103 // add all fields that have not been sorted
104 foreach ($fields as $f) {
105 $columns[] = array("id" => $f["id"],
106 "text" => $f["title"]);
107 }
108
109 return $columns;
110 }
111
115 public function saveColumnOrder(array $a_cols): void
116 {
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
143 public static function writeColumnOrder(
144 int $a_glo_id,
145 int $a_field_id,
146 int $a_order_nr
147 ): void {
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}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveColumnOrder(array $a_cols)
Save column order.
static writeColumnOrder(int $a_glo_id, int $a_field_id, int $a_order_nr)
Write single column order.
getAllFields()
Get all advanced metadata fields.
language handling
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 _lookupObjectId(int $ref_id)
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
Interface ilDBInterface.