ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilBookingPrefBasedBookGatewayRepository Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilBookingPrefBasedBookGatewayRepository:

Public Member Functions

 __construct (?ilDBInterface $db=null)
 
 getPoolsWithOverdueBooking ()
 Get pools with overdue preference booking. More...
 
 hasRun ($pool_id)
 
 resetRun ($pool_id)
 
 storeBookings (int $pool_id, array $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)
 

Protected Member Functions

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

Protected Attributes

ilDBInterface $db
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Manages the booking storage of the preference based calculated bookings

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

Definition at line 23 of file class.ilBookingPrefBasedBookGatewayRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookingPrefBasedBookGatewayRepository::__construct ( ?ilDBInterface  $db = null)

Definition at line 27 of file class.ilBookingPrefBasedBookGatewayRepository.php.

28 {
29 global $DIC;
30
31 $this->db = ($db)
32 ?: $DIC->database();
33 }
global $DIC
Definition: shib_login.php:26

References $db, and $DIC.

Member Function Documentation

◆ checkProcessHash()

ilBookingPrefBasedBookGatewayRepository::checkProcessHash ( int  $pool_id)
protected

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

Definition at line 63 of file class.ilBookingPrefBasedBookGatewayRepository.php.

63 : bool
64 {
65 $db = $this->db;
66
67 $hash = uniqid("", true);
68
69 $db->update("booking_settings", array(
70 "pref_booking_hash" => array("text", $hash)
71 ), array( // where
72 "booking_pool_id" => array("integer", $pool_id),
73 "pref_booking_hash" => array("text", "0"),
74 ));
75
76 $set = $db->queryF(
77 "SELECT pref_booking_hash FROM booking_settings " .
78 " WHERE booking_pool_id = %s ",
79 array("integer"),
80 array($pool_id)
81 );
82 $rec = $db->fetchAssoc($set);
83
84 return $rec["pref_booking_hash"] === $hash;
85 }
update(string $table_name, array $values, array $where)
@description $where MUST contain existing columns only.
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)

References $db, ilDBInterface\fetchAssoc(), ilDBInterface\queryF(), and ilDBInterface\update().

+ Here is the call graph for this function:

◆ getBookings()

ilBookingPrefBasedBookGatewayRepository::getBookings ( array  $obj_ids)

Definition at line 142 of file class.ilBookingPrefBasedBookGatewayRepository.php.

144 : array {
145 $bookings = [];
147 $obj_ids,
148 10000,
149 0,
151 )["data"] as $book) {
152 $bookings[$book["user_id"]][] = $book["object_id"];
153 }
154 return $bookings;
155 }
static getList(array $a_object_ids, int $a_limit=10, int $a_offset=0, array $filter=[])
List all reservations.

◆ getPoolsWithOverdueBooking()

ilBookingPrefBasedBookGatewayRepository::getPoolsWithOverdueBooking ( )

Get pools with overdue preference booking.

Returns
int[]

Definition at line 39 of file class.ilBookingPrefBasedBookGatewayRepository.php.

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

References $db, ilDBInterface\fetchAssoc(), ilDBInterface\queryF(), and ilObjBookingPool\TYPE_NO_SCHEDULE_PREFERENCES.

+ Here is the call graph for this function:

◆ hasRun()

ilBookingPrefBasedBookGatewayRepository::hasRun (   $pool_id)

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

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 }

References $db, ilDBInterface\fetchAssoc(), and ilDBInterface\queryF().

+ Here is the call graph for this function:

◆ resetRun()

ilBookingPrefBasedBookGatewayRepository::resetRun (   $pool_id)

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

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 }

References $db, and ilDBInterface\update().

+ Here is the call graph for this function:

◆ storeBookings()

ilBookingPrefBasedBookGatewayRepository::storeBookings ( int  $pool_id,
array  $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 120 of file class.ilBookingPrefBasedBookGatewayRepository.php.

123 : void {
124 if ($this->checkProcessHash($pool_id)) {
125 foreach ($bookings as $user_id => $obj_ids) {
126 foreach ($obj_ids as $obj_id) {
128 count(ilBookingReservation::getObjectReservationForUser($obj_id, $user_id)) === 0) { // #18304
129 $reservation = new ilBookingReservation();
130 $reservation->setObjectId($obj_id);
131 $reservation->setUserId($user_id);
132 $reservation->setAssignerId($user_id);
133 $reservation->setFrom(0);
134 $reservation->setTo(0);
135 $reservation->save();
136 }
137 }
138 }
139 }
140 }
checkProcessHash(int $pool_id)
Semaphore like hash setting/checking to ensure that no other process is doing the same.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getObjectReservationForUser(int $a_object_id, int $a_user_id)
static isObjectAvailableNoSchedule(int $a_obj_id)

References $user_id, ilBookingReservation\getObjectReservationForUser(), and ilBookingReservation\isObjectAvailableNoSchedule().

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilBookingPrefBasedBookGatewayRepository::$db
protected

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