ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\MetaData\Copyright\DatabaseRepository Class Reference
+ Inheritance diagram for ILIAS\MetaData\Copyright\DatabaseRepository:
+ Collaboration diagram for ILIAS\MetaData\Copyright\DatabaseRepository:

Public Member Functions

 __construct (WrapperInterface $db_wrapper)
 
 getEntry (int $id)
 
 getAllEntries ()
 The default entry is returned first, and the remaining entries are returned according to their position. More...
 
 getActiveEntries ()
 The default entry is returned first, and the remaining entries are returned according to their position. More...
 
 getDefaultEntry ()
 
 deleteEntry (int $id)
 
 createEntry (string $title, string $description='', bool $is_outdated=false, string $full_name='', ?URI $link=null, URI|string $image='', string $alt_text='')
 Returns the ID of the newly created entry. More...
 
 updateEntry (int $id, string $title, string $description='', bool $is_outdated=false, string $full_name='', ?URI $link=null, URI|string $image='', string $alt_text='')
 
 reorderEntries (int ... $ids)
 Updates the position of entries according to the order their IDs are passed. More...
 
 getEntry (int $id)
 
 getAllEntries ()
 The default entry is returned first, and the remaining entries are returned according to their position. More...
 
 getActiveEntries ()
 The default entry is returned first, and the remaining entries are returned according to their position. More...
 
 getDefaultEntry ()
 
 deleteEntry (int $id)
 
 createEntry (string $title, string $description='', bool $is_outdated=false, string $full_name='', ?URI $link=null, URI|string $image='', string $alt_text='')
 Returns the ID of the newly created entry. More...
 
 updateEntry (int $id, string $title, string $description='', bool $is_outdated=false, string $full_name='', ?URI $link=null, URI|string $image='', string $alt_text='')
 
 reorderEntries (int ... $ids)
 Updates the position of entries according to the order their IDs are passed. More...
 

Protected Member Functions

 entryFromRow (array $row)
 
 getURI (string $uri)
 
 getNextPosition ()
 
 checkTitle (string $title)
 
 getDefaultID ()
 
 updatePosition (int $id, int $position)
 

Protected Attributes

WrapperInterface $db_wrapper
 

Detailed Description

Definition at line 26 of file DatabaseRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MetaData\Copyright\DatabaseRepository::__construct ( WrapperInterface  $db_wrapper)

Definition at line 30 of file DatabaseRepository.php.

31 {
32 $this->db_wrapper = $db_wrapper;
33 }

References ILIAS\MetaData\Copyright\DatabaseRepository\$db_wrapper.

Member Function Documentation

◆ checkTitle()

ILIAS\MetaData\Copyright\DatabaseRepository::checkTitle ( string  $title)
protected

Definition at line 209 of file DatabaseRepository.php.

209 : void
210 {
211 if ($title === '') {
212 throw new \ilMDCopyrightException(
213 'Copyright entries can not have an empty title'
214 );
215 }
216 }

◆ createEntry()

ILIAS\MetaData\Copyright\DatabaseRepository::createEntry ( string  $title,
string  $description = '',
bool  $is_outdated = false,
string  $full_name = '',
?URI  $link = null,
URI|string  $image = '',
string  $alt_text = '' 
)

Returns the ID of the newly created entry.

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 119 of file DatabaseRepository.php.

127 : int {
128 $this->checkTitle($title);
129
130 $next_id = $this->db_wrapper->nextId('il_md_cpr_selections');
131 if (is_string($image)) {
132 $image_link = '';
133 $image_file = $image;
134 } else {
135 $image_link = (string) $image;
136 $image_file = '';
137 }
138
139 $this->db_wrapper->insert(
140 'il_md_cpr_selections',
141 [
142 'entry_id' => [\ilDBConstants::T_INTEGER, $next_id],
143 'title' => [\ilDBConstants::T_TEXT, $title],
144 'description' => [\ilDBConstants::T_TEXT, $description],
145 'is_default' => [\ilDBConstants::T_INTEGER, 0],
146 'outdated' => [\ilDBConstants::T_INTEGER, (int) $is_outdated],
147 'position' => [\ilDBConstants::T_INTEGER, $this->getNextPosition()],
148 'full_name' => [\ilDBConstants::T_TEXT, $full_name],
149 'link' => [\ilDBConstants::T_TEXT, (string) $link],
150 'image_link' => [\ilDBConstants::T_TEXT, $image_link],
151 'image_file' => [\ilDBConstants::T_TEXT, $image_file],
152 'alt_text' => [\ilDBConstants::T_TEXT, $alt_text],
153 'migrated' => [\ilDBConstants::T_INTEGER, 1]
154 ]
155 );
156
157 return $next_id;
158 }

