ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBookingPreferencesDBRepository.php
Go to the documentation of this file.
1<?php
2
24{
25 protected ilDBInterface $db;
27
28 public function __construct(
29 ILIAS\BookingManager\InternalDataService $data,
30 ?ilDBInterface $db = null
31 ) {
32 global $DIC;
33
34 $this->db = ($db)
35 ?: $DIC->database();
36 $this->data = $data;
37 }
38
42 public function getPreferences(int $a_pool_id): ilBookingPreferences
43 {
44 $db = $this->db;
45
46 $set = $db->queryF(
47 "SELECT * FROM booking_preferences " .
48 " WHERE book_pool_id = %s ",
49 array("integer"),
50 array($a_pool_id)
51 );
52 $preferences = [];
53 while ($rec = $db->fetchAssoc($set)) {
54 if (!isset($preferences[$rec["user_id"]]) || !in_array($rec["book_obj_id"], $preferences[$rec["user_id"]], true)) {
55 $preferences[$rec["user_id"]][] = $rec["book_obj_id"];
56 }
57 }
58 return $this->data->preferences($preferences);
59 }
60
64 public function getPreferencesOfUser(
65 int $a_pool_id,
66 int $a_user_id
68 $db = $this->db;
69
70 $set = $db->queryF(
71 "SELECT * FROM booking_preferences " .
72 " WHERE book_pool_id = %s " .
73 " AND user_id = %s ",
74 array("integer", "integer"),
75 array($a_pool_id, $a_user_id)
76 );
77 $preferences = [];
78 while ($rec = $db->fetchAssoc($set)) {
79 if (!isset($preferences[$rec["user_id"]]) || !in_array($rec["book_obj_id"], $preferences[$rec["user_id"]], true)) {
80 $preferences[$rec["user_id"]][] = $rec["book_obj_id"];
81 }
82 }
83 return $this->data->preferences($preferences);
84 }
85
89 public function savePreferences(
90 int $a_pool_id,
91 ilBookingPreferences $preferences
92 ): void {
93 $db = $this->db;
94
95 $db->manipulateF(
96 "DELETE FROM booking_preferences WHERE " .
97 " book_pool_id = %s",
98 array("integer"),
99 array($a_pool_id)
100 );
101
102 foreach ($preferences as $user_id => $obj_ids) {
103 if (is_array($obj_ids) && $user_id > 0) {
104 foreach ($obj_ids as $obj_id) {
105 $db->insert("booking_preferences", array(
106 "book_pool_id" => array("integer", $a_pool_id),
107 "user_id" => array("integer", $user_id),
108 "book_obj_id" => array("integer", $obj_id),
109 ));
110 }
111 }
112 }
113 }
114
118 public function savePreferencesOfUser(
119 int $a_pool_id,
120 int $a_user_id,
121 ilBookingPreferences $preferences
122 ): void {
123 $db = $this->db;
124
125 $db->manipulateF(
126 "DELETE FROM booking_preferences WHERE " .
127 " book_pool_id = %s" .
128 " AND user_id = %s",
129 array("integer","integer"),
130 array($a_pool_id, $a_user_id)
131 );
132
133 foreach ($preferences->getPreferences() as $user_id => $obj_ids) {
134 if (is_array($obj_ids) && $user_id === $a_user_id) {
135 foreach ($obj_ids as $obj_id) {
136 $db->insert("booking_preferences", array(
137 "book_pool_id" => array("integer", $a_pool_id),
138 "user_id" => array("integer", $user_id),
139 "book_obj_id" => array("integer", $obj_id),
140 ));
141 }
142 }
143 }
144 }
145}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS BookingManager InternalDataService $data
savePreferencesOfUser(int $a_pool_id, int $a_user_id, ilBookingPreferences $preferences)
Save all preferences of a user for a pool.
savePreferences(int $a_pool_id, ilBookingPreferences $preferences)
Save all preferences of a pool.
getPreferences(int $a_pool_id)
Get booking preferences for a pool id.
__construct(ILIAS\BookingManager\InternalDataService $data, ?ilDBInterface $db=null)
getPreferencesOfUser(int $a_pool_id, int $a_user_id)
Get booking preferences for a pool id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPreferences()
Get user preferences.
Interface ilDBInterface.
insert(string $table_name, array $values)
manipulateF(string $query, array $types, array $values)
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26