ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGlossaryTermReferences.php
Go to the documentation of this file.
1<?php
2
24{
25 protected int $glo_id;
27 protected array $terms = array();
28 protected ilDBInterface $db;
30
31 public function __construct(int $a_glo_id = 0)
32 {
33 global $DIC;
34
35 $this->db = $DIC->database();
36 $this->event_handler = $DIC->event();
37
38 $this->setGlossaryId($a_glo_id);
39 if ($a_glo_id > 0) {
40 $this->read();
41 }
42 }
43
44 public function setGlossaryId(int $a_val): void
45 {
46 $this->glo_id = $a_val;
47 }
48
49 public function getGlossaryId(): int
50 {
51 return $this->glo_id;
52 }
53
57 public function setTerms(array $a_val): void
58 {
59 $this->terms = $a_val;
60 }
61
65 public function getTerms(): array
66 {
67 return $this->terms;
68 }
69
70 public function addTerm(int $a_term_id): void
71 {
72 if (!in_array($a_term_id, $this->terms)) {
73 $this->terms[] = $a_term_id;
74 }
75 }
76
77 public function deleteTerm(int $a_term_id): void
78 {
79 foreach ($this->terms as $k => $v) {
80 if ($v == $a_term_id) {
81 unset($this->terms[$k]);
82 }
83 }
84
85 // delete flashcard entries
86 $this->event_handler->raise("components/ILIAS/Glossary", "deleteTerm", ["term_id" => $a_term_id]);
87 }
88
89 public function read(): void
90 {
91 $set = $this->db->query("SELECT term_id FROM glo_term_reference " .
92 " WHERE glo_id = " . $this->db->quote($this->getGlossaryId(), "integer"));
93 while ($rec = $this->db->fetchAssoc($set)) {
94 $this->addTerm($rec["term_id"]);
95 }
96 }
97
98 public function update(): void
99 {
100 $this->delete();
101 foreach ($this->getTerms() as $t) {
102 $this->db->replace(
103 "glo_term_reference",
104 array(
105 "glo_id" => array("integer", $this->getGlossaryId()),
106 "term_id" => array("integer", $t),
107 ),
108 array()
109 );
110 }
111 }
112
116 public function delete(): void
117 {
118 $this->db->manipulate(
119 "DELETE FROM glo_term_reference WHERE " .
120 " glo_id = " . $this->db->quote($this->getGlossaryId(), "integer")
121 );
122 }
123
127 public static function deleteReferencesOfTerm(int $a_term_id): void
128 {
129 global $DIC;
130
131 $db = $DIC->database();
133 "DELETE FROM glo_term_reference WHERE " .
134 " term_id = " . $db->quote($a_term_id, "integer")
135 );
136 }
137
138
142 public static function hasReferences(int $a_glossary_id): bool
143 {
144 global $DIC;
145
146 $db = $DIC->database();
147 $set = $db->query(
148 "SELECT * FROM glo_term_reference " .
149 " WHERE glo_id = " . $db->quote($a_glossary_id, "integer")
150 );
151 if ($rec = $db->fetchAssoc($set)) {
152 return true;
153 }
154 return false;
155 }
156
163 public static function isReferenced(
164 array $a_glo_id,
165 int $a_term_id
166 ): bool {
167 global $DIC;
168
169 $db = $DIC->database();
170 $set = $db->query(
171 "SELECT * FROM glo_term_reference " .
172 " WHERE " . $db->in("glo_id", $a_glo_id, false, "integer") .
173 " AND term_id = " . $db->quote($a_term_id, "integer")
174 );
175 if ($db->fetchAssoc($set)) {
176 return true;
177 }
178 return false;
179 }
180
185 public static function lookupReferencesOfTerm(
186 int $a_term_id
187 ): array {
188 global $DIC;
189
190 $db = $DIC->database();
191 $set = $db->query(
192 $q = "SELECT DISTINCT glo_id FROM glo_term_reference " .
193 " WHERE term_id = " . $db->quote($a_term_id, "integer")
194 );
195 $glos = array();
196 while ($rec = $db->fetchAssoc($set)) {
197 $glos[] = $rec["glo_id"];
198 }
199 return $glos;
200 }
201}
Global event handler.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupReferencesOfTerm(int $a_term_id)
static hasReferences(int $a_glossary_id)
Check if a glossary uses references.
static isReferenced(array $a_glo_id, int $a_term_id)
Is a term referenced by a set of glossaries.
static deleteReferencesOfTerm(int $a_term_id)
Delete all references of a term.
Interface ilDBInterface.
quote($value, string $type)
manipulate(string $query)
Run a (write) Query on the database.
query(string $query)
Run a (read-only) Query on the database.
fetchAssoc(ilDBStatement $statement)
in(string $field, array $values, bool $negate=false, string $type="")
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23