ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
13 include_once('Services/Table/classes/class.ilTable2GUI.php');
14 include_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  parent::__construct($a_parent_obj, $a_parent_cmd);
41  $this->addColumn('', '', 1);
42  $this->addColumn($this->lng->txt('md_adv_col_presentation_ordering'), 'sort');
43  $this->addColumn($this->lng->txt('title'), 'title');
44  $this->addColumn($this->lng->txt('md_fields'), 'fields');
45  $this->addColumn($this->lng->txt('md_adv_scope'), 'scope');
46  $this->addColumn($this->lng->txt('md_obj_types'), 'obj_types');
47  $this->addColumn($this->lng->txt('md_adv_active'), 'active');
48 
49  $this->addColumn($this->lng->txt('actions'));
50 
51  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
52  $this->setRowTemplate("tpl.show_records_row.html", "Services/AdvancedMetaData");
53  $this->setDefaultOrderField('position');
54  $this->setDefaultOrderDirection('asc');
55  }
56 
64  public function fillRow($a_set)
65  {
66  // assigned object types
68  $options = array(
69  0 => $this->lng->txt("meta_obj_type_inactive"),
70  1 => $this->lng->txt("meta_obj_type_mandatory"),
71  2 => $this->lng->txt("meta_obj_type_optional")
72  );
73 
74  $do_select = (!$a_set["readonly"] && !$a_set["local"]);
75  foreach (ilAdvancedMDRecord::_getAssignableObjectTypes(true) as $obj_type) {
76  $value = 0;
77  foreach ($a_set['obj_types'] as $t) {
78  if ($obj_type["obj_type"] == $t["obj_type"] &&
79  $obj_type["sub_type"] == $t["sub_type"]) {
80  if ($t["context"] &&
81  !$a_set["local"]) {
82  $obj_type["text"] = '<span class="il_ItemAlertProperty">' . $obj_type["text"] . '</span>';
83  }
84 
85  $value = $t["optional"]
86  ? 2
87  : 1;
88  break;
89  }
90  }
91 
92  if (!$do_select && !$value) {
93  continue;
94  }
95 
96 
97  if ($do_select) {
98  $this->tpl->setCurrentBlock('ass_obj_types');
99  $this->tpl->setVariable('VAL_OBJ_TYPE', $obj_type["text"]);
100 
101  $type_options = $options;
102  switch ($obj_type["obj_type"]) {
103  case "orgu":
104  // currently only optional records for org unit (types)
105  unset($type_options[1]);
106  break;
107  case "prg":
108  // currently only optional records for study programme (types)
109  unset($type_options[1]);
110  break;
111  case "rcrs":
112  // optional makes no sense for ecs-courses
113  unset($type_options[2]);
114  break;
115  }
116  $select = ilUtil::formSelect(
117  $value,
118  "obj_types[" . $a_set['id'] . "][" . $obj_type["obj_type"] . ":" . $obj_type["sub_type"] . "]",
119  $type_options,
120  false,
121  true,
122  0,
123  "",
124  array("style" => "min-width:125px"),
125  $disabled
126  );
127  $this->tpl->setVariable('VAL_OBJ_TYPE_STATUS', $select);
128  $this->tpl->parseCurrentBlock();
129  } else {
130  // only show object type
131  $this->tpl->setCurrentBlock('ass_obj_only');
132  $this->tpl->setVariable('VAL_OBJ_TYPE', $obj_type["text"]);
133  $this->tpl->parseCurrentBlock();
134  }
135  }
136 
137  $record = ilAdvancedMDRecord::_getInstanceByRecordId($a_set['id']);
138  if (!$a_set['local'] && count($record->getScopeRefIds())) {
139  $this->tpl->setCurrentBlock('scope_txt');
140  $this->tpl->setVariable('LOCAL_OR_GLOBAL', $this->lng->txt('md_adv_scope_list_header'));
141  $this->tpl->parseCurrentBlock();
142 
143  foreach ($record->getScopeRefIds() as $ref_id) {
144  $this->tpl->setCurrentBlock('scope_entry');
145  $this->tpl->setVariable('LINK_HREF', ilLink::_getLink($ref_id));
146  $this->tpl->setVariable('LINK_NAME', ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)));
147  $this->tpl->parseCurrentBlock();
148  }
149  } else {
150  $this->tpl->setCurrentBlock('scope_txt');
151  $this->tpl->setVariable('LOCAL_OR_GLOBAL', $a_set['local'] ? $this->lng->txt('meta_local') : $this->lng->txt('meta_global'));
152  $this->tpl->parseCurrentBlock();
153  }
154 
155  if (!$a_set["readonly"] || $a_set["local"]) {
156  $this->tpl->setCurrentBlock('check_bl');
157  $this->tpl->setVariable('VAL_ID', $a_set['id']);
158  $this->tpl->parseCurrentBlock();
159  }
160 
161 
162  $this->tpl->setVariable('R_ID', $a_set['id']);
163  $this->tpl->setVariable('VAL_POS', $a_set['position']);
164  $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
165  if (strlen($a_set['description'])) {
166  $this->tpl->setVariable('VAL_DESCRIPTION', $a_set['description']);
167  }
169  if (!count($defs)) {
170  $this->tpl->setVariable('TXT_FIELDS', $this->lng->txt('md_adv_no_fields'));
171  }
172  foreach ($defs as $definition_obj) {
173  $this->tpl->setCurrentBlock('field_entry');
174  $this->tpl->setVariable('FIELD_NAME', $definition_obj->getTitle() .
175  ": " . $this->lng->txt($definition_obj->getTypeTitle()));
176  $this->tpl->parseCurrentBlock();
177  }
178 
179  $this->tpl->setVariable('ACTIVE_CHECKED', $a_set['active'] ? ' checked="checked" ' : '');
180  $this->tpl->setVariable('ACTIVE_ID', $a_set['id']);
181 
182  if (($a_set["readonly"] && !$a_set["optional"]) ||
184  $this->tpl->setVariable('ACTIVE_DISABLED', 'disabled="disabled"');
185  }
186 
187  if (!$a_set["readonly"]) {
188  $this->ctrl->setParameter($this->parent_obj, 'record_id', $a_set['id']);
189 
191  $this->tpl->setVariable('EDIT_LINK', $this->ctrl->getLinkTarget($this->parent_obj, 'editRecord'));
192  $this->tpl->setVariable('TXT_EDIT_RECORD', $this->lng->txt('edit'));
193  }
195  $this->tpl->setVariable('EDIT_FIELDS_LINK', $this->ctrl->getLinkTarget($this->parent_obj, 'editFields'));
196  $this->tpl->setVariable('TXT_EDIT_FIELDS', $this->lng->txt('md_adv_field_table'));
197  }
198  }
199  }
200 }
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
global $DIC
Definition: saml.php:7
static _lookupTitle($a_id)
lookup object title
global $ilCtrl
Definition: ilias.php:18
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
Class ilTable2GUI.
Advanced metadata permission helper.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
static _lookupObjId($a_id)
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
static _getAssignableObjectTypes($a_include_text=false)
Get assignable object type.
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.
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.
__construct($a_parent_obj, $a_parent_cmd='', ilAdvancedMDPermissionHelper $a_permissions, $a_in_object_context=false)
Constructor.