ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMDCopyrightUsageTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
30{
31 protected int $copyright_id;
32 protected string $copyright_title;
33
34 protected ilDBInterface $db;
37
38 protected array $filter = [];
39 protected array $objects = [];
40
41 public function __construct(ilMDCopyrightUsageGUI $a_parent_obj, string $a_parent_cmd = '')
42 {
43 global $DIC;
44
45 $this->copyright_id = $a_parent_obj->getEntryId();
46 $this->copyright_title = $a_parent_obj->getEntryTitle();
47 $this->setId("mdcopusage" . $this->copyright_id);
48
49 parent::__construct($a_parent_obj, $a_parent_cmd);
50
51 $this->ui_factory = $DIC->ui()->factory();
52 $this->ui_renderer = $DIC->ui()->renderer();
53 $this->db = $DIC->database();
54 $this->lng = $DIC->language();
55 $this->lng->loadLanguageModule('meta');
56 }
57
58 public function init(): void
59 {
60 $this->setTitle($this->copyright_title);
61
62 $this->addColumn($this->lng->txt('object'), 'title');
63 $this->addColumn($this->lng->txt('meta_references'));
64 $this->addColumn($this->lng->txt('meta_copyright_sub_items'), 'sub_items');
65 $this->addColumn($this->lng->txt('owner'), 'owner_name');
66
67 $this->setRowTemplate("tpl.show_copyright_usages_row.html", "components/ILIAS/MetaData");
68 $this->setFormAction($this->ctrl->getFormAction(
69 $this->getParentObject(),
70 $this->getParentCmd()
71 ));
72 $this->setDisableFilterHiding(true);
73
74 $this->initFilter();
75 }
76
77 public function parse(): void
78 {
79 $data = $this->collectData($this->getCurrentFilter());
80 $this->setData($data);
81 }
82
83 public function initFilter(): void
84 {
86 "title",
88 false,
89 $this->lng->txt("object") . " " . $this->lng->txt("title")
90 );
91 $this->filter["title"] = $title->getValue();
92
93 //object
94 $this->objects = array();
95 foreach ($this->getObjTypesAvailable() as $item) {
96 $this->objects[$item] = $this->lng->txt("obj_" . $item);
97 }
99 $item->setOptions(array("" => "-") + $this->objects);
100 $this->filter["object"] = $item->getValue();
101 }
102
103 public function numericOrdering(string $a_field): bool
104 {
105 if ($a_field === 'sub_items') {
106 return true;
107 }
108 return false;
109 }
110
114 protected function getCurrentFilter(): array
115 {
116 $filter = array();
117 if ($this->filter["title"]) {
118 $filter["title"] = $this->filter["title"];
119 }
120
121 if ($this->filter['object']) {
122 $filter['object'] = $this->filter['object'];
123 }
124 return $filter;
125 }
126
127 protected function fillRow(array $a_set): void
128 {
129 $icon = $this->ui_factory->symbol()->icon()->standard(
130 $a_set['type'],
131 $this->lng->txt($a_set['type']),
132 "medium"
133 );
134 $this->tpl->setVariable('OBJ_TYPE_ICON', $this->ui_renderer->render($icon));
135 $this->tpl->setVariable('TITLE', $a_set['title']);
136 $this->tpl->setVariable("DESCRIPTION", $a_set['desc']);
137 if ($a_set['references']) {
138 $path = new ilPathGUI();
139 $path->enableHideLeaf(false);
140 $path->enableDisplayCut(true);
141 $path->enableTextOnly(false);
142
143 foreach ($a_set['references'] as $reference) {
144 $this->tpl->setCurrentBlock("references");
145 $this->tpl->setVariable("REFERENCE", $path->getPath(ROOT_FOLDER_ID, (int) $reference));
146 $this->tpl->parseCurrentBlock();
147 }
148 }
149
150 $this->tpl->setVariable('SUB_ITEMS', $a_set['sub_items']);
151
152 //TODO FIX WHITE PAGE OWNER LINK
153 if ($a_set['owner_link']) {
154 $this->tpl->setCurrentBlock("link_owner");
155 $this->tpl->setVariable("OWNER_LINK", $a_set['owner_link']);
156 $this->tpl->setVariable('OWNER', $a_set['owner_name']);
157 $this->tpl->parseCurrentBlock();
158 } else {
159 $this->tpl->setCurrentBlock("owner");
160 $this->tpl->setVariable('OWNER', $a_set['owner_name']);
161 $this->tpl->parseCurrentBlock();
162 }
163 }
164
170 public function collectData(array $filters): array
171 {
172 $db_data = $this->getDataFromDB();
173
174 $data = array();
175 foreach ($db_data as $item) {
176 $obj_id = $item['obj_id'];
177 if (
178 ($filters['title'] ?? false) &&
179 stripos(ilObject::_lookupTitle($obj_id), $filters['title'] ?? '') === false
180 ) {
181 continue;
182 }
183 if (
184 ($filters['object'] ?? false) &&
185 ilObject::_lookupType($obj_id) !== ($filters['object'] ?? '')
186 ) {
187 continue;
188 }
189 $data[] = array(
190 "obj_id" => $obj_id,
191 "type" => ilObject::_lookupType($obj_id),
192 "title" => ilObject::_lookupTitle($obj_id),
193 "desc" => ilObject::_lookupDescription($obj_id),
194 "references" => ilObject::_getAllReferences($obj_id),
196 "owner_link" => ilUserUtil::getProfileLink(ilObject::_lookupOwner($obj_id)),
197 "sub_items" => $this->getCountSubItemsFromDB($obj_id)
198 );
199 }
200
201 return $data;
202 }
203
207 public function getObjTypesAvailable(): array
208 {
209 $query = "SELECT DISTINCT obj_type FROM il_meta_rights " .
210 "WHERE description = " . $this->db->quote(
211 'il_copyright_entry__' . IL_INST_ID . '__' . $this->copyright_id,
212 'text'
213 ) .
214 " AND rbac_id = obj_id";
215 $result = $this->db->query($query);
216 $data = array();
217 while ($row = $this->db->fetchAssoc($result)) {
218 $data[] = $row['obj_type'];
219 }
220 return $data;
221 }
222
226 public function getDataFromDB(): array
227 {
228 $query = "SELECT rbac_id, obj_id, obj_type FROM il_meta_rights " .
229 "WHERE description = " . $this->db->quote(
230 'il_copyright_entry__' . IL_INST_ID . '__' . $this->copyright_id,
231 'text'
232 ) .
233 ' AND rbac_id != ' . $this->db->quote(0, 'integer') .
234 " GROUP BY rbac_id";
235
236 $result = $this->db->query($query);
237 $data = array();
238 while ($row = $this->db->fetchAssoc($result)) {
239 $data[] = array(
240 "obj_id" => (int) $row['rbac_id'],
241 "obj_type" => (string) $row['obj_type']
242 );
243 }
244 return $data;
245 }
246
247 public function getCountSubItemsFromDB(int $a_rbac_id): int
248 {
249 $query = "SELECT count(rbac_id) total FROM il_meta_rights " .
250 "WHERE rbac_id = " . $this->db->quote($a_rbac_id, ilDBConstants::T_INTEGER) .
251 " AND rbac_id != obj_id";
252
253 $result = $this->db->query($query);
254 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
255 return (int) $row->total;
256 }
257 return 0;
258 }
259}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
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)
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 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=null)
Default behaviour is:
static getProfileLink(int $a_usr_id)
Get link to personal profile Return empty string in case of not public profile.
const IL_INST_ID
Definition: constants.php:40
const ROOT_FOLDER_ID
Definition: constants.php:32
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:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26