ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public 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  $this->read();
43  }
44  }
45 
51  public function setGlossaryId($a_val)
52  {
53  $this->glo_id = $a_val;
54  }
55 
61  public function getGlossaryId()
62  {
63  return $this->glo_id;
64  }
65 
71  public function setTerms($a_val)
72  {
73  $this->terms = $a_val;
74  }
75 
81  public function getTerms()
82  {
83  return $this->terms;
84  }
85 
91  public function addTerm($a_term_id)
92  {
93  if (!in_array($a_term_id, $this->terms)) {
94  $this->terms[] = $a_term_id;
95  }
96  }
97 
103  public function deleteTerm($a_term_id)
104  {
105  foreach ($this->terms as $k => $v) {
106  if ($v == $a_term_id) {
107  unset($this->terms[$k]);
108  }
109  }
110  }
111 
112 
116  public function read()
117  {
118  $set = $this->db->query("SELECT term_id FROM glo_term_reference " .
119  " WHERE glo_id = " . $this->db->quote($this->getGlossaryId(), "integer"));
120  while ($rec = $this->db->fetchAssoc($set)) {
121  $this->addTerm($rec["term_id"]);
122  }
123  }
124 
128  public function update()
129  {
130  $this->delete();
131  foreach ($this->getTerms() as $t) {
132  $this->db->replace(
133  "glo_term_reference",
134  array(
135  "glo_id" => array("integer", $this->getGlossaryId()),
136  "term_id" => array("integer", $t),
137  ),
138  array()
139  );
140  }
141  }
142 
146  public function delete()
147  {
148  $this->db->manipulate(
149  "DELETE FROM glo_term_reference WHERE " .
150  " glo_id = " . $this->db->quote($this->getGlossaryId(), "integer")
151  );
152  }
153 
159  public static function deleteReferencesOfTerm($a_term_id)
160  {
161  global $DIC;
162 
163  $db = $DIC->database();
164  $db->manipulate(
165  "DELETE FROM glo_term_reference WHERE " .
166  " term_id = " . $db->quote($a_term_id, "integer")
167  );
168  }
169 
170 
177  public static function hasReferences($a_glossary_id)
178  {
179  global $DIC;
180 
181  $db = $DIC->database();
182  $set = $db->query(
183  "SELECT * FROM glo_term_reference " .
184  " WHERE glo_id = " . $db->quote($a_glossary_id, "integer")
185  );
186  if ($rec = $db->fetchAssoc($set)) {
187  return true;
188  }
189  return false;
190  }
191 
198  public static function isReferenced($a_glo_id, $a_term_id)
199  {
200  global $DIC;
201 
202  $db = $DIC->database();
203  if (!is_array($a_glo_id)) {
204  $a_glo_id = array($a_glo_id);
205  }
206  $set = $db->query(
207  $q = "SELECT * FROM glo_term_reference " .
208  " WHERE " . $db->in("glo_id", $a_glo_id, false, "integer") .
209  " AND term_id = " . $db->quote($a_term_id, "integer")
210  );
211  if ($rec = $db->fetchAssoc($set)) {
212  return true;
213  }
214  return false;
215  }
216 
223  public static function lookupReferencesOfTerm($a_term_id)
224  {
225  global $DIC;
226 
227  $db = $DIC->database();
228  $set = $db->query(
229  $q = "SELECT DISTINCT glo_id FROM glo_term_reference " .
230  " WHERE term_id = " . $db->quote($a_term_id, "integer")
231  );
232  $glos = array();
233  while ($rec = $db->fetchAssoc($set)) {
234  $glos[] = $rec["glo_id"];
235  }
236  return $glos;
237  }
238 }
static hasReferences($a_glossary_id)
Check if a glossary uses references.
static isReferenced($a_glo_id, $a_term_id)
Is a term referenced by one or multiple glossaries.
global $DIC
Definition: saml.php:7
static lookupReferencesOfTerm($a_term_id)
Lookup references of a term.
static deleteReferencesOfTerm($a_term_id)
Delete all references of a term.
setGlossaryId($a_val)
Set glossary id.