ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDRecordTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 public const ID = 'adv_md_records_tbl';
28
30 protected string $in_object_type_context = ""; // repo object type, if settings are not global
31
32 public function __construct(
33 $a_parent_obj,
34 $a_parent_cmd,
35 ilAdvancedMDPermissionHelper $a_permissions,
36 $a_in_object_type_context = ""
37 ) {
38 $this->permissions = $a_permissions;
39 $this->in_object_type_context = $a_in_object_type_context;
40
41 $this->setId(self::ID);
42 parent::__construct($a_parent_obj, $a_parent_cmd);
43 $this->addColumn('', '', '1');
44 $this->addColumn($this->lng->txt('md_adv_col_presentation_ordering'), 'position');
45 $this->addColumn($this->lng->txt('title'), 'title');
46 $this->addColumn($this->lng->txt('md_fields'));
47 $this->addColumn($this->lng->txt('md_adv_scope'), 'first_scope');
48 $this->addColumn($this->lng->txt('md_obj_types'));
49 $this->addColumn($this->lng->txt('md_adv_active'), 'active');
50
51 $this->addColumn($this->lng->txt('actions'));
52
53 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
54 $this->setRowTemplate("tpl.show_records_row.html", "components/ILIAS/AdvancedMetaData");
55 $this->setDefaultOrderField('position');
56 $this->setDefaultOrderDirection('asc');
57 $this->setShowRowsSelector(true);
58 }
59
60 public function numericOrdering(string $a_field): bool
61 {
62 if ($a_field == 'position') {
63 return true;
64 }
65 return parent::numericOrdering($a_field);
66 }
67
68 protected function fillRow(array $a_set): void
69 {
70 // assigned object types
72
73 if ($this->in_object_type_context === "") {
74 // options for global administration
75 $options = array(
76 0 => $this->lng->txt("meta_obj_type_inactive"),
77 1 => $this->lng->txt("meta_obj_type_mandatory"),
78 2 => $this->lng->txt("meta_obj_type_optional")
79 );
80 } else {
81 // options for local administration
82 $options = array(
83 0 => $this->lng->txt("meta_obj_type_inactive"),
84 1 => $this->lng->txt("meta_obj_type_active")
85 );
86 }
87
88 $do_select = true;
89
90 foreach (ilAdvancedMDRecord::_getAssignableObjectTypes(true) as $obj_type) {
91 $value = 0;
92 $do_disable = false;
93
94 // workaround for hiding portfolio pages in portfolios, since they only get
95 // data from portfolio templates
96 // @todo define interface for configuration of behaviour
97 $hidden = false;
98 if ($obj_type["obj_type"] == "prtf" && $obj_type["sub_type"] == "pfpg") {
99 $hidden = true;
100 }
101 // EmployeeTalks get their md from templates
102 if ($obj_type["obj_type"] == "tals" && $obj_type["sub_type"] == "etal") {
103 $hidden = true;
104 }
105
106 $assigned = false;
107 foreach ($a_set['obj_types'] as $t) {
108 if ($obj_type["obj_type"] == $t["obj_type"] &&
109 $obj_type["sub_type"] == $t["sub_type"]) {
110 $assigned = true;
111 $value = $t["optional"]
112 ? 2
113 : 1;
114
115 if (!$a_set["local"] && $a_set["readonly"]) {
116 // globally mandatory options should be disabled locally
117 if ($value === 1) {
118 $do_disable = true;
119 break;
120 }
121
122 // globally optional, locally selected global records
123 $value = (isset($a_set["local_selected"][$obj_type["obj_type"]]) &&
124 in_array($obj_type["sub_type"], $a_set["local_selected"][$obj_type["obj_type"]]))
125 ? 1
126 : 0;
127 }
128
129 break;
130 }
131 }
132
133 // do only list context types that match the current object type
134 if ($this->in_object_type_context !== "" && $this->in_object_type_context !== $obj_type["obj_type"]) {
135 continue;
136 }
137
138 // subtypes where the record is globally disabled should not be displayed at all #38557
139 // (only relevant if there are multiple subtypes, and for only some this record is disabled)
140 if ($this->in_object_type_context !== "" && !$a_set["local"] && !$assigned) {
141 continue;
142 }
143
144 if ($do_select) {
145 $this->tpl->setCurrentBlock('ass_obj_types');
146 $this->tpl->setVariable('VAL_OBJ_TYPE', $obj_type["text"]);
147
148 $type_options = $options;
149 switch ($obj_type["obj_type"]) {
150 case "talt":
151 // currently only optional records for talk templates (types)
152 unset($type_options[1]);
153 break;
154 case "rcrs":
155 // optional makes no sense for ecs-courses
156 unset($type_options[2]);
157 break;
158 }
160 $value,
161 "obj_types[" . $a_set['id'] . "][" . $obj_type["obj_type"] . ":" . $obj_type["sub_type"] . "]",
162 $type_options,
163 false,
164 true,
165 0,
166 "",
167 array("style" => "min-width:125px"),
168 $disabled || $do_disable
169 );
170 $this->tpl->setVariable('VAL_OBJ_TYPE_CLASS', $hidden ? 'hidden' : 'std');
171 $this->tpl->setVariable('VAL_OBJ_TYPE_STATUS', $select);
172 $this->tpl->parseCurrentBlock();
173 } else {
174 // only show object type
175 $this->tpl->setCurrentBlock('ass_obj_only');
176 $this->tpl->setVariable('VAL_OBJ_TYPE', $obj_type["text"]);
177 $this->tpl->parseCurrentBlock();
178 }
179 }
180
181 $record = ilAdvancedMDRecord::_getInstanceByRecordId((int) $a_set['id']);
182 if (!$a_set['local'] && count($record->getScopeRefIds())) {
183 $this->tpl->setCurrentBlock('scope_txt');
184 $this->tpl->setVariable('LOCAL_OR_GLOBAL', $this->lng->txt('md_adv_scope_list_header'));
185 $this->tpl->parseCurrentBlock();
186
187 foreach ($record->getScopeRefIds() as $ref_id) {
188 if (!ilObject::_exists($ref_id, true)) {
189 continue;
190 }
191 $this->tpl->setCurrentBlock('scope_entry');
192 $this->tpl->setVariable('LINK_HREF', ilLink::_getLink($ref_id));
193 $this->tpl->setVariable('LINK_NAME', ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)));
194 $this->tpl->parseCurrentBlock();
195 }
196 } else {
197 $this->tpl->setCurrentBlock('scope_txt');
198 $this->tpl->setVariable(
199 'LOCAL_OR_GLOBAL',
200 $a_set['local'] ? $this->lng->txt('meta_local') : $this->lng->txt('meta_global')
201 );
202 $this->tpl->parseCurrentBlock();
203 }
204
205 if (!$a_set["readonly"] || $a_set["local"]) {
206 $this->tpl->setCurrentBlock('check_bl');
207 $this->tpl->setVariable('VAL_ID', $a_set['id']);
208 $this->tpl->parseCurrentBlock();
209 }
210
211 $this->tpl->setVariable('R_ID', $a_set['id']);
212 $this->tpl->setVariable('VAL_POS', $a_set['position']);
213 $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
214 if (strlen($a_set['description'])) {
215 $this->tpl->setVariable('VAL_DESCRIPTION', $a_set['description']);
216 }
218 if (!count($defs)) {
219 $this->tpl->setVariable('TXT_FIELDS', $this->lng->txt('md_adv_no_fields'));
220 }
221 foreach ($defs as $definition_obj) {
222 $this->tpl->setCurrentBlock('field_entry');
223 $this->tpl->setVariable('FIELD_NAME', $definition_obj->getTitle() .
224 ": " . $this->lng->txt($definition_obj->getTypeTitle()));
225 $this->tpl->parseCurrentBlock();
226 }
227
228 $this->tpl->setVariable('ACTIVE_CHECKED', $a_set['active'] ? ' checked="checked" ' : '');
229 $this->tpl->setVariable('ACTIVE_ID', $a_set['id']);
230
231 if (($a_set["readonly"]) ||
233 $this->tpl->setVariable('ACTIVE_DISABLED', 'disabled="disabled"');
234 }
235
236 if (!$a_set["readonly"]) {
237 $this->ctrl->setParameter($this->parent_obj, 'record_id', $a_set['id']);
238
240 $this->tpl->setVariable('EDIT_LINK', $this->ctrl->getLinkTarget($this->parent_obj, 'editRecord'));
241 $this->tpl->setVariable('TXT_EDIT_RECORD', $this->lng->txt('edit'));
242 }
244 $this->tpl->setVariable(
245 'EDIT_FIELDS_LINK',
246 $this->ctrl->getLinkTarget($this->parent_obj, 'editFields')
247 );
248 $this->tpl->setVariable('TXT_EDIT_FIELDS', $this->lng->txt('md_adv_field_table'));
249 }
250 }
251 }
252}
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
Advanced metadata permission helper.
ilAdvancedMDPermissionHelper $permissions
fillRow(array $a_set)
Standard Version of Fill Row.
numericOrdering(string $a_field)
Should this field be sorted numeric?
__construct( $a_parent_obj, $a_parent_cmd, ilAdvancedMDPermissionHelper $a_permissions, $a_in_object_type_context="")
static _getInstanceByRecordId(int $a_record_id)
static _getAssignableObjectTypes(bool $a_include_text=false)
Get assignable object type @access public.
static formSelect( $selected, string $varname, array $options, bool $multiple=false, bool $direct_text=false, int $size=0, string $style_class="", array $attribs=[], bool $disabled=false)
Builds a select form field with options and shows the selected option first.
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
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)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc