ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.FlashcardBoxDBRepository.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): Box
37 {
38 return $this->data_service->flashcardBox(
39 (int) $rec["box_nr"],
40 (int) $rec["user_id"],
41 (int) $rec["glo_id"],
42 $rec["last_access"]
43 );
44 }
45
46 public function getEntry(
47 int $box_nr,
48 int $user_id,
49 int $glo_id
50 ): ?Box {
51 $set = $this->db->queryF(
52 "SELECT * FROM glo_flashcard_box " .
53 " WHERE box_nr = %s AND user_id = %s AND glo_id = %s ",
54 ["integer", "integer", "integer"],
55 [$box_nr, $user_id, $glo_id]
56 );
57
58 if ($rec = $this->db->fetchAssoc($set)) {
59 return $this->getFromRecord($rec);
60 }
61
62 return null;
63 }
64
65 public function createOrUpdateEntry(
66 Box $box
67 ): void {
68 $this->db->replace(
69 "glo_flashcard_box",
70 [
71 "box_nr" => ["integer", $box->getBoxNr()],
72 "user_id" => ["integer", $box->getUserId()],
73 "glo_id" => ["integer", $box->getGloId()]
74 ],
75 [
76 "last_access" => ["date", $box->getLastAccess()]
77 ]
78 );
79 }
80
81 public function deleteEntries(
82 int $glo_id,
83 int $user_id
84 ): void {
85 $q = "DELETE FROM glo_flashcard_box " .
86 " WHERE glo_id = " . $this->db->quote($glo_id, "integer") .
87 " AND user_id = " . $this->db->quote($user_id, "integer");
88 $this->db->manipulate($q);
89 }
90
91 public function deleteAllUserEntries(
92 int $user_id
93 ): void {
94 $q = "DELETE FROM glo_flashcard_box " .
95 " WHERE user_id = " . $this->db->quote($user_id, "integer");
96 $this->db->manipulate($q);
97 }
98
99 public function deleteAllGlossaryEntries(
100 int $glo_id
101 ): void {
102 $q = "DELETE FROM glo_flashcard_box " .
103 " WHERE glo_id = " . $this->db->quote($glo_id, "integer");
104 $this->db->manipulate($q);
105 }
106}
__construct(protected \ilDBInterface $db, protected InternalDataService $data_service)
Interface ilDBInterface.
$q
Definition: shib_logout.php:23