ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\MetaData\Copyright\DatabaseRepository Class Reference
+ Inheritance diagram for ILIAS\MetaData\Copyright\DatabaseRepository:
+ Collaboration diagram for ILIAS\MetaData\Copyright\DatabaseRepository:

Public Member Functions

 __construct (\ilDBInterface $db)
 
 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

ilDBInterface $db
 

Detailed Description

Definition at line 25 of file DatabaseRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MetaData\Copyright\DatabaseRepository::__construct ( \ilDBInterface  $db)

Definition at line 29 of file DatabaseRepository.php.

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

30  {
31  $this->db = $db;
32  }

Member Function Documentation

◆ checkTitle()

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

Definition at line 207 of file DatabaseRepository.php.

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

207  : void
208  {
209  if ($title === '') {
210  throw new \ilMDCopyrightException(
211  'Copyright entries can not have an empty title'
212  );
213  }
214  }
+ 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 118 of file DatabaseRepository.php.

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

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

◆ deleteEntry()

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

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 110 of file DatabaseRepository.php.

References ilDBConstants\T_INTEGER.

110  : void
111  {
112  $this->db->manipulate(
113  'DELETE FROM il_md_cpr_selections WHERE entry_id = ' .
114  $this->db->quote($id, \ilDBConstants::T_INTEGER)
115  );
116  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

◆ entryFromRow()

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

Definition at line 83 of file DatabaseRepository.php.

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().

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

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 59 of file DatabaseRepository.php.

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

59  : \Generator
60  {
61  $res = $this->db->query(
62  'SELECT * FROM il_md_cpr_selections WHERE outdated = 0
63  ORDER BY is_default DESC, position ASC'
64  );
65 
66  while ($row = $this->db->fetchAssoc($res)) {
67  yield $this->entryFromRow($row);
68  }
69  }
$res
Definition: ltiservices.php:69
+ 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.

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 47 of file DatabaseRepository.php.

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

47  : \Generator
48  {
49  $res = $this->db->query(
50  'SELECT * FROM il_md_cpr_selections
51  ORDER BY is_default DESC, position ASC'
52  );
53 
54  while ($row = $this->db->fetchAssoc($res)) {
55  yield $this->entryFromRow($row);
56  }
57  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:

◆ getDefaultEntry()

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

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 71 of file DatabaseRepository.php.

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

71  : EntryInterface
72  {
73  $res = $this->db->query(
74  'SELECT * FROM il_md_cpr_selections WHERE is_default = 1'
75  );
76 
77  if ($row = $this->db->fetchAssoc($res)) {
78  return $this->entryFromRow($row);
79  }
80  return new NullEntry();
81  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:

◆ getDefaultID()

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

Definition at line 229 of file DatabaseRepository.php.

References $res.

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

229  : int
230  {
231  $res = $this->db->query(
232  'SELECT entry_id FROM il_md_cpr_selections WHERE is_default = 1'
233  );
234 
235  if ($row = $this->db->fetchAssoc($res)) {
236  return $row['entry_id'] ?? 0;
237  }
238  return 0;
239  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getEntry()

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

Implements ILIAS\MetaData\Copyright\RepositoryInterface.

Definition at line 34 of file DatabaseRepository.php.

References $res, ILIAS\MetaData\Copyright\DatabaseRepository\entryFromRow(), and ilDBConstants\T_INTEGER.

34  : EntryInterface
35  {
36  $res = $this->db->query(
37  'SELECT * FROM il_md_cpr_selections WHERE entry_id = ' .
38  $this->db->quote($id, \ilDBConstants::T_INTEGER)
39  );
40 
41  if ($row = $this->db->fetchAssoc($res)) {
42  return $this->entryFromRow($row);
43  }
44  return new NullEntry();
45  }
$res
Definition: ltiservices.php:69
$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 159 of file DatabaseRepository.php.

References $res.

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

159  : int
160  {
161  $res = $this->db->query(
162  'SELECT MAX(position) AS max FROM il_md_cpr_selections WHERE is_default = 0'
163  );
164  $row = $this->db->fetchAssoc($res);
165 
166  return isset($row['max']) ? $row['max'] + 1 : 0;
167  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getURI()

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

Definition at line 105 of file DatabaseRepository.php.

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

105  : URI
106  {
107  return new URI($uri);
108  }
+ 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 216 of file DatabaseRepository.php.

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

216  : void
217  {
218  $pos = 0;
219  $default_id = $this->getDefaultID();
220  foreach ($ids as $id) {
221  if ($id === $default_id) {
222  continue;
223  }
224  $this->updatePosition($id, $pos);
225  $pos++;
226  }
227  }
$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 169 of file DatabaseRepository.php.

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

178  : void {
179  $this->checkTitle($title);
180 
181  if (is_string($image)) {
182  $image_link = '';
183  $image_file = $image;
184  } else {
185  $image_link = (string) $image;
186  $image_file = '';
187  }
188 
189  $this->db->update(
190  'il_md_cpr_selections',
191  [
192  'title' => [\ilDBConstants::T_TEXT, $title],
193  'description' => [\ilDBConstants::T_TEXT, $description],
194  'outdated' => [\ilDBConstants::T_INTEGER, (int) $is_outdated],
195  'full_name' => [\ilDBConstants::T_TEXT, $full_name],
196  'link' => [\ilDBConstants::T_TEXT, (string) $link],
197  'image_link' => [\ilDBConstants::T_TEXT, $image_link],
198  'image_file' => [\ilDBConstants::T_TEXT, $image_file],
199  'alt_text' => [\ilDBConstants::T_TEXT, $alt_text]
200  ],
201  [
202  'entry_id' => [\ilDBConstants::T_INTEGER, $id]
203  ]
204  );
205  }
$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 241 of file DatabaseRepository.php.

References ilDBConstants\T_INTEGER.

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

241  : void
242  {
243  $this->db->update(
244  'il_md_cpr_selections',
245  ['position' => [\ilDBConstants::T_INTEGER, $position]],
246  ['entry_id' => [\ilDBConstants::T_INTEGER, $id]]
247  );
248  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ILIAS\MetaData\Copyright\DatabaseRepository::$db
protected

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