ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilExcCriteria.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11abstract class ilExcCriteria
12{
13 protected $id; // [int]
14 protected $parent; // [int]
15 protected $title; // [string]
16 protected $desc; // [string]
17 protected $required; // [bool]
18 protected $pos; // [int]
19 protected $def; // [string]
20
21 protected $form; // [ilPropertyFormGUI]
22 protected $ass; // [ilExAssignment]
23 protected $giver_id; // [int]
24 protected $peer_id; // [int]
25
26 protected function __construct()
27 {
28
29 }
30
31 public static function getInstanceById($a_id)
32 {
33 global $ilDB;
34
35 $set = $ilDB->query("SELECT *".
36 " FROM exc_crit".
37 " WHERE id = ".$ilDB->quote($a_id, "integer"));
38 if($ilDB->numRows($set))
39 {
40 $row = $ilDB->fetchAssoc($set);
41 $obj = self::getInstanceByType($row["type"]);
42 $obj->importFromDB($row);
43 return $obj;
44 }
45 }
46
47 public static function getInstancesByParentId($a_parent_id)
48 {
49 global $ilDB;
50
51 $res = array();
52
53 $set = $ilDB->query("SELECT *".
54 " FROM exc_crit".
55 " WHERE parent = ".$ilDB->quote($a_parent_id, "integer").
56 " ORDER BY pos");
57 while($row = $ilDB->fetchAssoc($set))
58 {
59 $obj = self::getInstanceByType($row["type"]);
60 $obj->importFromDB($row);
61 $res[$obj->getId()] = $obj;
62 }
63
64 return $res;
65 }
66
67
68 //
69 // type(s)
70 //
71
72 public static function getTypesMap()
73 {
74 global $lng;
75
76 return array(
77 "bool" => $lng->txt("exc_criteria_type_bool")
78 ,"rating" => $lng->txt("exc_criteria_type_rating")
79 ,"text" => $lng->txt("exc_criteria_type_text")
80 ,"file" => $lng->txt("exc_criteria_type_file")
81 );
82 }
83
84 public function getTranslatedType()
85 {
86 $map = $this->getTypesMap();
87 return $map[$this->getType()];
88 }
89
90 public static function getInstanceByType($a_type)
91 {
92 $class = "ilExcCriteria".ucfirst($a_type);
93 include_once "Modules/Exercise/classes/class.".$class.".php";
94 return new $class;
95 }
96
97
98 //
99 // properties
100 //
101
102 public function getId()
103 {
104 return $this->id;
105 }
106
107 protected function setId($a_id)
108 {
109 $this->id = (int)$a_id;
110 }
111
112 abstract public function getType();
113
114 public function setParent($a_value)
115 {
116 $this->parent = ($a_value !== null)
117 ? (int)$a_value
118 : null;
119 }
120
121 public function getParent()
122 {
123 return $this->parent;
124 }
125
126 public function setTitle($a_value)
127 {
128 $this->title = ($a_value !== null)
129 ? trim($a_value)
130 : null;
131 }
132
133 public function getTitle()
134 {
135 return $this->title;
136 }
137
138 public function setDescription($a_value)
139 {
140 $this->desc = ($a_value !== null)
141 ? trim($a_value)
142 : null;
143 }
144
145 public function getDescription()
146 {
147 return $this->desc;
148 }
149
150 public function setRequired($a_value)
151 {
152 $this->required = (bool)$a_value;
153 }
154
155 public function isRequired()
156 {
157 return $this->required;
158 }
159
160 public function setPosition($a_value)
161 {
162 $this->pos = (int)$a_value;
163 }
164
165 public function getPosition()
166 {
167 return $this->pos;
168 }
169
170 protected function setDefinition(array $a_value = null)
171 {
172 $this->def = $a_value;
173 }
174
175 protected function getDefinition()
176 {
177 return $this->def;
178 }
179
180 public function importDefinition($a_def)
181 {
182 if($a_def)
183 {
184 $a_def = @unserialize($a_def);
185 if(is_array($a_def))
186 {
187 $this->setDefinition($a_def);
188 }
189 }
190 }
191
192
193 //
194 // CRUD
195 //
196
197 protected function importFromDB(array $a_row)
198 {
199 $this->setId($a_row["id"]);
200 $this->setParent($a_row["parent"]);
201 $this->setTitle($a_row["title"]);
202 $this->setDescription($a_row["descr"]);
203 $this->setRequired($a_row["required"]);
204 $this->setPosition($a_row["pos"]);
205 $this->setDefinition($a_row["def"]
206 ? unserialize($a_row["def"])
207 : null);
208 }
209
210 protected function getDBProperties()
211 {
212 return array(
213 "type" => array("text", $this->getType())
214 ,"title" => array("text", $this->getTitle())
215 ,"descr" => array("text", $this->getDescription())
216 ,"required" => array("integer", $this->isRequired())
217 ,"pos" => array("integer", $this->getPosition())
218 ,"def" => array("text", is_array($this->getDefinition())
219 ? serialize($this->getDefinition())
220 : null)
221 );
222 }
223 protected function getLastPosition()
224 {
225 global $ilDB;
226
227 if(!$this->getParent())
228 {
229 return;
230 }
231
232 $set = $ilDB->query("SELECT MAX(pos) pos".
233 " FROM exc_crit".
234 " WHERE parent = ".$ilDB->quote($this->getParent(), "integer"));
235 $row = $ilDB->fetchAssoc($set);
236 return (int)$row["pos"];
237 }
238
239 public function save()
240 {
241 global $ilDB;
242
243 if($this->id)
244 {
245 return $this->update();
246 }
247
248 $this->id = $ilDB->nextId("exc_crit");
249
250 $fields = $this->getDBProperties();
251
252 $fields["id"] = array("integer", $this->id);
253 $fields["type"] = array("text", $this->getType());
254 $fields["parent"] = array("integer", $this->getParent());
255 $fields["pos"] = array("integer", $this->getLastPosition()+10);
256
257 $ilDB->insert("exc_crit", $fields);
258 }
259
260 public function update()
261 {
262 global $ilDB;
263
264 if(!$this->id)
265 {
266 return $this->save();
267 }
268
269 $primary = array("id"=>array("integer", $this->id));
270 $ilDB->update("exc_crit", $this->getDBProperties(), $primary);
271 }
272
273 public function delete()
274 {
275 global $ilDB;
276
277 if(!$this->id)
278 {
279 return;
280 }
281
282 $ilDB->manipulate("DELETE FROM exc_crit".
283 " WHERE id = ".$ilDB->quote($this->id, "integer"));
284 }
285
286 public static function deleteByParent($a_parent_id)
287 {
288 global $ilDB;
289
290 if(!(int)$a_parent_id)
291 {
292 return;
293 }
294
295 $ilDB->manipulate("DELETE FROM exc_crit".
296 " WHERE parent = ".$ilDB->quote($a_parent_id, "integer"));
297 }
298
299 public function cloneObject($a_target_parent_id)
300 {
301 $new_obj = ilExcCriteria::getInstanceByType($this->getType());
302 $new_obj->setParent($a_target_parent_id);
303 $new_obj->setTitle($this->getTitle());
304 $new_obj->setDescription($this->getDescription());
305 $new_obj->setRequired($this->isRequired());
306 $new_obj->setPosition($this->getPosition());
307 $new_obj->setDefinition($this->getDefinition());
308 $new_obj->save();
309
310 return $new_obj->getId();
311 }
312
313
314 //
315 // ASSIGNMENT EDITOR
316 //
317
318 public function initCustomForm(ilPropertyFormGUI $a_form)
319 {
320 // type-specific
321 }
322
323 public function exportCustomForm(ilPropertyFormGUI $a_form)
324 {
325 // type-specific
326 }
327
328 public function importCustomForm(ilPropertyFormGUI $a_form)
329 {
330 // type-specific
331 }
332
333
334 // PEER REVIEW
335
336 public function setPeerReviewContext(ilExAssignment $a_ass, $a_giver_id, $a_peer_id, ilPropertyFormGUI $a_form = null)
337 {
338 $this->form = $a_form;
339 $this->ass = $a_ass;
340 $this->giver_id = $a_giver_id;
341 $this->peer_id = $a_peer_id;
342 }
343
344 abstract public function addToPeerReviewForm($a_value = null);
345
346 abstract public function importFromPeerReviewForm();
347
348 public function updateFromAjax()
349 {
350 // type-specific
351 }
352
353 public function validate($a_value)
354 {
355 return true;
356 }
357
358 abstract public function hasValue($a_value);
359
360 abstract public function getHTML($a_value);
361
362 public function resetReview()
363 {
364 // type-specific (only needed for data not kept in exc_assignment_peer)
365 }
366
367}
Exercise assignment.
Class ilExcCriteria.
importFromPeerReviewForm()
cloneObject($a_target_parent_id)
static getInstancesByParentId($a_parent_id)
importFromDB(array $a_row)
initCustomForm(ilPropertyFormGUI $a_form)
setPeerReviewContext(ilExAssignment $a_ass, $a_giver_id, $a_peer_id, ilPropertyFormGUI $a_form=null)
static getInstanceById($a_id)
exportCustomForm(ilPropertyFormGUI $a_form)
getHTML($a_value)
importCustomForm(ilPropertyFormGUI $a_form)
addToPeerReviewForm($a_value=null)
static getInstanceByType($a_type)
hasValue($a_value)
setDefinition(array $a_value=null)
static deleteByParent($a_parent_id)
This class represents a property form user interface.
global $lng
Definition: privfeed.php:40
global $ilDB