ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBookingReservation.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  protected $id; // int
15  protected $object_id; // int
16  protected $user_id; // int
17  protected $from; // timestamp
18  protected $to; // timestamp
19  protected $status; // status
20  protected $group_id; // int
21 
22  const STATUS_IN_USE = 2;
23  const STATUS_CANCELLED = 5;
24 
32  function __construct($a_id = NULL)
33  {
34  $this->id = (int)$a_id;
35  $this->read();
36  }
37 
42  function getId()
43  {
44  return $this->id;
45  }
46 
51  function setObjectId($a_object_id)
52  {
53  $this->object_id = $a_object_id;
54  }
55 
60  function getObjectId()
61  {
62  return $this->object_id;
63  }
64 
69  function setUserId($a_user_id)
70  {
71  $this->user_id = (int)$a_user_id;
72  }
73 
78  function getUserId()
79  {
80  return $this->user_id;
81  }
82 
87  function setFrom($a_from)
88  {
89  $this->from = (int)$a_from;
90  }
91 
96  function getFrom()
97  {
98  return $this->from;
99  }
100 
105  function setTo($a_to)
106  {
107  $this->to = (int)$a_to;
108  }
109 
114  function getTo()
115  {
116  return $this->to;
117  }
118 
123  function setStatus($a_status)
124  {
125  if($a_status === NULL)
126  {
127  $this->status = NULL;
128  }
129  if($this->isValidStatus((int)$a_status))
130  {
131  $this->status = (int)$a_status;
132  }
133  }
134 
139  function getStatus()
140  {
141  return $this->status;
142  }
143 
149  static function isValidStatus($a_status)
150  {
151  if(in_array($a_status, array(self::STATUS_IN_USE, self::STATUS_CANCELLED)))
152  {
153  return true;
154  }
155  return false;
156  }
157 
162  function setGroupId($a_group_id)
163  {
164  $this->group_id = $a_group_id;
165  }
166 
171  function getGroupId()
172  {
173  return $this->group_id;
174  }
175 
179  protected function read()
180  {
181  global $ilDB;
182 
183  if($this->id)
184  {
185  $set = $ilDB->query('SELECT *'.
186  ' FROM booking_reservation'.
187  ' WHERE booking_reservation_id = '.$ilDB->quote($this->id, 'integer'));
188  $row = $ilDB->fetchAssoc($set);
189  $this->setUserId($row['user_id']);
190  $this->setObjectId($row['object_id']);
191  $this->setFrom($row['date_from']);
192  $this->setTo($row['date_to']);
193  $this->setStatus($row['status']);
194  $this->setGroupId($row['group_id']);
195  }
196  }
197 
202  function save()
203  {
204  global $ilDB;
205 
206  if($this->id)
207  {
208  return false;
209  }
210 
211  $this->id = $ilDB->nextId('booking_reservation');
212 
213  return $ilDB->manipulate('INSERT INTO booking_reservation'.
214  ' (booking_reservation_id,user_id,object_id,date_from,date_to,status,group_id)'.
215  ' VALUES ('.$ilDB->quote($this->id, 'integer').
216  ','.$ilDB->quote($this->getUserId(), 'integer').
217  ','.$ilDB->quote($this->getObjectId(), 'integer').
218  ','.$ilDB->quote($this->getFrom(), 'integer').
219  ','.$ilDB->quote($this->getTo(), 'integer').
220  ','.$ilDB->quote($this->getStatus(), 'integer').
221  ','.$ilDB->quote($this->getGroupId(), 'integer').')');
222  }
223 
228  function update()
229  {
230  global $ilDB;
231 
232  if(!$this->id)
233  {
234  return false;
235  }
236 
237  /* there can only be 1
238  if($this->getStatus() == self::STATUS_IN_USE)
239  {
240  $ilDB->manipulate('UPDATE booking_reservation'.
241  ' SET status = '.$ilDB->quote(NULL, 'integer').
242  ' WHERE object_id = '.$ilDB->quote($this->getObjectId(), 'integer').
243  ' AND status = '.$ilDB->quote(self::STATUS_IN_USE, 'integer'));
244  }
245  */
246 
247  return $ilDB->manipulate('UPDATE booking_reservation'.
248  ' SET object_id = '.$ilDB->quote($this->getObjectId(), 'text').
249  ', user_id = '.$ilDB->quote($this->getUserId(), 'integer').
250  ', date_from = '.$ilDB->quote($this->getFrom(), 'integer').
251  ', date_to = '.$ilDB->quote($this->getTo(), 'integer').
252  ', status = '.$ilDB->quote($this->getStatus(), 'integer').
253  ', group_id = '.$ilDB->quote($this->getGroupId(), 'integer').
254  ' WHERE booking_reservation_id = '.$ilDB->quote($this->id, 'integer'));
255  }
256 
261  function delete()
262  {
263  global $ilDB;
264 
265  if($this->id)
266  {
267  return $ilDB->manipulate('DELETE FROM booking_reservation'.
268  ' WHERE booking_reservation_id = '.$ilDB->quote($this->id, 'integer'));
269  }
270  }
271 
276  public static function getNewGroupId()
277  {
278  global $ilDB;
279 
280  return $ilDB->nextId('booking_reservation_group');
281  }
282 
291  static function getAvailableObject(array $a_ids, $a_from, $a_to, $a_return_single = true, $a_return_counter = false)
292  {
293  global $ilDB;
294 
295  $nr_map = ilBookingObject::getNrOfItemsForObjects($a_ids);
296 
297  $from = $ilDB->quote($a_from, 'integer');
298  $to = $ilDB->quote($a_to, 'integer');
299 
300  $set = $ilDB->query('SELECT count(*) cnt, object_id'.
301  ' FROM booking_reservation'.
302  ' WHERE '.$ilDB->in('object_id', $a_ids, '', 'integer').
303  ' AND (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').')'.
304  ' AND ((date_from <= '.$from.' AND date_to >= '.$from.')'.
305  ' OR (date_from <= '.$to.' AND date_to >= '.$to.')'.
306  ' OR (date_from >= '.$from.' AND date_to <= '.$to.'))'.
307  ' GROUP BY object_id');
308  $blocked = $counter = array();
309  while($row = $ilDB->fetchAssoc($set))
310  {
311  if($row['cnt'] >= $nr_map[$row['object_id']])
312  {
313  $blocked[] = $row['object_id'];
314  }
315  else if($a_return_counter)
316  {
317  $counter[$row['object_id']] = (int)$nr_map[$row['object_id']]-(int)$row['cnt'];
318  }
319  }
320  $available = array_diff($a_ids, $blocked);
321  if(sizeof($available))
322  {
323  if($a_return_counter)
324  {
325  foreach($a_ids as $id)
326  {
327  if(!isset($counter[$id]))
328  {
329  $counter[$id] = (int)$nr_map[$id];
330  }
331  }
332  return $counter;
333  }
334  else if($a_return_single)
335  {
336  return array_shift($available);
337  }
338  else
339  {
340  return $available;
341  }
342  }
343  }
344 
345  static function isObjectAvailableNoSchedule($a_obj_id)
346  {
347  global $ilDB;
348 
349  $all = ilBookingObject::getNrOfItemsForObjects(array($a_obj_id));
350  $all = (int)$all[$a_obj_id];
351 
352  $set = $ilDB->query('SELECT COUNT(*) cnt'.
353  ' FROM booking_reservation r'.
354  ' JOIN booking_object o ON (o.booking_object_id = r.object_id)'.
355  ' WHERE (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').')'.
356  ' AND r.object_id = '.$ilDB->quote($a_obj_id, 'integer'));
357  $cnt = $ilDB->fetchAssoc($set);
358  $cnt = (int)$cnt['cnt'];
359 
360  return (bool)($all-$cnt); // #11864
361  }
362 
368  static function getCurrentOrUpcomingReservation($a_object_id)
369  {
370  global $ilDB;
371 
372  $now = $ilDB->quote(time(), 'integer');
373 
374  $ilDB->setLimit(1);
375  $set = $ilDB->query('SELECT user_id, status, date_from, date_to'.
376  ' FROM booking_reservation'.
377  ' WHERE ((date_from <= '.$now.' AND date_to >= '.$now.')'.
378  ' OR date_from > '.$now.')'.
379  ' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').
380  ' OR STATUS IS NULL) AND object_id = '.$ilDB->quote($a_object_id, 'integer').
381  ' ORDER BY date_from');
382  $row = $ilDB->fetchAssoc($set);
383  return $row;
384  }
385 
386  static function getObjectReservationForUser($a_object_id, $a_user_id, $a_multi = false)
387  {
388  global $ilDB;
389 
390  $set = $ilDB->query('SELECT booking_reservation_id FROM booking_reservation'.
391  ' WHERE user_id = '.$ilDB->quote($a_user_id, 'integer').
392  ' AND object_id = '.$ilDB->quote($a_object_id, 'integer').
393  ' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').
394  ' OR STATUS IS NULL)');
395  if(!$a_multi)
396  {
397  $row = $ilDB->fetchAssoc($set);
398  return $row['booking_reservation_id'];
399  }
400  else
401  {
402  $res = array();
403  while($row = $ilDB->fetchAssoc($set))
404  {
405  $res[] = $row['booking_reservation_id'];
406  }
407  return $res;
408  }
409  }
410 
419  static function getList($a_object_ids, $a_limit = 10, $a_offset = 0, array $filter)
420  {
421  global $ilDB;
422 
423  $sql = 'SELECT r.*,o.title'.
424  ' FROM booking_reservation r'.
425  ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
426 
427  $count_sql = 'SELECT COUNT(*) AS counter'.
428  ' FROM booking_reservation r'.
429  ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
430 
431  $where = array($ilDB->in('r.object_id', $a_object_ids, '', 'integer'));
432  if($filter['status'])
433  {
434  if($filter['status'] > 0)
435  {
436  $where[] = 'status = '.$ilDB->quote($filter['status'], 'integer');
437  }
438  else
439  {
440  $where[] = '(status != '.$ilDB->quote(-$filter['status'], 'integer').
441  ' OR status IS NULL)';
442  }
443  }
444  if($filter['from'])
445  {
446  $where[] = 'date_from >= '.$ilDB->quote($filter['from'], 'integer');
447  }
448  if($filter['to'])
449  {
450  $where[] = 'date_to <= '.$ilDB->quote($filter['to'], 'integer');
451  }
452  if(sizeof($where))
453  {
454  $sql .= ' WHERE '.implode(' AND ', $where);
455  $count_sql .= ' WHERE '.implode(' AND ', $where);
456  }
457 
458  $set = $ilDB->query($count_sql);
459  $row = $ilDB->fetchAssoc($set);
460  $counter = $row['counter'];
461 
462  $sql .= ' ORDER BY date_from DESC, booking_reservation_id DESC';
463 
464  $ilDB->setLimit($a_limit, $a_offset);
465  $set = $ilDB->query($sql);
466  $res = array();
467  while($row = $ilDB->fetchAssoc($set))
468  {
469  $res[] = $row;
470  }
471 
472  return array('data'=>$res, 'counter'=>$counter);
473  }
474 
486  static function getListByDate($a_has_schedule, array $a_object_ids, $a_order_field, $a_order_direction, $a_offset, $a_limit, array $filter = null)
487  {
488  global $ilDB;
489 
490  $res = array();
491 
492  $sql = 'SELECT r.*, o.title'.
493  ' FROM booking_reservation r'.
494  ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
495 
496  $where = array($ilDB->in('object_id', $a_object_ids, '', 'integer'));
497  if($filter['status'])
498  {
499  if($filter['status'] > 0)
500  {
501  $where[] = 'status = '.$ilDB->quote($filter['status'], 'integer');
502  }
503  else
504  {
505  $where[] = '(status != '.$ilDB->quote(-$filter['status'], 'integer').
506  ' OR status IS NULL)';
507  }
508  }
509  if($a_has_schedule)
510  {
511  if($filter['from'])
512  {
513  $where[] = 'date_from >= '.$ilDB->quote($filter['from'], 'integer');
514  }
515  if($filter['to'])
516  {
517  $where[] = 'date_to <= '.$ilDB->quote($filter['to'], 'integer');
518  }
519  }
520  if($filter['user_id']) // #16584
521  {
522  $where[] = 'user_id = '.$ilDB->quote($filter['user_id'], 'integer');
523  }
524  /*
525  if($a_group_id)
526  {
527  $where[] = 'group_id = '.$ilDB->quote(substr($a_group_id, 1), 'integer');
528  }
529  */
530  if(sizeof($where))
531  {
532  $sql .= ' WHERE '.implode(' AND ', $where);
533  }
534 
535  if($a_has_schedule)
536  {
537  $sql .= ' ORDER BY date_from DESC';
538  }
539  else
540  {
541  // #16155 - could be cancelled and re-booked
542  $sql .= ' ORDER BY status';
543  }
544 
545  $set = $ilDB->query($sql);
546  while($row = $ilDB->fetchAssoc($set))
547  {
548  $obj_id = $row["object_id"];
549  $user_id = $row["user_id"];
550 
551  if($a_has_schedule)
552  {
553  $slot = $row["date_from"]."_".$row["date_to"];
554  $idx = $obj_id."_".$user_id."_".$slot;
555  }
556  else
557  {
558  $idx = $obj_id."_".$user_id;
559  }
560 
561  if($a_has_schedule && $filter["slot"])
562  {
563  $slot_idx = date("w", $row["date_from"])."_".date("H:i", $row["date_from"]).
564  "-".date("H:i", $row["date_to"]+1);
565  if($filter["slot"] != $slot_idx)
566  {
567  continue;
568  }
569  }
570 
571  if(!isset($res[$idx]))
572  {
574 
575  $res[$idx] = array(
576  "object_id" => $obj_id
577  ,"title" => $row["title"]
578  ,"user_id" => $user_id
579  ,"counter" => 1
580  ,"user_name" => $uname["lastname"].", ".$uname["firstname"] // #17862
581  );
582 
583  if($a_has_schedule)
584  {
585  $res[$idx]["booking_reservation_id"] = $idx;
586  $res[$idx]["date"] = date("Y-m-d", $row["date_from"]);
587  $res[$idx]["slot"] = date("H:i", $row["date_from"])." - ".
588  date("H:i", $row["date_to"]+1);
589  $res[$idx]["week"] = date("W", $row["date_from"]);
590  $res[$idx]["weekday"] = date("w", $row["date_from"]);
591  $res[$idx]["can_be_cancelled"] = ($row["status"] != self::STATUS_CANCELLED &&
592  $row["date_from"] > time());
593  $res[$idx]["_sortdate"] = $row["date_from"];
594  }
595  else
596  {
597  $res[$idx]["booking_reservation_id"] = $row["booking_reservation_id"];
598  $res[$idx]["status"] = $row["status"];
599  $res[$idx]["can_be_cancelled"] = ($row["status"] != self::STATUS_CANCELLED);
600  }
601  }
602  else
603  {
604  $res[$idx]["counter"]++;
605  }
606  }
607 
608  $size = sizeof($res);
609 
610  // order
611  $numeric = in_array($a_order_field, array("counter", "date", "week", "weekday"));
612 
613  // #16560 - this will enable matchting slot sorting to date/week
614  if($a_has_schedule &&
615  in_array($a_order_field, array("date", "week")))
616  {
617  $a_order_field = "_sortdate";
618  }
619 
620  $res = ilUtil::sortArray($res, $a_order_field, $a_order_direction, $numeric);
621 
622  // offset/limit
623  $res = array_splice($res, $a_offset, $a_limit);
624 
625  return array("data"=>$res, "counter"=>$size);
626  }
627 
634  public static function getUserFilter(array $a_object_ids)
635  {
636  global $ilDB;
637 
638  $res = array();
639 
640  $sql = "SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login".
641  " FROM usr_data ud ".
642  " LEFT JOIN booking_reservation r ON (r.user_id = ud.usr_id)".
643  " WHERE ud.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer").
644  " AND ".$ilDB->in("r.object_id", $a_object_ids, "", "integer").
645  " ORDER BY ud.lastname,ud.firstname";
646  $set = $ilDB->query($sql);
647  while($row = $ilDB->fetchAssoc($set))
648  {
649  $res[$row["usr_id"]] = $row["lastname"].", ".$row["firstname"].
650  " (".$row["login"].")";
651  }
652 
653  return $res;
654  }
655 
665  /*
666  static function getGroupedList($a_object_ids, $a_limit = 10, $a_offset = 0, array $filter = null, $a_group_id = null)
667  {
668  global $ilDB;
669 
670  // CURRENTLY UNUSED!!!
671  return;
672 
673  // find matching groups / reservations
674 
675  $sql = 'SELECT booking_reservation_id, group_id'.
676  ' FROM booking_reservation';
677 
678  $where = array($ilDB->in('object_id', $a_object_ids, '', 'integer'));
679  if($filter['status'])
680  {
681  if($filter['status'] > 0)
682  {
683  $where[] = 'status = '.$ilDB->quote($filter['status'], 'integer');
684  }
685  else
686  {
687  $where[] = '(status != '.$ilDB->quote(-$filter['status'], 'integer').
688  ' OR status IS NULL)';
689  }
690  }
691  if($filter['from'])
692  {
693  $where[] = 'date_from >= '.$ilDB->quote($filter['from'], 'integer');
694  }
695  if($filter['to'])
696  {
697  $where[] = 'date_to <= '.$ilDB->quote($filter['to'], 'integer');
698  }
699  if($filter['user_id'])
700  {
701  $where[] = 'user_id = '.$ilDB->quote($filter['user_id'], 'integer');
702  }
703  if($a_group_id)
704  {
705  $where[] = 'group_id = '.$ilDB->quote(substr($a_group_id, 1), 'integer');
706  }
707  if(sizeof($where))
708  {
709  $sql .= ' WHERE '.implode(' AND ', $where);
710  }
711 
712  $grp_ids = $rsv_ids = array();
713  $set = $ilDB->query($sql);
714  while($row = $ilDB->fetchAssoc($set))
715  {
716  if($row["group_id"])
717  {
718  $grp_ids[] = $row["group_id"];
719  }
720  else
721  {
722  $rsv_ids[] = $row["booking_reservation_id"];
723  }
724  }
725 
726  $res = array();
727 
728  // get complete groups (and/or reservations)
729 
730  if($grp_ids || $rsv_ids)
731  {
732  $grp_ids = array_unique($grp_ids);
733 
734  // if result is on last page, reduce limit to entries on last page
735  $max_page = sizeof($grp_ids)+sizeof($rsv_ids);
736  $max_page = min($a_limit, $max_page-$a_offset);
737 
738  $sql = 'SELECT r.*,o.title'.
739  ' FROM booking_reservation r'.
740  ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
741 
742  $where = array();
743  if($grp_ids)
744  {
745  $where[] = $ilDB->in('group_id', $grp_ids, '', 'integer');
746  }
747  if($rsv_ids)
748  {
749  $where[] = $ilDB->in('booking_reservation_id', $rsv_ids, '', 'integer');
750  }
751 
752  $sql .= ' WHERE ('.implode(' OR ', $where).')'.
753  ' ORDER BY date_from DESC, booking_reservation_id DESC';
754 
755  $set = $ilDB->query($sql);
756  $grps = array();
757  $counter = 0;
758  while($row = $ilDB->fetchAssoc($set))
759  {
760  if($row["group_id"] && !$a_group_id)
761  {
762  if(!isset($grps[$row["group_id"]]))
763  {
764  $grps[$row["group_id"]] = 1;
765  $counter++;
766  }
767  else
768  {
769  $grps[$row["group_id"]]++;
770  }
771  }
772  else
773  {
774  $counter++;
775  }
776 
777  if($a_group_id ||
778  ($counter > $a_offset &&
779  (sizeof($res) < $max_page ||
780  // if group is current page we have to get all group entries, regardless of booking period
781  ($row["group_id"] && isset($res["g".$row["group_id"]])))))
782  {
783  if($row["group_id"] && !$a_group_id)
784  {
785  $group_id = "g".$row["group_id"];
786  $res[$group_id]["group_id"] = $group_id;
787  $res[$group_id]["details"][] = $row;
788  }
789  else
790  {
791  unset($row["group_id"]);
792  $res[] = $row;
793  }
794  }
795  }
796  }
797 
798  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
799 
800  foreach($res as $idx => $item)
801  {
802  if(isset($item["details"]))
803  {
804  $res[$idx]["date_from"] = null;
805  $res[$idx]["date_to"] = null;
806 
807  $weekdays = $week_counter = array();
808  $recur = $last = 0;
809 
810  foreach($item["details"] as $detail)
811  {
812  // same for each item
813  $res[$idx]["user_id"] = $detail["user_id"];
814  $res[$idx]["object_id"] = $detail["object_id"];
815  $res[$idx]["title"] = $detail["title"];
816  $res[$idx]["booking_reservation_id"] = $detail["booking_reservation_id"];
817 
818  // recurrence/weekdays
819  $sortkey = date("wHi", $detail["date_from"])."_".date("wHi", $detail["date_to"]);
820  $weekdays[$sortkey] = ilCalendarUtil::_numericDayToString(date("w", $detail["date_from"]), false).
821  ", ".date("H:i", $detail["date_from"]).
822  " - ".date("H:i", $detail["date_to"]);
823 
824  if($detail["status"] != self::STATUS_CANCELLED)
825  {
826  $week_counter[$sortkey][date("WHi", $detail["date_from"])."_".date("WHi", $detail["date_to"])]++;
827  }
828  else if(!isset($week_counter[$sortkey][date("WHi", $detail["date_from"])."_".date("WHi", $detail["date_to"])]))
829  {
830  $week_counter[$sortkey][date("WHi", $detail["date_from"])."_".date("WHi", $detail["date_to"])] = 0;
831  }
832 
833  if($last && $last-$detail["date_to"] > $recur)
834  {
835  $recur = $last-$detail["date_to"];
836  }
837 
838  // min/max period
839  if(!$res[$idx]["date_from"] || $detail["date_from"] < $res[$idx]["date_from"])
840  {
841  $res[$idx]["date_from"] = $detail["date_from"];
842  }
843  if(!$res[$idx]["date_to"] || $detail["date_to"] > $res[$idx]["date_to"])
844  {
845  $res[$idx]["date_to"] = $detail["date_to"];
846  }
847 
848  $last = $detail["date_to"];
849  }
850 
851  if(sizeof($item["details"]) > 1)
852  {
853  $weekdays = array_unique($weekdays);
854  ksort($weekdays);
855 
856  foreach($weekdays as $week_id => $weekday)
857  {
858  $min = min($week_counter[$week_id]);
859  $max = max($week_counter[$week_id]);
860  if($min == $max)
861  {
862  $weekdays[$week_id] .= " (".$min.")";
863  }
864  else
865  {
866  $weekdays[$week_id] .= " (".$min."-".$max.")";
867  }
868  }
869 
870 
871  $res[$idx]["weekdays"] = array_values($weekdays);
872  if($recur)
873  {
874  if(date("YW", $res[$idx]["date_to"]) != date("YW", $res[$idx]["date_from"]))
875  {
876  $recur = ceil(($recur/(60*60*24))/7);
877  }
878  else
879  {
880  $recur = 0;
881  }
882  }
883  $res[$idx]["recurrence"] = (int)$recur;
884 
885  $res[$idx]["booking_reservation_id"] = $idx;
886  $res[$idx]["title"] .= " (".sizeof($item["details"]).")";
887 
888  }
889  else
890  {
891  // undo grouping
892  $res[$idx] = array_pop($item["details"]);
893  unset($res[$idx]["group_id"]);
894  }
895  }
896  }
897 
898  $res = ilUtil::sortArray($res, "date_from", "desc", true);
899 
900  return array('data'=>$res, 'counter'=>$counter);
901  }
902  */
903 
910  static function changeStatus(array $a_ids, $a_status)
911  {
912  global $ilDB;
913 
914  if(self::isValidStatus($a_status))
915  {
916  return $ilDB->manipulate('UPDATE booking_reservation'.
917  ' SET status = '.$ilDB->quote($a_status, 'integer').
918  ' WHERE '.$ilDB->in('booking_reservation_id', $a_ids, '', 'integer'));
919 
920  }
921  }
922 
923  function getCalendarEntry()
924  {
925  global $ilDB;
926 
927  include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
928 
929  $set = $ilDB->query("SELECT ce.cal_id FROM cal_entries ce".
930  " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id".
931  " JOIN cal_categories cc ON cca.cat_id = cc.cat_id".
932  " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id".
933  " WHERE cc.obj_id = ".$ilDB->quote($this->getUserId(),'integer').
934  " AND br.user_id = ".$ilDB->quote($this->getUserId(),'integer').
935  " AND cc.type = ".$ilDB->quote(ilCalendarCategory::TYPE_BOOK,'integer').
936  " AND ce.context_id = ".$ilDB->quote($this->getId(), 'integer'));
937  $row = $ilDB->fetchAssoc($set);
938  return $row["cal_id"];
939  }
940 
950  public static function getCancelDetails($a_obj_id, $a_user_id, $a_from, $a_to)
951  {
952  global $ilDB;
953 
954  $res = array();
955 
956  $sql = "SELECT booking_reservation_id".
957  " FROM booking_reservation".
958  " WHERE object_id = ".$ilDB->quote($a_obj_id, "integer").
959  " AND user_id = ".$ilDB->quote($a_user_id, "integer").
960  " AND date_from = ".$ilDB->quote($a_from, "integer").
961  " AND date_to = ".$ilDB->quote($a_to, "integer").
962  " AND (status IS NULL".
963  " OR status <> ".$ilDB->quote(self::STATUS_CANCELLED, "integer").")";
964  $set = $ilDB->query($sql);
965  while($row = $ilDB->fetchAssoc($set))
966  {
967  $res[] = $row["booking_reservation_id"];
968  }
969 
970  return $res;
971  }
972 }
973 
974 ?>