ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilGlossaryTermReferences.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
17 protected $glo_id;
18
22 protected $terms = array();
23
27 protected $db;
28
34 function __construct($a_glo_id = 0)
35 {
36 global $DIC;
37
38 $this->db = $DIC->database();
39
40 $this->setGlossaryId($a_glo_id);
41 if ($a_glo_id > 0)
42 {
43 $this->read();
44 }
45 }
46
52 function setGlossaryId($a_val)
53 {
54 $this->glo_id = $a_val;
55 }
56
62 function getGlossaryId()
63 {
64 return $this->glo_id;
65 }
66
72 function setTerms($a_val)
73 {
74 $this->terms = $a_val;
75 }
76
82 function getTerms()
83 {
84 return $this->terms;
85 }
86
92 function addTerm($a_term_id)
93 {
94 if (!in_array($a_term_id, $this->terms))
95 {
96 $this->terms[] = $a_term_id;
97 }
98 }
99
105 function deleteTerm($a_term_id)
106 {
107 foreach ($this->terms as $k => $v)
108 {
109 if ($v == $a_term_id)
110 {
111 unset($this->terms[$k]);
112 }
113 }
114 }
115
116
120 function read()
121 {
122 $set = $this->db->query("SELECT term_id FROM glo_term_reference ".
123 " WHERE glo_id = ".$this->db->quote($this->getGlossaryId(), "integer"));
124 while ($rec = $this->db->fetchAssoc($set))
125 {
126 $this->addTerm($rec["term_id"]);
127 }
128 }
129
133 function update()
134 {
135 $this->delete();
136 foreach ($this->getTerms() as $t)
137 {
138 $this->db->replace("glo_term_reference",
139 array(
140 "glo_id" => array("integer", $this->getGlossaryId()),
141 "term_id" => array("integer", $t),
142 ),
143 array()
144 );
145 }
146 }
147
151 function delete()
152 {
153 $this->db->manipulate("DELETE FROM glo_term_reference WHERE ".
154 " glo_id = ".$this->db->quote($this->getGlossaryId(), "integer")
155 );
156 }
157
163 static function deleteReferencesOfTerm($a_term_id)
164 {
165 global $DIC;
166
167 $db = $DIC->database();
168 $db->manipulate("DELETE FROM glo_term_reference WHERE ".
169 " term_id = ".$db->quote($a_term_id, "integer")
170 );
171 }
172
173
180 static function hasReferences($a_glossary_id)
181 {
182 global $DIC;
183
184 $db = $DIC->database();
185 $set = $db->query("SELECT * FROM glo_term_reference ".
186 " WHERE glo_id = ".$db->quote($a_glossary_id, "integer")
187 );
188 if ($rec = $db->fetchAssoc($set))
189 {
190 return true;
191 }
192 return false;
193 }
194
201 static function isReferenced($a_glo_id, $a_term_id)
202 {
203 global $DIC;
204
205 $db = $DIC->database();
206 if (!is_array($a_glo_id))
207 {
208 $a_glo_id = array($a_glo_id);
209 }
210 $set = $db->query($q = "SELECT * FROM glo_term_reference ".
211 " WHERE ".$db->in("glo_id", $a_glo_id, false, "integer").
212 " AND term_id = ".$db->quote($a_term_id, "integer")
213 );
214 if ($rec = $db->fetchAssoc($set))
215 {
216 return true;
217 }
218 return false;
219 }
220
227 static function lookupReferencesOfTerm($a_term_id)
228 {
229 global $DIC;
230
231 $db = $DIC->database();
232 $set = $db->query($q = "SELECT DISTINCT glo_id FROM glo_term_reference ".
233 " WHERE term_id = ".$db->quote($a_term_id, "integer")
234 );
235 $glos = array();
236 while ($rec = $db->fetchAssoc($set))
237 {
238 $glos[] = $rec["glo_id"];
239 }
240 return $glos;
241 }
242
243
244
245}
246
247?>
An exception for terminatinating execution or to throw for unit testing.
static hasReferences($a_glossary_id)
Check if a glossary uses references.
static lookupReferencesOfTerm($a_term_id)
Lookup references of a term.
static deleteReferencesOfTerm($a_term_id)
Delete all references of a term.
static isReferenced($a_glo_id, $a_term_id)
Is a term referenced by one or multiple glossaries.
global $DIC