Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class ilMDCopyrightSelectionEntry
private string $title = '';
private string $description = '';
private string $copyright = '';
private int $usage = 0;
// set null as initial value to trigger a query on demand
private ?int $usage = null;

protected bool $outdated = false;

Expand Down Expand Up @@ -187,6 +188,19 @@ public static function isEntry($a_cp_string): bool

public function getUsage(): int
{
// do a time-consuming usage count on demand
if ($this->usage === null) {
$query = "SELECT count(meta_rights_id) used FROM il_meta_rights " .
"WHERE description = " . $this->db->quote(
'il_copyright_entry__' . IL_INST_ID . '__' . $this->getEntryId(),
'text'
);

$res = $this->db->query($query);
$row = $this->db->fetchObject($res);
$this->usage = (int) $row->used;
}

return $this->usage;
}

Expand Down Expand Up @@ -339,16 +353,6 @@ private function read(): void
$this->setCopyright($rendered_cp);
$this->setOutdated($entry->isOutdated());
$this->setOrderPosition($entry->position());

$query = "SELECT count(meta_rights_id) used FROM il_meta_rights " .
"WHERE description = " . $this->db->quote(
'il_copyright_entry__' . IL_INST_ID . '__' . $this->getEntryId(),
'text'
);

$res = $this->db->query($query);
$row = $this->db->fetchObject($res);
$this->usage = (int) $row->used;
}

public static function createIdentifier(int $a_entry_id): string
Expand Down