ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAdvancedMDRecordTableGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13include_once('Services/Table/classes/class.ilTable2GUI.php');
14include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
15
17{
18 protected $lng = null;
19 protected $ctrl;
20 protected $permissions; // [ilAdvancedMDPermissionHelper]
21
29 public function __construct($a_parent_obj, $a_parent_cmd = '', ilAdvancedMDPermissionHelper $a_permissions, $a_in_object_context = false)
30 {
31 global $DIC;
32
33 $lng = $DIC['lng'];
34 $ilCtrl = $DIC['ilCtrl'];
35
36 $this->lng = $lng;
37 $this->ctrl = $ilCtrl;
38 $this->permissions = $a_permissions;
39
40 $this->setId('adv_md_records_tbl');
41 parent::__construct($a_parent_obj, $a_parent_cmd);
42 $this->addColumn('', '', 1);
43 $this->addColumn($this->lng->txt('md_adv_col_presentation_ordering'), 'position');
44 $this->addColumn($this->lng->txt('title'), 'title');
45 $this->addColumn($this->lng->txt('md_fields'), 'fields');
46 $this->addColumn($this->lng->txt('md_adv_scope'), 'scope');
47 $this->addColumn($this->lng->txt('md_obj_types'), 'obj_types');
48 $this->addColumn($this->lng->txt('md_adv_active'), 'active');
49
50 $this->addColumn($this->lng->txt('actions'));
51
52 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
53 $this->setRowTemplate("tpl.show_records_row.html", "Services/AdvancedMetaData");
54 $this->setDefaultOrderField('position');
55 $this->setDefaultOrderDirection('asc');
56 $this->setShowRowsSelector(true);
57 }
58
63 public function numericOrdering($a_field)
64 {
65 if ($a_field == 'position') {
66 return true;
67 }
68 return parent::numericOrdering($a_field);
69 }
70
78 public function fillRow($a_set)
79 {
80 // assigned object types
82 $options = array(
83 0 => $this->lng->txt("meta_obj_type_inactive"),
84 1 => $this->lng->txt("meta_obj_type_mandatory"),
85 2 => $this->lng->txt("meta_obj_type_optional")
86 );
87
88 $do_select = (!$a_set["readonly"] && !$a_set["local"]);
89 foreach (ilAdvancedMDRecord::_getAssignableObjectTypes(true) as $obj_type) {
90 $value = 0;
91 foreach ($a_set['obj_types'] as $t) {
92 if ($obj_type["obj_type"] == $t["obj_type"] &&
93 $obj_type["sub_type"] == $t["sub_type"]) {
94 if ($t["context"] &&
95 !$a_set["local"]) {
96 $obj_type["text"] = '<span class="il_ItemAlertProperty">' . $obj_type["text"] . '</span>';
97 }
98
99 $value = $t["optional"]
100 ? 2
101 : 1;
102 break;
103 }
104 }
105
106 if (!$do_select && !$value) {
107 continue;
108 }
109
110
111 if ($do_select) {
112 $this->tpl->setCurrentBlock('ass_obj_types');
113 $this->tpl->setVariable('VAL_OBJ_TYPE', $obj_type["text"]);
114
115 $type_options = $options;
116 switch ($obj_type["obj_type"]) {
117 case "orgu":
118 // currently only optional records for org unit (types)
119 unset($type_options[1]);
120 break;
121 case "prg":
122 // currently only optional records for study programme (types)
123 unset($type_options[1]);
124 break;
125 case "rcrs":
126 // optional makes no sense for ecs-courses
127 unset($type_options[2]);
128 break;
129 }
130 $select = ilUtil::formSelect(
131 $value,
132 "obj_types[" . $a_set['id'] . "][" . $obj_type["obj_type"] . ":" . $obj_type["sub_type"] . "]",
133 $type_options,
134 false,
135 true,
136 0,
137 "",
138 array("style" => "min-width:125px"),
139 $disabled
140 );
141 $this->tpl->setVariable('VAL_OBJ_TYPE_STATUS', $select);
142 $this->tpl->parseCurrentBlock();
143 } else {
144 // only show object type
145 $this->tpl->setCurrentBlock('ass_obj_only');
146 $this->tpl->setVariable('VAL_OBJ_TYPE', $obj_type["text"]);
147 $this->tpl->parseCurrentBlock();
148 }
149 }
150
151 $record = ilAdvancedMDRecord::_getInstanceByRecordId($a_set['id']);
152 if (!$a_set['local'] && count($record->getScopeRefIds())) {
153 $this->tpl->setCurrentBlock('scope_txt');
154 $this->tpl->setVariable('LOCAL_OR_GLOBAL', $this->lng->txt('md_adv_scope_list_header'));
155 $this->tpl->parseCurrentBlock();
156
157 foreach ($record->getScopeRefIds() as $ref_id) {
158 $this->tpl->setCurrentBlock('scope_entry');
159 $this->tpl->setVariable('LINK_HREF', ilLink::_getLink($ref_id));
160 $this->tpl->setVariable('LINK_NAME', ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)));
161 $this->tpl->parseCurrentBlock();
162 }
163 } else {
164 $this->tpl->setCurrentBlock('scope_txt');
165 $this->tpl->setVariable('LOCAL_OR_GLOBAL', $a_set['local'] ? $this->lng->txt('meta_local') : $this->lng->txt('meta_global'));
166 $this->tpl->parseCurrentBlock();
167 }
168
169 if (!$a_set["readonly"] || $a_set["local"]) {
170 $this->tpl->setCurrentBlock('check_bl');
171 $this->tpl->setVariable('VAL_ID', $a_set['id']);
172 $this->tpl->parseCurrentBlock();
173 }
174
175
176 $this->tpl->setVariable('R_ID', $a_set['id']);
177 $this->tpl->setVariable('VAL_POS', $a_set['position']);
178 $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
179 if (strlen($a_set['description'])) {
180 $this->tpl->setVariable('VAL_DESCRIPTION', $a_set['description']);
181 }
183 if (!count($defs)) {
184 $this->tpl->setVariable('TXT_FIELDS', $this->lng->txt('md_adv_no_fields'));
185 }
186 foreach ($defs as $definition_obj) {
187 $this->tpl->setCurrentBlock('field_entry');
188 $this->tpl->setVariable('FIELD_NAME', $definition_obj->getTitle() .
189 ": " . $this->lng->txt($definition_obj->getTypeTitle()));
190 $this->tpl->parseCurrentBlock();
191 }
192
193 $this->tpl->setVariable('ACTIVE_CHECKED', $a_set['active'] ? ' checked="checked" ' : '');
194 $this->tpl->setVariable('ACTIVE_ID', $a_set['id']);
195
196 if (($a_set["readonly"] && !$a_set["optional"]) ||
198 $this->tpl->setVariable('ACTIVE_DISABLED', 'disabled="disabled"');
199 }
200
201 if (!$a_set["readonly"]) {
202 $this->ctrl->setParameter($this->parent_obj, 'record_id', $a_set['id']);
203
205 $this->tpl->setVariable('EDIT_LINK', $this->ctrl->getLinkTarget($this->parent_obj, 'editRecord'));
206 $this->tpl->setVariable('TXT_EDIT_RECORD', $this->lng->txt('edit'));
207 }
209 $this->tpl->setVariable('EDIT_FIELDS_LINK', $this->ctrl->getLinkTarget($this->parent_obj, 'editFields'));
210 $this->tpl->setVariable('TXT_EDIT_FIELDS', $this->lng->txt('md_adv_field_table'));
211 }
212 }
213 }
214}
An exception for terminatinating execution or to throw for unit testing.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
Advanced metadata permission helper.
__construct($a_parent_obj, $a_parent_cmd='', ilAdvancedMDPermissionHelper $a_permissions, $a_in_object_context=false)
Constructor.
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
static _getAssignableObjectTypes($a_include_text=false)
Get assignable object type.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
Class ilTable2GUI.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
static formSelect( $selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc