ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilStartingPoint.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
13 //list view: first and last items in the table are fixed.
15 const ORDER_POSITION_MAX = 9999;
16
17 //rule options.
18 const FALLBACK_RULE = 1;
19 const ROLE_BASED = 2;
21
22 protected $starting_point;
25 protected $rule_type;
26 protected $rule_options; // array serialized in db
27 protected $id;
28 protected $calendar_view;
30
36 public function __construct($a_id = 0)
37 {
38 if ($a_id > 0) {
39 $this->id = $a_id;
40 $this->setData($a_id);
41 }
42 }
43
49 private function setData($a_id)
50 {
51 global $DIC;
52
53 $ilDB = $DIC['ilDB'];
54
55 $query = "SELECT * FROM usr_starting_point WHERE id = " . $ilDB->quote($a_id, 'integer');
56 $res = $ilDB->query($query);
57
58 while ($point = $ilDB->fetchAssoc($res)) {
59 $this->setStartingPoint($point['starting_point']);
60 $this->setRuleOptions($point['rule_options']);
61 $this->setPosition($point['position']);
62 $this->setStartingObject($point['starting_object']);
63 $this->setRuleType($point['rule_type']);
64 $this->setCalendarView($point['calendar_view']);
65 $this->setCalendarPeriod($point['calendar_period']);
66 }
67 }
68
75 public function setStartingPoint($a_starting_point)
76 {
77 $this->starting_point = $a_starting_point;
78 }
79
86 public function getStartingPoint()
87 {
89 }
90
97 public function setStartingObject($a_starting_object)
98 {
99 $this->starting_object = $a_starting_object;
100 }
101
108 public function getStartingObject()
109 {
111 }
112
119 public function setPosition($a_starting_position)
120 {
121 $this->starting_position = $a_starting_position;
122 }
123
130 public function getPosition()
131 {
133 }
134
141 public function setRuleType($a_rule_type)
142 {
143 $this->rule_type = $a_rule_type;
144 }
145
152 public function getRuleType()
153 {
154 return $this->rule_type;
155 }
156
163 public function setRuleOptions($a_rule_options)
164 {
165 $this->rule_options = $a_rule_options;
166 }
167
173 public function getCalendarView() : int
174 {
176 }
177
183 public function setCalendarView(int $calendar_view) : void
184 {
185 $this->calendar_view = $calendar_view;
186 }
187
193 public function getCalendarPeriod() : int
194 {
196 }
197
203 public function setCalendarPeriod(int $calendar_period) : void
204 {
205 $this->calendar_period = $calendar_period;
206 }
207
214 public function getRuleOptions()
215 {
216 return $this->rule_options;
217 }
218
223 public static function getStartingPoints()
224 {
225 global $DIC;
226
227 $ilDB = $DIC['ilDB'];
228
229 $query = "SELECT * FROM usr_starting_point";
230 $res = $ilDB->query($query);
231 $points = array();
232 while ($point = $ilDB->fetchAssoc($res)) {
233 $points[] = array(
234 "id" => $point["id"],
235 "position" => $point["position"],
236 "starting_point" => $point['starting_point'],
237 "starting_object" => $point['starting_object'],
238 "calendar_view" => $point['calendar_view'],
239 "calendar_period" => $point['calendar_period'],
240 "rule_type" => $point['rule_type'],
241 "rule_options" => $point['rule_options']
242 );
243 }
244
245 return $points;
246 }
247
252 public static function onRoleDeleted(ilObjRole $role)
253 {
254 foreach (self::getRolesWithStartingPoint() as $roleId => $data) {
255 if ((int) $roleId === (int) $role->getId()) {
256 $sp = new self((int) $data['id']);
257 $sp->delete();
258 } elseif (
259 false === ($maybeDeletedRole = ilObjectFactory::getInstanceByObjId((int) $roleId, false)) ||
260 !($maybeDeletedRole instanceof ilObjRole)
261 ) {
262 $sp = new self((int) $data['id']);
263 $sp->delete();
264 }
265 }
266 }
267
272 public static function getRolesWithStartingPoint()
273 {
274 global $DIC;
275
276 $ilDB = $DIC['ilDB'];
277
278 $query = "SELECT * FROM usr_starting_point WHERE rule_options LIKE %s";
279 $res = $ilDB->queryF($query, array('text'), array("%role_id%"));
280
281 $roles = array();
282 while ($sp = $ilDB->fetchAssoc($res)) {
283 $options = unserialize($sp['rule_options']);
284
285 $roles[$options['role_id']] = array(
286 "id" => $sp['id'],
287 "starting_point" => $sp['starting_point'],
288 "starting_object" => $sp['starting_object'],
289 "calendar_view" => $sp['calendar_view'],
290 "calendar_period" => $sp['calendar_period'],
291 "position" => $sp['position'],
292 "role_id" => $options['role_id'],
293
294 );
295 }
296 return $roles;
297 }
298
303 public static function getGlobalRolesWithoutStartingPoint()
304 {
305 global $DIC;
306
307 $rbacreview = $DIC['rbacreview'];
308
309 require_once "./Services/AccessControl/classes/class.ilObjRole.php";
310
311 $global_roles = $rbacreview->getGlobalRoles();
312
313 $roles_with_starting_point = self::getRolesWithStartingPoint();
314
315 $ids_roles_with_sp = array();
316 foreach ($roles_with_starting_point as $role) {
317 array_push($ids_roles_with_sp, $role['role_id']);
318 }
319
320 $ids_roles_without_sp = array_diff($global_roles, $ids_roles_with_sp);
321
322 $roles = array();
323 foreach ($ids_roles_without_sp as $roleid) {
324 if ($roleid === ANONYMOUS_ROLE_ID) {
325 continue;
326 }
327 $role_obj = new ilObjRole($roleid);
328 $roles[] = array(
329 "id" => $role_obj->getId(),
330 "title" => $role_obj->getTitle(),
331 );
332 }
333
334 return $roles;
335 }
336
340 public function save()
341 {
342 global $DIC;
343
344 $ilDB = $DIC['ilDB'];
345
346 //get position
347 $max_position = $this->getMaxPosition();
348 $position = $max_position + 10;
349
350 $next_id = $ilDB->nextId('usr_starting_point');
351 $values = array(
352 $next_id,
353 $this->getStartingPoint(),
354 $this->getStartingObject(),
355 $position,
356 $this->getRuleType(),
357 $this->getRuleOptions(),
358 $this->getCalendarView(),
359 $this->getCalendarPeriod()
360 );
361
362 $ilDB->manipulateF(
363 "INSERT INTO usr_starting_point (id, starting_point, starting_object, position, rule_type, rule_options, calendar_view, calendar_period) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
365 $values
366 );
367 }
368
372 public function update()
373 {
374 global $DIC;
375
376 $ilDB = $DIC['ilDB'];
377
378 $ilDB->manipulateF(
379 'UPDATE usr_starting_point
380 SET starting_point = %s,
381 starting_object = %s,
382 position = %s,
383 rule_type = %s,
384 rule_options = %s,
385 calendar_view = %s,
386 calendar_period = %s
387 WHERE id = %s',
389 array($this->getStartingPoint(), $this->getStartingObject(), $this->getPosition(),
390 $this->getRuleType(), $this->getRuleOptions(), $this->getCalendarView(), $this->getCalendarPeriod(), $this->id)
391 );
392 }
393
397 public function delete()
398 {
399 global $DIC;
400
401 $ilDB = $DIC['ilDB'];
402
403 $query = "DELETE FROM usr_starting_point WHERE id = " . $ilDB->quote($this->id, "integer");
404 $ilDB->manipulate($query);
405 }
406
407 //Order methods
412 public function getMaxPosition()
413 {
414 global $DIC;
415
416 $ilDB = $DIC['ilDB'];
417
418 //get max order number
419 $result = $ilDB->query("SELECT max(position) as max_order FROM usr_starting_point");
420
421 while ($row = $ilDB->fetchAssoc($result)) {
422 $order_val = (int) $row['max_order'];
423 }
424 return $order_val;
425 }
426
431 public static function reArrangePositions($a_items)
432 {
433 $ord_const = 0;
434 $rearranged = [];
435 foreach ($a_items as $k => $v) {
436 $v['starting_position'] = $ord_const;
437 $rearranged[$ord_const] = $v;
438 $ord_const = $ord_const + 10;
439 }
440 return $rearranged;
441 }
442
447 public function saveOrder($a_items)
448 {
449 global $DIC;
450
451 $ilDB = $DIC['ilDB'];
452
453 asort($a_items);
454 $nr = 10;
455 foreach ($a_items as $id => $position) {
456 if ($position > self::ORDER_POSITION_MIN && $position < self::ORDER_POSITION_MAX) {
457 $ilDB->manipulate(
458 "UPDATE usr_starting_point SET" .
459 " position = " . $ilDB->quote($nr, 'integer') .
460 " WHERE id = " . $ilDB->quote($id, 'integer')
461 );
462 $nr += 10;
463 }
464 }
465 }
466}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilObjRole.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
getId()
get object id @access public
Class ilStartingPoint.
getCalendarView()
Gets calendar view.
save()
insert starting point into database
getPosition()
Gets the starting point position.
getStartingObject()
Gets the starting object.
static getRolesWithStartingPoint()
get array with all roles which have starting point defined.
setStartingObject($a_starting_object)
Sets the starting object.
update()
update starting point
setData($a_id)
Set data for the starting point.
static getStartingPoints()
Get all the starting points in database.
getRuleType()
Gets the rule type.
setPosition($a_starting_position)
Sets the starting position.
setRuleOptions($a_rule_options)
Sets rule type options.
getCalendarPeriod()
Gets calendar Period.
getRuleOptions()
Gets the rule options.
setRuleType($a_rule_type)
Sets rule type.
saveOrder($a_items)
Save all starting point positions.
setCalendarPeriod(int $calendar_period)
Sets calendar Period.
static onRoleDeleted(ilObjRole $role)
getStartingPoint()
Gets the starting point.
setCalendarView(int $calendar_view)
Sets calendar view.
setStartingPoint($a_starting_point)
Sets the starting point.
static reArrangePositions($a_items)
static getGlobalRolesWithoutStartingPoint()
Get id and title of the roles without starting points.
__construct($a_id=0)
Constructor.
const ANONYMOUS_ROLE_ID
Definition: constants.php:26
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23