ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilBookingPrefBasedBookGatewayRepository Class Reference

Manages the booking storage of the preference based calculated bookings. More...

+ Collaboration diagram for ilBookingPrefBasedBookGatewayRepository:

Public Member Functions

 __construct (ilDBInterface $db=null)
 Constructor. More...
 
 getPoolsWithOverdueBooking ()
 Get pools with overdue preference booking. More...
 
 hasRun ($pool_id)
 
 resetRun ($pool_id)
 
 storeBookings (int $pool_id, $bookings)
 Store bookings see similar code in ilObjBookingPoolGUI::confirmedBookingObject this should got to a reservation repo/manager in the future. More...
 
 getBookings (array $obj_ids)
 Get bookings. More...
 

Protected Member Functions

 checkProcessHash ($pool_id)
 Semaphore like hash setting/checking to ensure that no other process is doing the same. More...
 

Protected Attributes

 $db
 

Detailed Description

Manages the booking storage of the preference based calculated bookings.

Author
killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 10 of file class.ilBookingPrefBaseBookGatewayRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookingPrefBasedBookGatewayRepository::__construct ( ilDBInterface  $db = null)

Constructor.

Definition at line 20 of file class.ilBookingPrefBaseBookGatewayRepository.php.

References $db, and $DIC.

21  {
22  global $DIC;
23 
24  $this->db = ($db)
25  ? $db
26  : $DIC->database();
27  }
global $DIC
Definition: goto.php:24

Member Function Documentation

◆ checkProcessHash()

ilBookingPrefBasedBookGatewayRepository::checkProcessHash (   $pool_id)
protected

Semaphore like hash setting/checking to ensure that no other process is doing the same.

Returns
bool

Definition at line 60 of file class.ilBookingPrefBaseBookGatewayRepository.php.

References $db.

Referenced by storeBookings().

61  {
62  $db = $this->db;
63 
64  $hash = uniqid("", true);
65 
66  $db->update("booking_settings", array(
67  "pref_booking_hash" => array("text", $hash)
68  ), array( // where
69  "booking_pool_id" => array("integer", $pool_id),
70  "pref_booking_hash" => array("text", "0"),
71  ));
72 
73  $set = $db->queryF(
74  "SELECT pref_booking_hash FROM booking_settings " .
75  " WHERE booking_pool_id = %s ",
76  array("integer"),
77  array($pool_id)
78  );
79  $rec = $db->fetchAssoc($set);
80 
81  if ($rec["pref_booking_hash"] == $hash) {
82  return true;
83  }
84  return false;
85  }
+ Here is the caller graph for this function:

◆ getBookings()

ilBookingPrefBasedBookGatewayRepository::getBookings ( array  $obj_ids)

Get bookings.

Parameters
array$obj_ids
Returns
array

Definition at line 147 of file class.ilBookingPrefBaseBookGatewayRepository.php.

References ilBookingReservation\getList(), and ilBookingReservation\STATUS_CANCELLED.

148  {
149  $bookings = [];
151  $obj_ids,
152  10000,
153  0,
155  )["data"] as $book) {
156  $bookings[$book["user_id"]][] = $book["object_id"];
157  }
158  return $bookings;
159  }
static getList($a_object_ids, $a_limit=10, $a_offset=0, array $filter=[])
List all reservations.
+ Here is the call graph for this function:

◆ getPoolsWithOverdueBooking()

ilBookingPrefBasedBookGatewayRepository::getPoolsWithOverdueBooking ( )

Get pools with overdue preference booking.

Returns
int[]

Definition at line 34 of file class.ilBookingPrefBaseBookGatewayRepository.php.

References $db, and ilObjBookingPool\TYPE_NO_SCHEDULE_PREFERENCES.

35  {
36  $db = $this->db;
37 
38  $pool_ids = [];
39  $set = $db->queryF(
40  "SELECT booking_pool_id FROM booking_settings " .
41  " WHERE schedule_type = %s " .
42  " AND pref_deadline < %s " .
43  " AND pref_booking_hash = %s ",
44  array("integer", "integer", "text"),
46  );
47  while ($rec = $db->fetchAssoc($set)) {
48  $pool_ids[] = $rec["booking_pool_id"];
49  }
50  return $pool_ids;
51  }

◆ hasRun()

ilBookingPrefBasedBookGatewayRepository::hasRun (   $pool_id)

Definition at line 87 of file class.ilBookingPrefBaseBookGatewayRepository.php.

References $db.

87  : bool
88  {
89  $db = $this->db;
90  $set = $db->queryF(
91  "SELECT pref_booking_hash FROM booking_settings " .
92  " WHERE booking_pool_id = %s ",
93  array("integer"),
94  array($pool_id)
95  );
96  $rec = $db->fetchAssoc($set);
97 
98  if ($rec["pref_booking_hash"] !== "0") {
99  return true;
100  }
101  return false;
102  }

◆ resetRun()

ilBookingPrefBasedBookGatewayRepository::resetRun (   $pool_id)

Definition at line 104 of file class.ilBookingPrefBaseBookGatewayRepository.php.

References $db.

104  : void
105  {
106  $db = $this->db;
107  $db->update("booking_settings", array(
108  "pref_booking_hash" => array("text", "0")
109  ), array( // where
110  "booking_pool_id" => array("integer", $pool_id)
111  ));
112  }

◆ storeBookings()

ilBookingPrefBasedBookGatewayRepository::storeBookings ( int  $pool_id,
  $bookings 
)

Store bookings see similar code in ilObjBookingPoolGUI::confirmedBookingObject this should got to a reservation repo/manager in the future.

Parameters
int[][]$bookings

Definition at line 121 of file class.ilBookingPrefBaseBookGatewayRepository.php.

References checkProcessHash(), ilBookingReservation\getObjectReservationForUser(), and ilBookingReservation\isObjectAvailableNoSchedule().

122  {
123  if ($this->checkProcessHash($pool_id)) {
124  foreach ($bookings as $user_id => $obj_ids) {
125  foreach ($obj_ids as $obj_id) {
127  !ilBookingReservation::getObjectReservationForUser($obj_id, $user_id)) { // #18304
128  $reservation = new ilBookingReservation();
129  $reservation->setObjectId($obj_id);
130  $reservation->setUserId($user_id);
131  $reservation->setAssignerId($user_id);
132  $reservation->setFrom(null);
133  $reservation->setTo(null);
134  $reservation->save();
135  }
136  }
137  }
138  }
139  }
static isObjectAvailableNoSchedule($a_obj_id)
checkProcessHash($pool_id)
Semaphore like hash setting/checking to ensure that no other process is doing the same...
static getObjectReservationForUser($a_object_id, $a_user_id, $a_multi=false)
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilBookingPrefBasedBookGatewayRepository::$db
protected

The documentation for this class was generated from the following file: