ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
17 protected $id; // [int] sequence
18 protected $parent_id; // [int] parent object
19 protected $title; // [string]
20 protected $description; // [string]
21 protected $pos; // [int] order
22
28 public function __construct($a_id = null)
29 {
30 $this->read($a_id);
31 }
32
38 public function setId($a_value)
39 {
40 $this->id = (int)$a_value;
41 }
42
48 public function getId()
49 {
50 return $this->id;
51 }
52
58 public function setParentId($a_value)
59 {
60 $this->parent_id = (int)$a_value;
61 }
62
68 public function getParentId()
69 {
70 return $this->parent_id;
71 }
72
78 public function setTitle($a_value)
79 {
80 $this->title = (string)$a_value;
81 }
82
88 public function getTitle()
89 {
90 return $this->title;
91 }
92
98 public function setDescription($a_value)
99 {
100 $this->description = (string)$a_value;
101 }
102
108 public function getDescription()
109 {
110 return $this->description;
111 }
112
118 public function setPosition($a_value)
119 {
120 $this->pos = (int)$a_value;
121 }
122
128 public function getPosition()
129 {
130 return $this->pos;
131 }
132
138 protected function read($a_id)
139 {
140 global $ilDB;
141
142 $a_id = (int)$a_id;
143 if($a_id)
144 {
145 $sql = "SELECT * FROM il_rating_cat".
146 " WHERE id = ".$ilDB->quote($a_id, "integer");
147 $set = $ilDB->query($sql);
148 $row = $ilDB->fetchAssoc($set);
149 if($row["id"])
150 {
151 $this->setId($row["id"]);
152 $this->setParentId($row["parent_id"]);
153 $this->setTitle($row["title"]);
154 $this->setDescription($row["description"]);
155 $this->setPosition($row["pos"]);
156 }
157 }
158 }
159
165 protected function getDBProperties()
166 {
167 // parent id must not change
168 $fields = array("title" => array("text", $this->getTitle()),
169 "description" => array("text", $this->getDescription()),
170 "pos" => array("integer", $this->getPosition()));
171
172 return $fields;
173 }
174
178 public function update()
179 {
180 global $ilDB;
181
182 if($this->getId())
183 {
184 $fields = $this->getDBProperties();
185
186 $ilDB->update("il_rating_cat", $fields,
187 array("id" => array("integer", $this->getId())));
188 }
189 }
190
194 public function save()
195 {
196 global $ilDB;
197
198 $id = $ilDB->nextId("il_rating_cat");
199 $this->setId($id);
200
201 // append
202 $sql = "SELECT max(pos) pos FROM il_rating_cat".
203 " WHERE parent_id = ".$ilDB->quote($this->getParentId(), "integer");
204 $set = $ilDB->query($sql);
205 $pos = $ilDB->fetchAssoc($set);
206 $pos = $pos["pos"];
207 $this->setPosition($pos+10);
208
209 $fields = $this->getDBProperties();
210 $fields["id"] = array("integer", $id);
211 $fields["parent_id"] = array("integer", $this->getParentId());
212
213 $ilDB->insert("il_rating_cat", $fields);
214 }
215
221 public static function delete($a_id)
222 {
223 global $ilDB;
224
225 if((int)$a_id)
226 {
227 $sql = "DELETE FROM il_rating".
228 " WHERE category_id = ".$ilDB->quote($a_id, "integer");
229 $ilDB->manipulate($sql);
230
231 $sql = "DELETE FROM il_rating_cat".
232 " WHERE id = ".$ilDB->quote($a_id, "integer");
233 $ilDB->manipulate($sql);
234 }
235 }
236
243 public static function getAllForObject($a_parent_obj_id)
244 {
245 global $ilDB;
246
247 $cats = array();
248
249 $sql = "SELECT * FROM il_rating_cat".
250 " WHERE parent_id = ".$ilDB->quote($a_parent_obj_id, "integer").
251 " ORDER BY pos";
252 $set = $ilDB->query($sql);
253 while($row = $ilDB->fetchAssoc($set))
254 {
255 $cats[] = $row;
256 }
257
258 return $cats;
259 }
260
266 public static function deleteForObject($a_parent_obj_id)
267 {
268 if((int)$a_parent_obj_id)
269 {
270 foreach(self::getAllForObject($a_parent_obj_id) as $item)
271 {
272 self::delete($item["id"]);
273 }
274 }
275 }
276}
277
278?>
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 $ilDB