ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilRatingCategory.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
16 {
20  protected $db;
21 
22  protected $id; // [int] sequence
23  protected $parent_id; // [int] parent object
24  protected $title; // [string]
25  protected $description; // [string]
26  protected $pos; // [int] order
27 
33  public function __construct($a_id = null)
34  {
35  global $DIC;
36 
37  $this->db = $DIC->database();
38  $this->read($a_id);
39  }
40 
46  public function setId($a_value)
47  {
48  $this->id = (int) $a_value;
49  }
50 
56  public function getId()
57  {
58  return $this->id;
59  }
60 
66  public function setParentId($a_value)
67  {
68  $this->parent_id = (int) $a_value;
69  }
70 
76  public function getParentId()
77  {
78  return $this->parent_id;
79  }
80 
86  public function setTitle($a_value)
87  {
88  $this->title = (string) $a_value;
89  }
90 
96  public function getTitle()
97  {
98  return $this->title;
99  }
100 
106  public function setDescription($a_value)
107  {
108  $this->description = (string) $a_value;
109  }
110 
116  public function getDescription()
117  {
118  return $this->description;
119  }
120 
126  public function setPosition($a_value)
127  {
128  $this->pos = (int) $a_value;
129  }
130 
136  public function getPosition()
137  {
138  return $this->pos;
139  }
140 
146  protected function read($a_id)
147  {
148  $ilDB = $this->db;
149 
150  $a_id = (int) $a_id;
151  if ($a_id) {
152  $sql = "SELECT * FROM il_rating_cat" .
153  " WHERE id = " . $ilDB->quote($a_id, "integer");
154  $set = $ilDB->query($sql);
155  $row = $ilDB->fetchAssoc($set);
156  if ($row["id"]) {
157  $this->setId($row["id"]);
158  $this->setParentId($row["parent_id"]);
159  $this->setTitle($row["title"]);
160  $this->setDescription($row["description"]);
161  $this->setPosition($row["pos"]);
162  }
163  }
164  }
165 
171  protected function getDBProperties()
172  {
173  // parent id must not change
174  $fields = array("title" => array("text", $this->getTitle()),
175  "description" => array("text", $this->getDescription()),
176  "pos" => array("integer", $this->getPosition()));
177 
178  return $fields;
179  }
180 
184  public function update()
185  {
186  $ilDB = $this->db;
187 
188  if ($this->getId()) {
189  $fields = $this->getDBProperties();
190 
191  $ilDB->update(
192  "il_rating_cat",
193  $fields,
194  array("id" => array("integer", $this->getId()))
195  );
196  }
197  }
198 
202  public function save()
203  {
204  $ilDB = $this->db;
205 
206  $id = $ilDB->nextId("il_rating_cat");
207  $this->setId($id);
208 
209  // append
210  $sql = "SELECT max(pos) pos FROM il_rating_cat" .
211  " WHERE parent_id = " . $ilDB->quote($this->getParentId(), "integer");
212  $set = $ilDB->query($sql);
213  $pos = $ilDB->fetchAssoc($set);
214  $pos = $pos["pos"];
215  $this->setPosition($pos + 10);
216 
217  $fields = $this->getDBProperties();
218  $fields["id"] = array("integer", $id);
219  $fields["parent_id"] = array("integer", $this->getParentId());
220 
221  $ilDB->insert("il_rating_cat", $fields);
222  }
223 
229  public static function delete($a_id)
230  {
231  global $DIC;
232 
233  $ilDB = $DIC->database();
234 
235  if ((int) $a_id) {
236  $sql = "DELETE FROM il_rating" .
237  " WHERE category_id = " . $ilDB->quote($a_id, "integer");
238  $ilDB->manipulate($sql);
239 
240  $sql = "DELETE FROM il_rating_cat" .
241  " WHERE id = " . $ilDB->quote($a_id, "integer");
242  $ilDB->manipulate($sql);
243  }
244  }
245 
252  public static function getAllForObject($a_parent_obj_id)
253  {
254  global $DIC;
255 
256  $ilDB = $DIC->database();
257 
258  $cats = array();
259 
260  $sql = "SELECT * FROM il_rating_cat" .
261  " WHERE parent_id = " . $ilDB->quote($a_parent_obj_id, "integer") .
262  " ORDER BY pos";
263  $set = $ilDB->query($sql);
264  while ($row = $ilDB->fetchAssoc($set)) {
265  $cats[] = $row;
266  }
267 
268  return $cats;
269  }
270 
276  public static function deleteForObject($a_parent_obj_id)
277  {
278  if ((int) $a_parent_obj_id) {
279  foreach (self::getAllForObject($a_parent_obj_id) as $item) {
280  self::delete($item["id"]);
281  }
282  }
283  }
284 }
setPosition($a_value)
Set position.
getParentId()
Get parent object id.
global $DIC
Definition: saml.php:7
setId($a_value)
Set id.
static deleteForObject($a_parent_obj_id)
Delete all categories for object.
save()
Create db entry.
getPosition()
Get position.
static getAllForObject($a_parent_obj_id)
Get all categories for object.
getDescription()
Get description.
setParentId($a_value)
Set parent id.
getDBProperties()
Parse properties into db definition.
$row
setTitle($a_value)
Set title.
setDescription($a_value)
Set description.
global $ilDB
Class ilRatingCategory.
update()
Update db entry.
read($a_id)
Load db entry.
__construct($a_id=null)
Constructor.