ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWebDAVMountInstructionsRepositoryImpl.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public const TABLE_MOUNT_INSTRUCTIONS = 'webdav_instructions';
24
25 public function __construct(protected ilDBInterface $db)
26 {
27 }
28
30 {
31 $this->db->insert(
32 // table
33 self::TABLE_MOUNT_INSTRUCTIONS,
34
35 // values
36 [
37 'id' => ['int', $document->getId()],
38 'title' => ['text', $document->getTitle()],
39 'uploaded_instructions' => ['clob', $document->getUploadedInstructions()],
40 'processed_instructions' => ['clob', $document->getProcessedInstructions()],
41 'lng' => ['text', $document->getLanguage()],
42 'creation_ts' => ['timestamp', $document->getCreationTs()],
43 'modification_ts' => ['timestamp', $document->getModificationTs()],
44 'owner_usr_id' => ['int', $document->getOwnerUsrId()],
45 'last_modification_usr_id' => ['int', $document->getLastModificationUsrId()],
46 'sorting' => ['int', $document->getSorting()]
47 ]
48 );
49 }
50
52 {
53 if (!$this->db->sequenceExists(self::TABLE_MOUNT_INSTRUCTIONS)) {
54 $this->db->createSequence(self::TABLE_MOUNT_INSTRUCTIONS);
55 }
56
57 return $this->db->nextId(self::TABLE_MOUNT_INSTRUCTIONS);
58 }
59
60 public function getHighestSortingNumber(): int
61 {
62 $query = "SELECT max(sorting) as max_sort FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS);
63 $result = $this->db->query($query);
64
65 $row = $this->db->fetchAssoc($result);
66 return isset($row) && !is_null($row['max_sort']) ? (int) $row['max_sort'] : 0;
67 }
68
70 {
71 $query = "SELECT * FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS)
72 . " WHERE id=" . $this->db->quote($id, 'int');
73
74 $result = $this->db->query($query);
75 $record = $this->db->fetchAssoc($result);
76
77 if (!$record) {
78 throw new InvalidArgumentException("Document with the id $id not found");
79 }
80
81 return $this->buildDocumentFromDatabaseRecord($record);
82 }
83
85 {
86 $query = "SELECT * FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS)
87 . " WHERE lng=" . $this->db->quote($language, 'text');
88
89 $result = $this->db->query($query);
90 $record = $this->db->fetchAssoc($result);
91
92 if (!$record) {
93 throw new InvalidArgumentException("Document for the language $language not found");
94 }
95
96 return $this->buildDocumentFromDatabaseRecord($record);
97 }
98
99 public function getAllMountInstructions(): array
100 {
101 $query = "SELECT * FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS) . " ORDER BY sorting";
102 $result = $this->db->query($query);
103
104 $document_list = [];
105 while ($record = $this->db->fetchAssoc($result)) {
106 $document_list[] = $this->buildDocumentFromDatabaseRecord($record);
107 }
108
109 return $document_list;
110 }
111
112 public function doMountInstructionsExistByLanguage(string $language): int
113 {
114 $query = "SELECT id FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS)
115 . " WHERE lng=" . $this->db->quote($language, 'text');
116
117 $result = $this->db->query($query);
118 $record = $this->db->fetchAssoc($result);
119
120 return ($record === null ? 0 : (int) $record['id']);
121 }
122
124 {
125 $this->db->update(
126 // table name
127 self::TABLE_MOUNT_INSTRUCTIONS,
128
129 // values to update
130 [
131 'title' => ['text', $document->getTitle()],
132 'lng' => ['text', $document->getLanguage()],
133 'creation_ts' => ['timestamp', $document->getCreationTs()],
134 'modification_ts' => ['timestamp', $document->getModificationTs()],
135 'owner_usr_id' => ['int', $document->getOwnerUsrId()],
136 'last_modification_usr_id' => ['int', $document->getLastModificationUsrId()],
137 'sorting' => ['int', $document->getSorting()]
138 ],
139
140 // which rows to update
141 [
142 'id' => ['int', $document->getId()],
143 ]
144 );
145 }
146
147 public function updateSortingValueById(int $id, int $a_new_sorting_value): void
148 {
149 $this->db->update(
150 // table name
151 self::TABLE_MOUNT_INSTRUCTIONS,
152
153 // values to update
154 [
155 'sorting' => ['int', $a_new_sorting_value]
156 ],
157
158 // which rows to update
159 [
160 'id' => ['int', $id],
161 ]
162 );
163 }
164
165 public function deleteMountInstructionsById(int $id): void
166 {
167 $query = "DELETE FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS)
168 . ' WHERE id=' . $this->db->quote($id, 'integer');
169
170 $this->db->manipulate($query);
171 }
172
174 {
176 (int) $result['id'],
177 $result['title'],
178 $result['uploaded_instructions'],
179 $result['processed_instructions'],
180 $result['lng'],
181 $result['creation_ts'],
182 $result['modification_ts'],
183 (int) $result['owner_usr_id'],
184 (int) $result['last_modification_usr_id'],
185 (int) $result['sorting']
186 );
187 }
188}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
createMountInstructionsDocumentEntry(ilWebDAVMountInstructionsDocument $document)
updateMountInstructions(ilWebDAVMountInstructionsDocument $document)
Interface ilDBInterface.