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