ILIAS  release_7 Revision v7.30-3-g800a261c036
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 {
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 {
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 {
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}
An exception for terminatinating execution or to throw for unit testing.
Class ilRatingCategory.
setPosition($a_value)
Set position.
save()
Create db entry.
setTitle($a_value)
Set title.
read($a_id)
Load db entry.
static delete($a_id)
Delete db entry.
setParentId($a_value)
Set parent id.
update()
Update db entry.
getParentId()
Get parent object id.
getDescription()
Get description.
getDBProperties()
Parse properties into db definition.
setDescription($a_value)
Set description.
__construct($a_id=null)
Constructor.
static deleteForObject($a_parent_obj_id)
Delete all categories for object.
setId($a_value)
Set id.
static getAllForObject($a_parent_obj_id)
Get all categories for object.
global $DIC
Definition: goto.php:24
global $ilDB