ILIAS  release_8 Revision v8.24
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'), 'fields');
47 $this->addColumn($this->lng->txt('md_adv_scope'), 'first_scope');
48 $this->addColumn($this->lng->txt('md_obj_types'), '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", "Services/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 foreach ($a_set['obj_types'] as $t) {
107 if ($obj_type["obj_type"] == $t["obj_type"] &&
108 $obj_type["sub_type"] == $t["sub_type"]) {
109 $value = $t["optional"]
110 ? 2
111 : 1;
112
113 if (!$a_set["local"] && $a_set["readonly"]) {
114 // globally mandatory options should be disabled locally
115 if ($value === 1) {
116 $do_disable = true;
117 break;
118 }
119
120 // globally optional, locally selected global records
121 $value = (isset($a_set["local_selected"][$obj_type["obj_type"]]) &&
122 in_array($obj_type["sub_type"], $a_set["local_selected"][$obj_type["obj_type"]]))
123 ? 1
124 : 0;
125 }
126
127 break;
128 }
129 }
130
131 // do only list context types that match the current object type
132 if ($this->in_object_type_context !== "" && $this->in_object_type_context !== $obj_type["obj_type"]) {
133 continue;
134 }
135
136 if (!$do_select && !$value) {
137 continue;
138 }
139
140 if ($do_select) {
141 $this->tpl->setCurrentBlock('ass_obj_types');
142 $this->tpl->setVariable('VAL_OBJ_TYPE', $obj_type["text"]);
143
144 $type_options = $options;
145 switch ($obj_type["obj_type"]) {
146 case "talt":
147 // currently only optional records for talk templates (types)
148 unset($type_options[1]);
149 break;
150 case "rcrs":
151 // optional makes no sense for ecs-courses
152 unset($type_options[2]);
153 break;
154 }
156 $value,
157 "obj_types[" . $a_set['id'] . "][" . $obj_type["obj_type"] . ":" . $obj_type["sub_type"] . "]",
158 $type_options,
159 false,
160 true,
161 0,
162 "",
163 array("style" => "min-width:125px"),
164 $disabled || $do_disable
165 );
166 $this->tpl->setVariable('VAL_OBJ_TYPE_CLASS', $hidden ? 'hidden' : 'std');
167 $this->tpl->setVariable('VAL_OBJ_TYPE_STATUS', $select);
168 $this->tpl->parseCurrentBlock();
169 } else {
170 // only show object type
171 $this->tpl->setCurrentBlock('ass_obj_only');
172 $this->tpl->setVariable('VAL_OBJ_TYPE', $obj_type["text"]);
173 $this->tpl->parseCurrentBlock();
174 }
175 }
176
177 $record = ilAdvancedMDRecord::_getInstanceByRecordId((int) $a_set['id']);
178 if (!$a_set['local'] && count($record->getScopeRefIds())) {
179 $this->tpl->setCurrentBlock('scope_txt');
180 $this->tpl->setVariable('LOCAL_OR_GLOBAL', $this->lng->txt('md_adv_scope_list_header'));
181 $this->tpl->parseCurrentBlock();
182
183 foreach ($record->getScopeRefIds() as $ref_id) {
184 $this->tpl->setCurrentBlock('scope_entry');
185 $this->tpl->setVariable('LINK_HREF', ilLink::_getLink($ref_id));
186 $this->tpl->setVariable('LINK_NAME', ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)));
187 $this->tpl->parseCurrentBlock();
188 }
189 } else {
190 $this->tpl->setCurrentBlock('scope_txt');
191 $this->tpl->setVariable(
192 'LOCAL_OR_GLOBAL',
193 $a_set['local'] ? $this->lng->txt('meta_local') : $this->lng->txt('meta_global')
194 );
195 $this->tpl->parseCurrentBlock();
196 }
197
198 if (!$a_set["readonly"] || $a_set["local"]) {
199 $this->tpl->setCurrentBlock('check_bl');
200 $this->tpl->setVariable('VAL_ID', $a_set['id']);
201 $this->tpl->parseCurrentBlock();
202 }
203
204 $this->tpl->setVariable('R_ID', $a_set['id']);
205 $this->tpl->setVariable('VAL_POS', $a_set['position']);
206 $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
207 if (strlen($a_set['description'])) {
208 $this->tpl->setVariable('VAL_DESCRIPTION', $a_set['description']);
209 }
211 if (!count($defs)) {
212 $this->tpl->setVariable('TXT_FIELDS', $this->lng->txt('md_adv_no_fields'));
213 }
214 foreach ($defs as $definition_obj) {
215 $this->tpl->setCurrentBlock('field_entry');
216 $this->tpl->setVariable('FIELD_NAME', $definition_obj->getTitle() .
217 ": " . $this->lng->txt($definition_obj->getTypeTitle()));
218 $this->tpl->parseCurrentBlock();
219 }
220
221 $this->tpl->setVariable('ACTIVE_CHECKED', $a_set['active'] ? ' checked="checked" ' : '');
222 $this->tpl->setVariable('ACTIVE_ID', $a_set['id']);
223
224 if (($a_set["readonly"]) ||
226 $this->tpl->setVariable('ACTIVE_DISABLED', 'disabled="disabled"');
227 }
228
229 if (!$a_set["readonly"]) {
230 $this->ctrl->setParameter($this->parent_obj, 'record_id', $a_set['id']);
231
233 $this->tpl->setVariable('EDIT_LINK', $this->ctrl->getLinkTarget($this->parent_obj, 'editRecord'));
234 $this->tpl->setVariable('TXT_EDIT_RECORD', $this->lng->txt('edit'));
235 }
237 $this->tpl->setVariable(
238 'EDIT_FIELDS_LINK',
239 $this->ctrl->getLinkTarget($this->parent_obj, 'editFields')
240 );
241 $this->tpl->setVariable('TXT_EDIT_FIELDS', $this->lng->txt('md_adv_field_table'));
242 }
243 }
244 }
245}
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 _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:67
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc