ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilBookingPreferencesDBRepository 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 ilBookingPreferencesDBRepository:

Public Member Functions

 __construct (ILIAS\BookingManager\InternalDataService $data, ?ilDBInterface $db=null)
 
 getPreferences (int $a_pool_id)
 Get booking preferences for a pool id. More...
 
 getPreferencesOfUser (int $a_pool_id, int $a_user_id)
 Get booking preferences for a pool id. More...
 
 savePreferences (int $a_pool_id, ilBookingPreferences $preferences)
 Save all preferences of a pool. More...
 
 savePreferencesOfUser (int $a_pool_id, int $a_user_id, ilBookingPreferences $preferences)
 Save all preferences of a user for a pool. More...
 

Protected Attributes

ilDBInterface $db
 
ILIAS BookingManager InternalDataService $data
 

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 Booking preferences repo

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

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

Constructor & Destructor Documentation

◆ __construct()

ilBookingPreferencesDBRepository::__construct ( ILIAS\BookingManager\InternalDataService  $data,
?ilDBInterface  $db = null 
)

Definition at line 28 of file class.ilBookingPreferencesDBRepository.php.

References $data, $db, and $DIC.

31  {
32  global $DIC;
33 
34  $this->db = ($db)
35  ?: $DIC->database();
36  $this->data = $data;
37  }
global $DIC
Definition: shib_login.php:22
ILIAS BookingManager InternalDataService $data

Member Function Documentation

◆ getPreferences()

ilBookingPreferencesDBRepository::getPreferences ( int  $a_pool_id)

Get booking preferences for a pool id.

Definition at line 42 of file class.ilBookingPreferencesDBRepository.php.

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

Referenced by ilBookingPreferencesGUI\listBookingResults().

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  }
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPreferencesOfUser()

ilBookingPreferencesDBRepository::getPreferencesOfUser ( int  $a_pool_id,
int  $a_user_id 
)

Get booking preferences for a pool id.

Definition at line 64 of file class.ilBookingPreferencesDBRepository.php.

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

Referenced by ilBookingPreferencesGUI\initPreferenceForm(), and ilBookingPreferencesGUI\listBookingResults().

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  }
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ savePreferences()

ilBookingPreferencesDBRepository::savePreferences ( int  $a_pool_id,
ilBookingPreferences  $preferences 
)

Save all preferences of a pool.

Definition at line 89 of file class.ilBookingPreferencesDBRepository.php.

References $db, $user_id, ilDBInterface\insert(), and ilDBInterface\manipulateF().

92  : void {
93  $db = $this->db;
94 
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  }
insert(string $table_name, array $values)
manipulateF(string $query, array $types, array $values)
+ Here is the call graph for this function:

◆ savePreferencesOfUser()

ilBookingPreferencesDBRepository::savePreferencesOfUser ( int  $a_pool_id,
int  $a_user_id,
ilBookingPreferences  $preferences 
)

Save all preferences of a user for a pool.

Definition at line 118 of file class.ilBookingPreferencesDBRepository.php.

References $db, $user_id, ilBookingPreferences\getPreferences(), ilDBInterface\insert(), and ilDBInterface\manipulateF().

Referenced by ilBookingPreferencesGUI\savePreferences().

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  }
insert(string $table_name, array $values)
manipulateF(string $query, array $types, array $values)
getPreferences()
Get user preferences.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $data

ILIAS BookingManager InternalDataService ilBookingPreferencesDBRepository::$data
protected

Definition at line 26 of file class.ilBookingPreferencesDBRepository.php.

Referenced by __construct().

◆ $db

ilDBInterface ilBookingPreferencesDBRepository::$db
protected

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