ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.FlashcardTermDBRepository.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 namespace ILIAS\Glossary\Flashcard;
22 
27 {
28  protected \ilDBInterface $db;
29 
30  public function __construct(
31  \ilDBInterface $db
32  ) {
33  $this->db = $db;
34  }
35 
36  public function getUserEntriesForBox(
37  int $box_nr,
38  int $user_id,
39  int $glo_id
40  ): array {
41  $set = $this->db->queryF(
42  "SELECT * FROM glo_flashcard_term " .
43  " WHERE box_nr = %s AND user_id = %s AND glo_id = %s " .
44  " ORDER BY last_access ASC ",
45  ["integer", "integer", "integer"],
46  [$box_nr, $user_id, $glo_id]
47  );
48 
49  $entries = [];
50  while ($rec = $this->db->fetchAssoc($set)) {
51  $entries[] = [
52  "term_id" => $rec["term_id"],
53  "user_id" => $rec["user_id"],
54  "glo_id" => $rec["glo_id"],
55  "last_access" => $rec["last_access"],
56  "box_nr" => $rec["box_nr"]
57  ];
58  }
59 
60  return $entries;
61  }
62 
63  public function getAllUserEntries(
64  int $user_id,
65  int $glo_id
66  ): array {
67  $set = $this->db->queryF(
68  "SELECT * FROM glo_flashcard_term " .
69  " WHERE user_id = %s AND glo_id = %s " .
70  " ORDER BY last_access ASC ",
71  ["integer", "integer"],
72  [$user_id, $glo_id]
73  );
74 
75  $entries = [];
76  while ($rec = $this->db->fetchAssoc($set)) {
77  $entries[] = [
78  "term_id" => $rec["term_id"],
79  "user_id" => $rec["user_id"],
80  "glo_id" => $rec["glo_id"],
81  "last_access" => $rec["last_access"],
82  "box_nr" => $rec["box_nr"]
83  ];
84  }
85 
86  return $entries;
87  }
88 
89  public function getBoxNr(
90  int $term_id,
91  int $user_id,
92  int $glo_id
93  ): int {
94  $set = $this->db->queryF(
95  "SELECT box_nr FROM glo_flashcard_term " .
96  " WHERE term_id = %s AND user_id = %s AND glo_id = %s ",
97  ["integer", "integer", "integer"],
98  [$term_id, $user_id, $glo_id]
99  );
100 
101  if ($rec = $this->db->fetchAssoc($set)) {
102  return (int) $rec["box_nr"];
103  }
104 
105  return 0;
106  }
107 
108  public function createEntry(
109  int $term_id,
110  int $user_id,
111  int $glo_id,
112  int $box_nr,
113  string $date
114  ): void {
115  $this->db->insert("glo_flashcard_term", [
116  "term_id" => ["integer", $term_id],
117  "user_id" => ["integer", $user_id],
118  "glo_id" => ["integer", $glo_id],
119  "last_access" => ["date", $date],
120  "box_nr" => ["integer", $box_nr]
121  ]);
122  }
123 
124  public function updateEntry(
125  int $term_id,
126  int $user_id,
127  int $glo_id,
128  int $box_nr,
129  string $date
130  ): void {
131  $this->db->update("glo_flashcard_term", [
132  "last_access" => ["date", $date],
133  "box_nr" => ["integer", $box_nr]
134  ], [
135  "term_id" => ["integer", $term_id],
136  "user_id" => ["integer", $user_id],
137  "glo_id" => ["integer", $glo_id]
138  ]);
139  }
140 
141  public function deleteEntries(
142  int $glo_id,
143  int $user_id
144  ): void {
145  $q = "DELETE FROM glo_flashcard_term " .
146  " WHERE glo_id = " . $this->db->quote($glo_id, "integer") .
147  " AND user_id = " . $this->db->quote($user_id, "integer");
148  $this->db->manipulate($q);
149  }
150 
151  public function deleteAllUserEntries(
152  int $user_id
153  ): void {
154  $q = "DELETE FROM glo_flashcard_term " .
155  " WHERE user_id = " . $this->db->quote($user_id, "integer");
156  $this->db->manipulate($q);
157  }
158 
159  public function deleteAllGlossaryEntries(
160  int $glo_id
161  ): void {
162  $q = "DELETE FROM glo_flashcard_term " .
163  " WHERE glo_id = " . $this->db->quote($glo_id, "integer");
164  $this->db->manipulate($q);
165  }
166 
167  public function deleteAllTermEntries(
168  int $term_id
169  ): void {
170  $q = "DELETE FROM glo_flashcard_term " .
171  " WHERE term_id = " . $this->db->quote($term_id, "integer");
172  $this->db->manipulate($q);
173  }
174 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateEntry(int $term_id, int $user_id, int $glo_id, int $box_nr, string $date)
$q
Definition: shib_logout.php:21
createEntry(int $term_id, int $user_id, int $glo_id, int $box_nr, string $date)