ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilWebDAVMountInstructionsRepositoryImpl.php
Go to the documentation of this file.
1<?php
2
3
5{
6 const TABLE_MOUNT_INSTRUCTIONS = 'webdav_instructions';
7
9 protected $db;
10
16 public function __construct(ilDBInterface $a_db)
17 {
18 $this->db = $a_db;
19 }
20
25 {
26 $this->db->insert(
27 // table
28 self::TABLE_MOUNT_INSTRUCTIONS,
29
30 // values
31 array(
32 'id' => array('int', $document->getId()),
33 'title' => array('text', $document->getTitle()),
34 'uploaded_instructions' => array('clob', $document->getUploadedInstructions()),
35 'processed_instructions' => array('clob', $document->getProcessedInstructions()),
36 'lng' => array('text', $document->getLanguage()),
37 'creation_ts' => array('timestamp', $document->getCreationTs()),
38 'modification_ts' => array('timestamp', $document->getModificationTs()),
39 'owner_usr_id' => array('int', $document->getOwnerUsrId()),
40 'last_modification_usr_id' => array('int', $document->getLastModificationUsrId()),
41 'sorting' => array('int', $document->getSorting())
42 )
43 );
44 }
45
49 public function getNextMountInstructionsDocumentId() : int
50 {
51 if (!$this->db->sequenceExists(self::TABLE_MOUNT_INSTRUCTIONS)) {
52 $this->db->createSequence(self::TABLE_MOUNT_INSTRUCTIONS);
53 }
54
55 return $this->db->nextId(self::TABLE_MOUNT_INSTRUCTIONS);
56 }
57
61 public function getHighestSortingNumber() : int
62 {
63 $query = "SELECT max(sorting) as max_sort FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS);
64 $result = $this->db->query($query);
65
66 $row = $this->db->fetchAssoc($result);
67 return isset($row) && !is_null($row['max_sort']) ? $row['max_sort'] : 0;
68 }
69
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
92 {
93 $query = "SELECT * FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS)
94 . " WHERE lng=" . $this->db->quote($language, 'text');
95
96 $result = $this->db->query($query);
97 $record = $this->db->fetchAssoc($result);
98
99 if (!$record) {
100 throw new InvalidArgumentException("Document for the language $language not found");
101 }
102
103 return $this->buildDocumentFromDatabaseRecord($record);
104 }
105
109 public function getAllMountInstructions() : array
110 {
111 $query = "SELECT * FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS) . " ORDER BY sorting";
112 $result = $this->db->query($query);
113
114 $document_list = array();
115 while ($record = $this->db->fetchAssoc($result)) {
116 $document_list[] = $this->buildDocumentFromDatabaseRecord($record);
117 }
118
119 return $document_list;
120 }
121
125 public function doMountInstructionsExistByLanguage(string $language) : int
126 {
127 $query = "SELECT * FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS)
128 . " WHERE lng=" . $this->db->quote($language, 'text');
129
130 $result = $this->db->query($query);
131 $record = $this->db->fetchAssoc($result);
132
133 return ($record == null ? 0 : $record['id']);
134 }
135
140 {
141 $this->db->update(
142 // table name
143 self::TABLE_MOUNT_INSTRUCTIONS,
144
145 // values to update
146 array(
147 'title' => array('text', $document->getTitle()),
148 'lng' => array('text', $document->getLanguage()),
149 'creation_ts' => array('timestamp', $document->getCreationTs()),
150 'modification_ts' => array('timestamp', $document->getModificationTs()),
151 'owner_usr_id' => array('int', $document->getOwnerUsrId()),
152 'last_modification_usr_id' => array('int', $document->getLastModificationUsrId()),
153 'sorting' => array('int', $document->getSorting())
154 ),
155
156 // which rows to update
157 array(
158 'id' => array('int', $document->getId()),
159 )
160 );
161 }
162
166 public function updateSortingValueById(int $id, int $a_new_sorting_value)
167 {
168 $this->db->update(
169 // table name
170 self::TABLE_MOUNT_INSTRUCTIONS,
171
172 // values to update
173 array(
174 'sorting' => array('int', $a_new_sorting_value)
175 ),
176
177 // which rows to update
178 array(
179 'id' => array('int', $id),
180 )
181 );
182 }
183
187 public function deleteMountInstructionsById(int $id)
188 {
189 $query = "DELETE FROM " . $this->db->quoteIdentifier(self::TABLE_MOUNT_INSTRUCTIONS)
190 . ' WHERE id=' . $this->db->quote($id, 'integer');
191
192 $this->db->manipulate($query);
193 }
194
201 protected function buildDocumentFromDatabaseRecord(array $result)
202 {
204 $result['id'],
205 $result['title'],
206 $result['uploaded_instructions'],
207 $result['processed_instructions'],
208 $result['lng'],
209 $result['creation_ts'],
210 $result['modification_ts'],
211 $result['owner_usr_id'],
212 $result['last_modification_usr_id'],
213 $result['sorting']
214 );
215 }
216}
$result
An exception for terminatinating execution or to throw for unit testing.
__construct(ilDBInterface $a_db)
ilWebDAVMountInstructionsRepository constructor.
createMountInstructionsDocumentEntry(ilWebDAVMountInstructionsDocument $document)
@inheritDoc
buildDocumentFromDatabaseRecord(array $result)
Fills document with results array from database.
updateMountInstructions(ilWebDAVMountInstructionsDocument $document)
@inheritDoc
updateSortingValueById(int $id, int $a_new_sorting_value)
@inheritDoc
Interface ilDBInterface.
Interface ilWebDAVMountInstructionsRepository.
$query