19 declare(strict_types=1);
57 $DIC->ui()->factory(),
58 $DIC->resourceStorage()
61 $this->ui_renderer = $DIC->ui()->renderer();
62 $this->
logger = $DIC->logger()->meta();
63 $this->db = $DIC->database();
64 $this->entry_id = $a_entry_id;
75 $ilDB = $DIC->database();
77 $query =
"SELECT entry_id FROM il_md_cpr_selections ORDER BY is_default DESC, position ASC";
91 $ilDB = $DIC->database();
93 if (!$entry_id = self::_extractEntryId($a_cp_string)) {
97 $query =
"SELECT title FROM il_md_cpr_selections " .
101 return $row->title ??
'';
109 $DIC->ui()->factory(),
110 $DIC->resourceStorage()
113 $ui_renderer = $DIC->ui()->renderer();
115 if (!$entry_id = self::_extractEntryId($a_cp_string)) {
119 $entry = $repository->getEntry($entry_id);
131 if (!$entry_id = self::_extractEntryId($a_cp_string)) {
137 return (
string) (
$data->link() ??
$data->fullName());
147 $normalized_copyright = str_replace(
'https://',
'http://', $copyright_text);
149 $matches_by_name = null;
151 $entry_link = (string) $entry->copyrightData()->link();
152 $normalized_link = str_replace(
'https://',
'http://', $entry_link);
153 if ($normalized_link !==
'' && str_contains($normalized_copyright, $normalized_link)) {
158 is_null($matches_by_name) &&
159 trim($copyright_text) === trim($entry->copyrightData()->fullName())
161 $matches_by_name = $entry->id();
165 if (!is_null($matches_by_name)) {
166 return $matches_by_name;
173 if (!preg_match(
'/il_copyright_entry__([0-9]+)__([0-9]+)/', $a_cp_string, $matches)) {
179 return (
int) ($matches[2] ?? 0);
182 public static function isEntry($a_cp_string): bool
184 if (!preg_match(
'/il_copyright_entry__([0-9]+)__([0-9]+)/', $a_cp_string)) {
193 if ($this->usage === null) {
194 $query =
"SELECT count(meta_rights_id) used FROM il_meta_rights " .
195 "WHERE description = " . $this->db->quote(
200 $res = $this->db->query($query);
201 $row = $this->db->fetchObject(
$res);
202 $this->usage = (
int) $row->used;
219 $query =
"SELECT is_default FROM il_md_cpr_selections " .
220 "WHERE entry_id = " . $this->db->quote($this->entry_id,
'integer');
222 $res = $this->db->query($query);
223 $row = $this->db->fetchAssoc(
$res);
225 return (
bool) ($row[
'is_default'] ??
false);
230 $this->outdated = $a_value;
242 $db = $DIC->database();
244 $query =
"SELECT entry_id FROM il_md_cpr_selections " .
245 "WHERE is_default = " . $db->
quote(1,
'integer');
250 return (
int) $row[
'entry_id'];
255 $this->title = $a_title;
265 $this->description = $a_desc;
275 $this->copyright = $a_copyright;
285 $this->order_position = $a_position;
295 $query =
"SELECT count(entry_id) total FROM il_md_cpr_selections";
296 $res = $this->db->query($query);
297 $row = $this->db->fetchAssoc(
$res);
299 return $row[
'total'] + 1;
302 public function add(): bool
304 $next_id = $this->db->nextId(
'il_md_cpr_selections');
306 $this->db->insert(
'il_md_cpr_selections', array(
307 'entry_id' => array(
'integer', $next_id),
308 'title' => array(
'text', $this->
getTitle()),
311 'outdated' => array(
'integer', $this->
getOutdated()),
314 $this->entry_id = $next_id;
320 $this->db->update(
'il_md_cpr_selections', array(
321 'title' => array(
'text', $this->
getTitle()),
324 'outdated' => array(
'integer', $this->
getOutdated()),
327 'entry_id' => array(
'integer', $this->
getEntryId())
332 public function delete():
void 346 $entry = $this->
repository->getEntry($this->entry_id);
348 $rendered_cp = $this->ui_renderer->render(
349 $this->renderer->toUIComponents($entry->copyrightData())
361 return 'il_copyright_entry__' .
IL_INST_ID .
'__' . $a_entry_id;
static _extractEntryId(string $a_cp_string)
fetchAssoc(ilDBStatement $statement)
static _lookupCopyrightForExport(string $a_cp_string)
repository()
description: > Example for rendering a repository card
setCopyright(string $a_copyright)
quote($value, string $type)
RepositoryInterface $repository
static isEntry($a_cp_string)
setDescription(string $a_desc)
query(string $query)
Run a (read-only) Query on the database.
__construct(int $a_entry_id)
static _lookupCopyright(string $a_cp_string)
static lookupCopyrightFromImport(string $copyright_text)
setOrderPosition(int $a_position)
getIsDefault()
Get if the entry is default No setter for this.
RendererInterface $renderer
setTitle(string $a_title)
static createIdentifier(int $a_entry_id)
static lookupCopyyrightTitle(string $a_cp_string)
setOutdated(bool $a_value)