◆ deleteEntry()

ILIAS\MetaData\Copyright\DatabaseRepository::deleteEntry ( int  $id)

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 111 of file DatabaseRepository.php.

111 : void
112 {
113 $this->db_wrapper->manipulate(
114 'DELETE FROM il_md_cpr_selections WHERE entry_id = ' .
115 $this->db_wrapper->quoteInteger($id)
116 );
117 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

◆ entryFromRow()

ILIAS\MetaData\Copyright\DatabaseRepository::entryFromRow ( array  $row)
protected

Definition at line 84 of file DatabaseRepository.php.

84 : EntryInterface
85 {
86 $data = new CopyrightData(
87 (string) ($row['full_name'] ?? ''),
88 !empty($row['link'] ?? '') ? $this->getURI((string) $row['link']) : null,
89 !empty($row['image_link']) ? $this->getURI((string) $row['image_link']) : null,
90 (string) ($row['image_file'] ?? ''),
91 (string) ($row['alt_text'] ?? ''),
92 $row['is_default'] ? true : false
93 );
94
95 return new Entry(
96 (int) $row['entry_id'],
97 (string) ($row['title'] ?? ''),
98 (string) ($row['description'] ?? ''),
99 $row['is_default'] ? true : false,
100 $row['outdated'] ? true : false,
101 (int) ($row['position'] ?? 0),
102 $data
103 );
104 }

References $data, and ILIAS\MetaData\Copyright\DatabaseRepository\getURI().

Referenced by ILIAS\MetaData\Copyright\DatabaseRepository\getActiveEntries(), ILIAS\MetaData\Copyright\DatabaseRepository\getAllEntries(), ILIAS\MetaData\Copyright\DatabaseRepository\getDefaultEntry(), and ILIAS\MetaData\Copyright\DatabaseRepository\getEntry().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getActiveEntries()

ILIAS\MetaData\Copyright\DatabaseRepository::getActiveEntries ( )

The default entry is returned first, and the remaining entries are returned according to their position.

Outdated entries are skipped.

Returns
EntryInterface[]

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 60 of file DatabaseRepository.php.

60 : \Generator
61 {
62 $rows = $this->db_wrapper->query(
63 'SELECT * FROM il_md_cpr_selections WHERE outdated = 0
64 ORDER BY is_default DESC, position ASC'
65 );
66
67 foreach ($rows as $row) {
68 yield $this->entryFromRow($row);
69 }
70 }

References ILIAS\MetaData\Copyright\DatabaseRepository\entryFromRow().

+ Here is the call graph for this function:

◆ getAllEntries()

ILIAS\MetaData\Copyright\DatabaseRepository::getAllEntries ( )

The default entry is returned first, and the remaining entries are returned according to their position.

Returns
EntryInterface[]

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 48 of file DatabaseRepository.php.

48 : \Generator
49 {
50 $rows = $this->db_wrapper->query(
51 'SELECT * FROM il_md_cpr_selections
52 ORDER BY is_default DESC, position ASC'
53 );
54
55 foreach ($rows as $row) {
56 yield $this->entryFromRow($row);
57 }
58 }

References ILIAS\MetaData\Copyright\DatabaseRepository\entryFromRow().

+ Here is the call graph for this function:

◆ getDefaultEntry()

ILIAS\MetaData\Copyright\DatabaseRepository::getDefaultEntry ( )

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 72 of file DatabaseRepository.php.

72 : EntryInterface
73 {
74 $rows = $this->db_wrapper->query(
75 'SELECT * FROM il_md_cpr_selections WHERE is_default = 1'
76 );
77
78 foreach ($rows as $row) {
79 return $this->entryFromRow($row);
80 }
81 return new NullEntry();
82 }

References ILIAS\MetaData\Copyright\DatabaseRepository\entryFromRow().

+ Here is the call graph for this function:

◆ getDefaultID()

ILIAS\MetaData\Copyright\DatabaseRepository::getDefaultID ( )
protected

Definition at line 231 of file DatabaseRepository.php.

231 : int
232 {
233 $rows = $this->db_wrapper->query(
234 'SELECT entry_id FROM il_md_cpr_selections WHERE is_default = 1'
235 );
236
237 foreach ($rows as $row) {
238 return (int) ($row['entry_id'] ?? 0);
239 }
240 return 0;
241 }

◆ getEntry()

ILIAS\MetaData\Copyright\DatabaseRepository::getEntry ( int  $id)

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 35 of file DatabaseRepository.php.

35 : EntryInterface
36 {
37 $rows = $this->db_wrapper->query(
38 'SELECT * FROM il_md_cpr_selections WHERE entry_id = ' .
39 $this->db_wrapper->quoteInteger($id)
40 );
41
42 foreach ($rows as $row) {
43 return $this->entryFromRow($row);
44 }
45 return new NullEntry();
46 }

References $id, and ILIAS\MetaData\Copyright\DatabaseRepository\entryFromRow().

+ Here is the call graph for this function:

◆ getNextPosition()

ILIAS\MetaData\Copyright\DatabaseRepository::getNextPosition ( )
protected

Definition at line 160 of file DatabaseRepository.php.

160 : int
161 {
162 $rows = $this->db_wrapper->query(
163 'SELECT MAX(position) AS max FROM il_md_cpr_selections WHERE is_default = 0'
164 );
165 foreach ($rows as $row) {
166 return isset($row['max']) ? ((int) $row['max']) + 1 : 0;
167 }
168 return 0;
169 }

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ getURI()

ILIAS\MetaData\Copyright\DatabaseRepository::getURI ( string  $uri)
protected

Definition at line 106 of file DatabaseRepository.php.

106 : URI
107 {
108 return new URI($uri);
109 }
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35

Referenced by ILIAS\MetaData\Copyright\DatabaseRepository\entryFromRow().

+ Here is the caller graph for this function:

◆ reorderEntries()

ILIAS\MetaData\Copyright\DatabaseRepository::reorderEntries ( int ...  $ids)

Updates the position of entries according to the order their IDs are passed.

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 218 of file DatabaseRepository.php.

218 : void
219 {
220 $pos = 0;
221 $default_id = $this->getDefaultID();
222 foreach ($ids as $id) {
223 if ($id === $default_id) {
224 continue;
225 }
226 $this->updatePosition($id, $pos);
227 $pos++;
228 }
229 }

References $id.

◆ updateEntry()

ILIAS\MetaData\Copyright\DatabaseRepository::updateEntry ( int  $id,
string  $title,
string  $description = '',
bool  $is_outdated = false,
string  $full_name = '',
?URI  $link = null,
URI|string  $image = '',
string  $alt_text = '' 
)

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 171 of file DatabaseRepository.php.

180 : void {
181 $this->checkTitle($title);
182
183 if (is_string($image)) {
184 $image_link = '';
185 $image_file = $image;
186 } else {
187 $image_link = (string) $image;
188 $image_file = '';
189 }
190
191 $this->db_wrapper->update(
192 'il_md_cpr_selections',
193 [
194 'title' => [\ilDBConstants::T_TEXT, $title],
195 'description' => [\ilDBConstants::T_TEXT, $description],
196 'outdated' => [\ilDBConstants::T_INTEGER, (int) $is_outdated],
197 'full_name' => [\ilDBConstants::T_TEXT, $full_name],
198 'link' => [\ilDBConstants::T_TEXT, (string) $link],
199 'image_link' => [\ilDBConstants::T_TEXT, $image_link],
200 'image_file' => [\ilDBConstants::T_TEXT, $image_file],
201 'alt_text' => [\ilDBConstants::T_TEXT, $alt_text]
202 ],
203 [
204 'entry_id' => [\ilDBConstants::T_INTEGER, $id]
205 ]
206 );
207 }

◆ updatePosition()

ILIAS\MetaData\Copyright\DatabaseRepository::updatePosition ( int  $id,
int  $position 
)
protected

Definition at line 243 of file DatabaseRepository.php.

243 : void
244 {
245 $this->db_wrapper->update(
246 'il_md_cpr_selections',
247 ['position' => [\ilDBConstants::T_INTEGER, $position]],
248 ['entry_id' => [\ilDBConstants::T_INTEGER, $id]]
249 );
250 }

References $id, and ilDBConstants\T_INTEGER.

Field Documentation

◆ $db_wrapper

WrapperInterface ILIAS\MetaData\Copyright\DatabaseRepository::$db_wrapper
protected

The documentation for this class was generated from the following file: