ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.SelectedObjectsDBRepository.php
Go to the documentation of this file.
1 <?php
2 
20 
25 {
26  protected \ilDBInterface $db;
27 
28  public function __construct(
29  \ilDBInterface $db
30  ) {
31  $this->db = $db;
32  }
33 
34  public function getSelectedObjects(int $pool_id, int $user_id): array
35  {
36  $db = $this->db;
37  $set = $db->queryF(
38  "SELECT * FROM book_sel_object " .
39  " WHERE user_id = %s " .
40  " AND pool_id = %s ",
41  ["integer", "integer"],
42  [$user_id, $pool_id]
43  );
44  $obj_ids = [];
45  while ($rec = $db->fetchAssoc($set)) {
46  $obj_ids[] = (int) $rec["object_id"];
47  }
48  return $obj_ids;
49  }
50 
51  public function setSelectedObjects(int $pool_id, int $user_id, array $obj_ids): void
52  {
53  $db = $this->db;
54  $this->deleteSelectedObjects($pool_id, $user_id);
55  foreach ($obj_ids as $obj_id) {
56  $db->insert("book_sel_object", [
57  "user_id" => ["integer", $user_id],
58  "pool_id" => ["integer", $pool_id],
59  "object_id" => ["integer", $obj_id]
60  ]);
61  }
62  }
63 
64  protected function deleteSelectedObjects(int $pool_id, int $user_id): void
65  {
66  $db = $this->db;
67  $db->manipulateF(
68  "DELETE FROM book_sel_object WHERE " .
69  " user_id = %s" .
70  " AND pool_id = %s",
71  ["integer", "integer"],
72  [$user_id, $pool_id]
73  );
74  }
75 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
manipulateF(string $query, array $types, array $values)
queryF(string $query, array $types, array $values)