ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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...
 

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.

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

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

Member Function Documentation

◆ checkTitle()

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

Definition at line 209 of file DatabaseRepository.php.

Referenced by ILIAS\MetaData\Copyright\DatabaseRepository\createEntry(), and ILIAS\MetaData\Copyright\DatabaseRepository\updateEntry().

209  : void
210  {
211  if ($title === '') {
212  throw new \ilMDCopyrightException(
213  'Copyright entries can not have an empty title'
214  );
215  }
216  }
+ Here is the caller graph for this function:

◆ 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.

References ILIAS\MetaData\Copyright\DatabaseRepository\checkTitle(), ILIAS\MetaData\Copyright\DatabaseRepository\getNextPosition(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

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  }
+ Here is the call graph for this function:

◆ 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

◆ entryFromRow()

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

Definition at line 84 of file DatabaseRepository.php.

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

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

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  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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.

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

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  }
+ 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.

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

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  }
+ 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.

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

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  }
+ Here is the call graph for this function:

◆ getDefaultID()

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

Definition at line 231 of file DatabaseRepository.php.

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

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  }
+ Here is the caller graph for this function:

◆ getEntry()

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

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 35 of file DatabaseRepository.php.

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

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  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ getNextPosition()

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

Definition at line 160 of file DatabaseRepository.php.

References ILIAS\Repository\int().

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

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  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getURI()

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

Definition at line 106 of file DatabaseRepository.php.

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

106  : URI
107  {
108  return new URI($uri);
109  }
+ 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.

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

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  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ 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.

References ILIAS\MetaData\Copyright\DatabaseRepository\checkTitle(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

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  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ updatePosition()

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

Definition at line 243 of file DatabaseRepository.php.

References ilDBConstants\T_INTEGER.

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

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  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

Field Documentation

◆ $db_wrapper

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

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