ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
52 
53  $query = "SELECT * FROM usr_starting_point WHERE id = " . $ilDB->quote($a_id, 'integer');
54  $res = $ilDB->query($query);
55 
56  while ($point = $ilDB->fetchAssoc($res)) {
57  $this->setStartingPoint($point['starting_point']);
58  $this->setRuleOptions($point['rule_options']);
59  $this->setPosition($point['position']);
60  $this->setStartingObject($point['starting_object']);
61  $this->setRuleType($point['rule_type']);
62  }
63  }
64 
71  public function setStartingPoint($a_starting_point)
72  {
73  $this->starting_point = $a_starting_point;
74  }
75 
82  public function getStartingPoint()
83  {
84  return $this->starting_point;
85  }
86 
93  public function setStartingObject($a_starting_object)
94  {
95  $this->starting_object = $a_starting_object;
96  }
97 
104  public function getStartingObject()
105  {
106  return $this->starting_object;
107  }
108 
115  public function setPosition($a_starting_position)
116  {
117  $this->starting_position = $a_starting_position;
118  }
119 
126  public function getPosition()
127  {
129  }
130 
137  public function setRuleType($a_rule_type)
138  {
139  $this->rule_type = $a_rule_type;
140  }
141 
148  public function getRuleType()
149  {
150  return $this->rule_type;
151  }
152 
159  public function setRuleOptions($a_rule_options)
160  {
161  $this->rule_options = $a_rule_options;
162  }
163 
164 
171  public function getRuleOptions()
172  {
173  return $this->rule_options;
174  }
175 
180  public static function getStartingPoints()
181  {
182  global $ilDB;
183 
184  $query = "SELECT * FROM usr_starting_point";
185  $res = $ilDB->query($query);
186  $points = array();
187  while ($point = $ilDB->fetchAssoc($res)) {
188  $points[] = array(
189  "id" => $point["id"],
190  "position" => $point["position"],
191  "starting_point" => $point['starting_point'],
192  "starting_object" => $point['starting_object'],
193  "rule_type" => $point['rule_type'],
194  "rule_options" => $point['rule_options']
195  );
196  }
197 
198  return $points;
199  }
200 
205  public static function getRolesWithStartingPoint()
206  {
207  global $ilDB;
208 
209  $query = "SELECT * FROM usr_starting_point WHERE rule_options LIKE %s";
210  $res = $ilDB->queryF($query, array('text'), array("%role_id%"));
211 
212  $roles = array();
213  while ($sp = $ilDB->fetchAssoc($res)) {
214  $options = unserialize($sp['rule_options']);
215 
216  $roles[$options['role_id']] = array(
217  "id" => $sp['id'],
218  "starting_point" => $sp['starting_point'],
219  "starting_object" => $sp['starting_object'],
220  "position" => $sp['position'],
221  "role_id" => $options['role_id'],
222 
223  );
224  }
225  return $roles;
226  }
227 
232  public static function getGlobalRolesWithoutStartingPoint()
233  {
234  global $rbacreview;
235 
236  require_once "./Services/AccessControl/classes/class.ilObjRole.php";
237 
238  $global_roles = $rbacreview->getGlobalRoles();
239 
240  $roles_with_starting_point = self::getRolesWithStartingPoint();
241 
242  $ids_roles_with_sp = array();
243  foreach ($roles_with_starting_point as $role) {
244  array_push($ids_roles_with_sp, $role['role_id']);
245  }
246 
247  $ids_roles_without_sp = array_diff($global_roles, $ids_roles_with_sp);
248 
249  $roles = array();
250  foreach ($ids_roles_without_sp as $roleid) {
251  $role_obj = new ilObjRole($roleid);
252  $roles[] = array(
253  "id" => $role_obj->getId(),
254  "title" => $role_obj->getTitle(),
255  );
256  }
257 
258  return $roles;
259  }
260 
264  public function save()
265  {
266  global $ilDB;
267 
268  //get position
269  $max_position = $this->getMaxPosition();
270  $position = $max_position + 10;
271 
272  $next_id = $ilDB->nextId('usr_starting_point');
273  $values = array(
274  $next_id,
275  $this->getStartingPoint(),
276  $this->getStartingObject(),
277  $position,
278  $this->getRuleType(),
279  $this->getRuleOptions()
280  );
281 
282  $ilDB->manipulateF(
283  "INSERT INTO usr_starting_point (id, starting_point, starting_object, position, rule_type, rule_options) VALUES (%s, %s, %s, %s, %s, %s)",
284  array('integer', 'integer', 'integer', 'integer', 'integer', 'text'),
285  $values
286  );
287  }
288 
292  public function update()
293  {
294  global $ilDB;
295 
296  $ilDB->manipulateF(
297  'UPDATE usr_starting_point
298  SET starting_point = %s,
299  starting_object = %s,
300  position = %s,
301  rule_type = %s,
302  rule_options = %s
303  WHERE id = %s',
304  array('integer', 'integer', 'integer', 'integer', 'text', 'integer'),
305  array($this->getStartingPoint(), $this->getStartingObject(), $this->getPosition(),
306  $this->getRuleType(), $this->getRuleOptions(), $this->id)
307  );
308  }
309 
313  public function delete()
314  {
315  global $ilDB;
316 
317  $query = "DELETE FROM usr_starting_point WHERE id = " . $ilDB->quote($this->id, "integer");
318  $ilDB->manipulate($query);
319  }
320 
321  //Order methods
326  public function getMaxPosition()
327  {
328  global $ilDB;
329 
330  //get max order number
331  $result = $ilDB->query("SELECT max(position) as max_order FROM usr_starting_point");
332 
333  while ($row = $ilDB->fetchAssoc($result)) {
334  $order_val = (int) $row['max_order'];
335  }
336  return $order_val;
337  }
338 
343  public static function reArrangePositions($a_items)
344  {
345  //first and last items doesn't have order position, are fixed.
346  $ord_const = 10;
347  foreach ($a_items as $k => $v) {
348  if ($k > 0) {
349  $item = $v;
350  $item['starting_position'] = $ord_const;
351  unset($a_items[$k]);
352  $a_items[$ord_const] = $item;
353  $ord_const = $ord_const + 10;
354  }
355  }
356 
357  return $a_items;
358  }
359 
364  public function saveOrder($a_items)
365  {
366  global $ilDB;
367 
368  asort($a_items);
369  $nr = 10;
370  foreach ($a_items as $id => $position) {
371  if ($position > self::ORDER_POSITION_MIN && $position < self::ORDER_POSITION_MAX) {
372  $ilDB->manipulate(
373  "UPDATE usr_starting_point SET" .
374  " position = " . $ilDB->quote($nr, 'integer') .
375  " WHERE id = " . $ilDB->quote($id, 'integer')
376  );
377  $nr+=10;
378  }
379  }
380  }
381 }
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.
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.
setStartingPoint($a_starting_point)
Sets the starting point.
saveOrder($a_items)
Save all starting point positions.
$query
Create styles array
The data for the language used.
getRuleType()
Gets the rule type.
global $ilDB
__construct($a_id=0)
Constructor.
static reArrangePositions($a_items)
getStartingPoint()
Gets the starting point.
setRuleType($a_rule_type)
Sets rule type.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20