ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.FlashcardTermDBRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
29{
30 public function __construct(
31 protected \ilDBInterface $db,
32 protected InternalDataService $data_service
33 ) {
34 }
35
36 protected function getFromRecord(array $rec): Term
37 {
38 return $this->data_service->flashcardTerm(
39 (int) $rec["term_id"],
40 (int) $rec["user_id"],
41 (int) $rec["glo_id"],
42 (int) $rec["box_nr"],
43 $rec["last_access"]
44 );
45 }
46
47 public function getEntry(
48 int $term_id,
49 int $user_id,
50 int $glo_id
51 ): ?Term {
52 $set = $this->db->queryF(
53 "SELECT * FROM glo_flashcard_term " .
54 " WHERE term_id = %s AND user_id = %s AND glo_id = %s ",
55 ["integer", "integer", "integer"],
56 [$term_id, $user_id, $glo_id]
57 );
58
59 if ($rec = $this->db->fetchAssoc($set)) {
60 return $this->getFromRecord($rec);
61 }
62
63 return null;
64 }
65
69 public function getUserEntriesForBox(
70 int $box_nr,
71 int $user_id,
72 int $glo_id
73 ): array {
74 $set = $this->db->queryF(
75 "SELECT * FROM glo_flashcard_term " .
76 " WHERE box_nr = %s AND user_id = %s AND glo_id = %s " .
77 " ORDER BY last_access ASC ",
78 ["integer", "integer", "integer"],
79 [$box_nr, $user_id, $glo_id]
80 );
81
82 $entries = [];
83 while ($rec = $this->db->fetchAssoc($set)) {
84 $entries[] = $this->getFromRecord($rec);
85 }
86
87 return $entries;
88 }
89
93 public function getAllUserEntries(
94 int $user_id,
95 int $glo_id
96 ): array {
97 $set = $this->db->queryF(
98 "SELECT * FROM glo_flashcard_term " .
99 " WHERE user_id = %s AND glo_id = %s " .
100 " ORDER BY last_access ASC ",
101 ["integer", "integer"],
102 [$user_id, $glo_id]
103 );
104
105 $entries = [];
106 while ($rec = $this->db->fetchAssoc($set)) {
107 $entries[] = $this->getFromRecord($rec);
108 }
109
110 return $entries;
111 }
112
113 public function createEntry(
114 Term $term
115 ): void {
116 $this->db->insert("glo_flashcard_term", [
117 "term_id" => ["integer", $term->getTermId()],
118 "user_id" => ["integer", $term->getUserId()],
119 "glo_id" => ["integer", $term->getGloId()],
120 "last_access" => ["date", $term->getLastAccess()],
121 "box_nr" => ["integer", $term->getBoxNr()]
122 ]);
123 }
124
125 public function updateEntry(
126 Term $term
127 ): void {
128 $this->db->update("glo_flashcard_term", [
129 "last_access" => ["date", $term->getLastAccess()],
130 "box_nr" => ["integer", $term->getBoxNr()]
131 ], [
132 "term_id" => ["integer", $term->getTermId()],
133 "user_id" => ["integer", $term->getUserId()],
134 "glo_id" => ["integer", $term->getGloId()]
135 ]);
136 }
137
138 public function deleteEntries(
139 int $glo_id,
140 int $user_id
141 ): void {
142 $q = "DELETE FROM glo_flashcard_term " .
143 " WHERE glo_id = " . $this->db->quote($glo_id, "integer") .
144 " AND user_id = " . $this->db->quote($user_id, "integer");
145 $this->db->manipulate($q);
146 }
147
148 public function deleteAllUserEntries(
149 int $user_id
150 ): void {
151 $q = "DELETE FROM glo_flashcard_term " .
152 " WHERE user_id = " . $this->db->quote($user_id, "integer");
153 $this->db->manipulate($q);
154 }
155
157 int $glo_id
158 ): void {
159 $q = "DELETE FROM glo_flashcard_term " .
160 " WHERE glo_id = " . $this->db->quote($glo_id, "integer");
161 $this->db->manipulate($q);
162 }
163
164 public function deleteAllTermEntries(
165 int $term_id
166 ): void {
167 $q = "DELETE FROM glo_flashcard_term " .
168 " WHERE term_id = " . $this->db->quote($term_id, "integer");
169 $this->db->manipulate($q);
170 }
171}
__construct(protected \ilDBInterface $db, protected InternalDataService $data_service)
Interface ilDBInterface.
$q
Definition: shib_logout.php:23