ILIAS  release_8 Revision v8.24
class.ilMDCopyrightUsageTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
23
30{
31 protected int $copyright_id;
32
33 protected ilDBInterface $db;
36
37 protected array $filter = [];
38 protected array $objects = [];
39
40 public function __construct(ilMDCopyrightUsageGUI $a_parent_obj, string $a_parent_cmd = '')
41 {
42 global $DIC;
43
44 $this->copyright_id = $a_parent_obj->getEntryId();
45 $this->setId("mdcopusage" . $this->copyright_id);
46
47 parent::__construct($a_parent_obj, $a_parent_cmd);
48
49 $this->ui_factory = $DIC->ui()->factory();
50 $this->ui_renderer = $DIC->ui()->renderer();
51 $this->db = $DIC->database();
52 $this->lng = $DIC->language();
53 $this->lng->loadLanguageModule('meta');
54 }
55
56 public function init(): void
57 {
58 $md_entry = new ilMDCopyrightSelectionEntry($this->copyright_id);
59 $this->setTitle($md_entry->getTitle());
60
61 $this->addColumn($this->lng->txt('object'), 'title');
62 $this->addColumn($this->lng->txt('meta_references'));
63 $this->addColumn($this->lng->txt('meta_copyright_sub_items'), 'sub_items');
64 $this->addColumn($this->lng->txt('owner'), 'owner_name');
65
66 $this->setRowTemplate("tpl.show_copyright_usages_row.html", "Services/MetaData");
67 $this->setFormAction($this->ctrl->getFormAction(
68 $this->getParentObject(),
69 $this->getParentCmd()
70 ));
71 $this->setDisableFilterHiding(true);
72
73 $this->initFilter();
74 }
75
76 public function parse(): void
77 {
78 $data = $this->collectData($this->getCurrentFilter());
79 $this->setData($data);
80 }
81
82 public function initFilter(): void
83 {
85 "title",
87 false,
88 $this->lng->txt("object") . " " . $this->lng->txt("title")
89 );
90 $this->filter["title"] = $title->getValue();
91
92 //object
93 $this->objects = array();
94 foreach ($this->getObjTypesAvailable() as $item) {
95 $this->objects[$item] = $this->lng->txt("obj_" . $item);
96 }
98 $item->setOptions(array("" => "-") + $this->objects);
99 $this->filter["object"] = $item->getValue();
100 }
101
102 public function numericOrdering(string $a_field): bool
103 {
104 if ($a_field === 'sub_items') {
105 return true;
106 }
107 return false;
108 }
109
113 protected function getCurrentFilter(): array
114 {
115 $filter = array();
116 if ($this->filter["title"]) {
117 $filter["title"] = $this->filter["title"];
118 }
119
120 if ($this->filter['object']) {
121 $filter['object'] = $this->filter['object'];
122 }
123 return $filter;
124 }
125
126 protected function fillRow(array $a_set): void
127 {
128 $icon = $this->ui_factory->symbol()->icon()->standard(
129 $a_set['type'],
130 $this->lng->txt($a_set['type']),
131 "medium"
132 );
133 $this->tpl->setVariable('OBJ_TYPE_ICON', $this->ui_renderer->render($icon));
134 $this->tpl->setVariable('TITLE', $a_set['title']);
135 $this->tpl->setVariable("DESCRIPTION", $a_set['desc']);
136 if ($a_set['references']) {
137 $path = new ilPathGUI();
138 $path->enableHideLeaf(false);
139 $path->enableDisplayCut(true);
140 $path->enableTextOnly(false);
141
142 foreach ($a_set['references'] as $reference) {
143 $this->tpl->setCurrentBlock("references");
144 $this->tpl->setVariable("REFERENCE", $path->getPath(ROOT_FOLDER_ID, (int) $reference));
145 $this->tpl->parseCurrentBlock();
146 }
147 }
148
149 $this->tpl->setVariable('SUB_ITEMS', $a_set['sub_items']);
150
151 //TODO FIX WHITE PAGE OWNER LINK
152 if ($a_set['owner_link']) {
153 $this->tpl->setCurrentBlock("link_owner");
154 $this->tpl->setVariable("OWNER_LINK", $a_set['owner_link']);
155 $this->tpl->setVariable('OWNER', $a_set['owner_name']);
156 $this->tpl->parseCurrentBlock();
157 } else {
158 $this->tpl->setCurrentBlock("owner");
159 $this->tpl->setVariable('OWNER', $a_set['owner_name']);
160 $this->tpl->parseCurrentBlock();
161 }
162 }
163
169 public function collectData(array $filters): array
170 {
171 $db_data = $this->getDataFromDB();
172
173 $data = array();
174 foreach ($db_data as $item) {
175 $obj_id = $item['obj_id'];
176 if (
177 ($filters['title'] ?? false) &&
178 stripos(ilObject::_lookupTitle($obj_id), $filters['title'] ?? '') === false
179 ) {
180 continue;
181 }
182 if (
183 ($filters['object'] ?? false) &&
184 ilObject::_lookupType($obj_id) !== ($filters['object'] ?? '')
185 ) {
186 continue;
187 }
188 $data[] = array(
189 "obj_id" => $obj_id,
190 "type" => ilObject::_lookupType($obj_id),
191 "title" => ilObject::_lookupTitle($obj_id),
192 "desc" => ilObject::_lookupDescription($obj_id),
193 "references" => ilObject::_getAllReferences($obj_id),
195 "owner_link" => ilUserUtil::getProfileLink(ilObject::_lookupOwner($obj_id)),
196 "sub_items" => $this->getCountSubItemsFromDB($obj_id)
197 );
198 }
199
200 return $data;
201 }
202
206 public function getObjTypesAvailable(): array
207 {
208 $query = "SELECT DISTINCT obj_type FROM il_meta_rights " .
209 "WHERE description = " . $this->db->quote(
210 'il_copyright_entry__' . IL_INST_ID . '__' . $this->copyright_id,
211 'text'
212 ) .
213 " AND rbac_id = obj_id";
214 $result = $this->db->query($query);
215 $data = array();
216 while ($row = $this->db->fetchAssoc($result)) {
217 $data[] = $row['obj_type'];
218 }
219 return $data;
220 }
221
225 public function getDataFromDB(): array
226 {
227 $query = "SELECT rbac_id, obj_id, obj_type FROM il_meta_rights " .
228 "WHERE description = " . $this->db->quote(
229 'il_copyright_entry__' . IL_INST_ID . '__' . $this->copyright_id,
230 'text'
231 ) .
232 ' AND rbac_id != ' . $this->db->quote(0, 'integer') .
233 " GROUP BY rbac_id";
234
235 $result = $this->db->query($query);
236 $data = array();
237 while ($row = $this->db->fetchAssoc($result)) {
238 $data[] = array(
239 "obj_id" => (int) $row['rbac_id'],
240 "obj_type" => (string) $row['obj_type']
241 );
242 }
243 return $data;
244 }
245
246 public function getCountSubItemsFromDB(int $a_rbac_id): int
247 {
248 $query = "SELECT count(rbac_id) total FROM il_meta_rights " .
249 "WHERE rbac_id = " . $this->db->quote($a_rbac_id, ilDBConstants::T_INTEGER) .
250 " AND rbac_id != obj_id";
251
252 $result = $this->db->query($query);
253 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
254 return (int) $row->total;
255 }
256 return 0;
257 }
258}
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(ilMDCopyrightUsageGUI $a_parent_obj, string $a_parent_cmd='')
numericOrdering(string $a_field)
Should this field be sorted numeric?
static _lookupType(int $id, bool $reference=false)
static _lookupOwner(int $obj_id)
Lookup owner user ID for object ID.
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
Creates a path for a start and endnode.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setDisableFilterHiding(bool $a_val=true)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
static getProfileLink(int $a_usr_id)
Get link to personal profile Return empty string in case of not public profile.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
const IL_INST_ID
Definition: constants.php:40
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilDBInterface.
$path
Definition: ltiservices.php:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query