ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
14 {
15  //list view: first and last items in the table are fixed.
16  const ORDER_POSITION_MIN = 0;
17  const ORDER_POSITION_MAX = 9999;
18 
19  //rule options.
20  const FALLBACK_RULE = 1;
21  const ROLE_BASED = 2;
23 
24  protected $starting_point;
25  protected $starting_object;
26  protected $starting_position;
27  protected $rule_type;
28  protected $rule_options; // array serialized in db
29  protected $id;
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  }
65  }
66 
73  public function setStartingPoint($a_starting_point)
74  {
75  $this->starting_point = $a_starting_point;
76  }
77 
84  public function getStartingPoint()
85  {
86  return $this->starting_point;
87  }
88 
95  public function setStartingObject($a_starting_object)
96  {
97  $this->starting_object = $a_starting_object;
98  }
99 
106  public function getStartingObject()
107  {
108  return $this->starting_object;
109  }
110 
117  public function setPosition($a_starting_position)
118  {
119  $this->starting_position = $a_starting_position;
120  }
121 
128  public function getPosition()
129  {
131  }
132 
139  public function setRuleType($a_rule_type)
140  {
141  $this->rule_type = $a_rule_type;
142  }
143 
150  public function getRuleType()
151  {
152  return $this->rule_type;
153  }
154 
161  public function setRuleOptions($a_rule_options)
162  {
163  $this->rule_options = $a_rule_options;
164  }
165 
166 
173  public function getRuleOptions()
174  {
175  return $this->rule_options;
176  }
177 
182  public static function getStartingPoints()
183  {
184  global $DIC;
185 
186  $ilDB = $DIC['ilDB'];
187 
188  $query = "SELECT * FROM usr_starting_point";
189  $res = $ilDB->query($query);
190  $points = array();
191  while ($point = $ilDB->fetchAssoc($res)) {
192  $points[] = array(
193  "id" => $point["id"],
194  "position" => $point["position"],
195  "starting_point" => $point['starting_point'],
196  "starting_object" => $point['starting_object'],
197  "rule_type" => $point['rule_type'],
198  "rule_options" => $point['rule_options']
199  );
200  }
201 
202  return $points;
203  }
204 
209  public static function onRoleDeleted(ilObjRole $role)
210  {
211  foreach (self::getRolesWithStartingPoint() as $roleId => $data) {
212  if ((int) $roleId === (int) $role->getId()) {
213  $sp = new self((int) $data['id']);
214  $sp->delete();
215  } elseif (
216  false === ($maybeDeletedRole = ilObjectFactory::getInstanceByObjId((int) $roleId, false)) ||
217  !($maybeDeletedRole instanceof ilObjRole)
218  ) {
219  $sp = new self((int) $data['id']);
220  $sp->delete();
221  }
222  }
223  }
224 
229  public static function getRolesWithStartingPoint()
230  {
231  global $DIC;
232 
233  $ilDB = $DIC['ilDB'];
234 
235  $query = "SELECT * FROM usr_starting_point WHERE rule_options LIKE %s";
236  $res = $ilDB->queryF($query, array('text'), array("%role_id%"));
237 
238  $roles = array();
239  while ($sp = $ilDB->fetchAssoc($res)) {
240  $options = unserialize($sp['rule_options']);
241 
242  $roles[$options['role_id']] = array(
243  "id" => $sp['id'],
244  "starting_point" => $sp['starting_point'],
245  "starting_object" => $sp['starting_object'],
246  "position" => $sp['position'],
247  "role_id" => $options['role_id'],
248 
249  );
250  }
251  return $roles;
252  }
253 
258  public static function getGlobalRolesWithoutStartingPoint()
259  {
260  global $DIC;
261 
262  $rbacreview = $DIC['rbacreview'];
263 
264  require_once "./Services/AccessControl/classes/class.ilObjRole.php";
265 
266  $global_roles = $rbacreview->getGlobalRoles();
267 
268  $roles_with_starting_point = self::getRolesWithStartingPoint();
269 
270  $ids_roles_with_sp = array();
271  foreach ($roles_with_starting_point as $role) {
272  array_push($ids_roles_with_sp, $role['role_id']);
273  }
274 
275  $ids_roles_without_sp = array_diff($global_roles, $ids_roles_with_sp);
276 
277  $roles = array();
278  foreach ($ids_roles_without_sp as $roleid) {
279  $role_obj = new ilObjRole($roleid);
280  $roles[] = array(
281  "id" => $role_obj->getId(),
282  "title" => $role_obj->getTitle(),
283  );
284  }
285 
286  return $roles;
287  }
288 
292  public function save()
293  {
294  global $DIC;
295 
296  $ilDB = $DIC['ilDB'];
297 
298  //get position
299  $max_position = $this->getMaxPosition();
300  $position = $max_position + 10;
301 
302  $next_id = $ilDB->nextId('usr_starting_point');
303  $values = array(
304  $next_id,
305  $this->getStartingPoint(),
306  $this->getStartingObject(),
307  $position,
308  $this->getRuleType(),
309  $this->getRuleOptions()
310  );
311 
312  $ilDB->manipulateF(
313  "INSERT INTO usr_starting_point (id, starting_point, starting_object, position, rule_type, rule_options) VALUES (%s, %s, %s, %s, %s, %s)",
314  array('integer', 'integer', 'integer', 'integer', 'integer', 'text'),
315  $values
316  );
317  }
318 
322  public function update()
323  {
324  global $DIC;
325 
326  $ilDB = $DIC['ilDB'];
327 
328  $ilDB->manipulateF(
329  'UPDATE usr_starting_point
330  SET starting_point = %s,
331  starting_object = %s,
332  position = %s,
333  rule_type = %s,
334  rule_options = %s
335  WHERE id = %s',
336  array('integer', 'integer', 'integer', 'integer', 'text', 'integer'),
337  array($this->getStartingPoint(), $this->getStartingObject(), $this->getPosition(),
338  $this->getRuleType(), $this->getRuleOptions(), $this->id)
339  );
340  }
341 
345  public function delete()
346  {
347  global $DIC;
348 
349  $ilDB = $DIC['ilDB'];
350 
351  $query = "DELETE FROM usr_starting_point WHERE id = " . $ilDB->quote($this->id, "integer");
352  $ilDB->manipulate($query);
353  }
354 
355  //Order methods
360  public function getMaxPosition()
361  {
362  global $DIC;
363 
364  $ilDB = $DIC['ilDB'];
365 
366  //get max order number
367  $result = $ilDB->query("SELECT max(position) as max_order FROM usr_starting_point");
368 
369  while ($row = $ilDB->fetchAssoc($result)) {
370  $order_val = (int) $row['max_order'];
371  }
372  return $order_val;
373  }
374 
379  public static function reArrangePositions($a_items)
380  {
381  $ord_const = 0;
382  $rearranged = [];
383  foreach ($a_items as $k => $v) {
384  $v['starting_position'] = $ord_const;
385  $rearranged[$ord_const] = $v;
386  $ord_const = $ord_const + 10;
387  }
388  return $rearranged;
389  }
390 
395  public function saveOrder($a_items)
396  {
397  global $DIC;
398 
399  $ilDB = $DIC['ilDB'];
400 
401  asort($a_items);
402  $nr = 10;
403  foreach ($a_items as $id => $position) {
404  if ($position > self::ORDER_POSITION_MIN && $position < self::ORDER_POSITION_MAX) {
405  $ilDB->manipulate(
406  "UPDATE usr_starting_point SET" .
407  " position = " . $ilDB->quote($nr, 'integer') .
408  " WHERE id = " . $ilDB->quote($id, 'integer')
409  );
410  $nr += 10;
411  }
412  }
413  }
414 }
Class ilObjRole.
setRuleOptions($a_rule_options)
Sets rule type options.
setStartingObject($a_starting_object)
Sets the starting object.
static getStartingPoints()
Get all the starting points in database.
$result
setData($a_id)
Set data for the starting point.
static onRoleDeleted(ilObjRole $role)
global $DIC
Definition: saml.php:7
Class ilStartingPoint.
update()
update starting point
save()
insert starting point into database
getRuleOptions()
Gets the rule options.
static getRolesWithStartingPoint()
get array with all roles which have starting point defined.
static getGlobalRolesWithoutStartingPoint()
Get id and title of the roles without starting points.
getStartingObject()
Gets the starting object.
getPosition()
Gets the starting point position.
foreach($_POST as $key=> $value) $res
setPosition($a_starting_position)
Sets the starting position.
getId()
get object id public
$values
setStartingPoint($a_starting_point)
Sets the starting point.
saveOrder($a_items)
Save all starting point positions.
$query
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
getRuleType()
Gets the rule type.
$row
global $ilDB
__construct($a_id=0)
Constructor.
static reArrangePositions($a_items)
getStartingPoint()
Gets the starting point.
setRuleType($a_rule_type)
Sets rule type.
$data
Definition: bench.php:6