ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDidacticTemplateSettingsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5 
12 {
13  private $ref_id;
14 
16 
17  public function __construct(object $a_parent_obj, string $a_parent_cmd, int $ref_id)
18  {
19  global $DIC;
20  $this->ref_id = $ref_id;
21  parent::__construct($a_parent_obj, $a_parent_cmd);
22  $this->setId('tbl_didactic_tpl_settings');
23 
24  $this->access = $DIC->access();
25  }
26 
30  public function init(): void
31  {
32  $this->addColumn('', 'f', '1px');
33  $this->lng->loadLanguageModule('search');
34  $this->lng->loadLanguageModule('meta');
35  $this->addColumn($this->lng->txt('icon'), '', '5%');
36  $this->addColumn($this->lng->txt('search_title_description'), 'title', '30%');
37  $this->addColumn($this->lng->txt('didactic_applicable_for'), 'applicable', '20%');
38  $this->addColumn($this->lng->txt('didactic_scope'), 'scope', '20%');
39  $this->addColumn($this->lng->txt('active'), 'active', '10%');
40  $this->addColumn($this->lng->txt('actions'), '', '15%');
41 
42  $this->setTitle($this->lng->txt('didactic_available_templates'));
43 
44  if ($this->access->checkAccess('write', '', $this->ref_id)) {
45  $this->addMultiCommand('activateTemplates', $this->lng->txt('activate'));
46  $this->addMultiCommand('deactivateTemplates', $this->lng->txt('deactivate'));
47  $this->addMultiCommand('confirmDelete', $this->lng->txt('delete'));
48 
49  $this->setSelectAllCheckbox('tpls');
50  }
51  $this->setRowTemplate('tpl.didactic_template_overview_row.html', 'Services/DidacticTemplate');
52  $this->setDefaultOrderField('title');
53  $this->setDefaultOrderDirection('asc');
54  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
55  }
56 
60  public function parse(ilDidacticTemplateSettingsTableFilter $filter): void
61  {
63  $tpls->readInactive();
64  $templates = $filter->filter($tpls->getTemplates());
65 
66  $counter = 0;
67  $data = [];
68  foreach ($templates as $tpl) {
69  /* @var $tpl ilDidacticTemplateSetting */
70  $data[$counter]['id'] = $tpl->getId();
71  $data[$counter]['icon'] = $tpl->getIconHandler()->getAbsolutePath();
72  $data[$counter]['title'] = $tpl->getPresentationTitle();
73  $data[$counter]['description'] = $tpl->getPresentationDescription();
74  $data[$counter]['info'] = $tpl->getInfo();
75  $data[$counter]['enabled'] = (int) $tpl->isEnabled();
76  $data[$counter]['assignments'] = $tpl->getAssignments();
77 
78  $atxt = '';
79  foreach ($tpl->getAssignments() as $obj_type) {
80  $atxt .= ($this->lng->txt('objs_' . $obj_type) . '<br/>');
81  }
82  $data[$counter]['applicable'] = $atxt;
83  $data[$counter]['automatic_generated'] = $tpl->isAutoGenerated();
84  $data[$counter]['scope'] = (array) $tpl->getEffectiveFrom();
85 
86  ++$counter;
87  }
88 
89  $this->setData($data);
90  }
91 
92  protected function fillRow(array $a_set): void
93  {
94  if ($this->access->checkAccess('write', '', $this->ref_id)) {
95  $this->tpl->setVariable('VAL_ID', $a_set['id']);
96  }
97 
98  $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
99  $this->tpl->setVariable('VAL_DESC', $a_set['description']);
100 
101  if (($a_set['icon'] ?? '') !== '') {
102  $this->tpl->setVariable('ICON_SRC', $a_set['icon']);
103  foreach ((array) $a_set['assignments'] as $obj_type) {
104  $this->tpl->setVariable('ICON_ALT', $this->lng->txt('objs_' . $obj_type));
105  }
106  }
107 
108  foreach ((array) explode("\n", $a_set['info']) as $info) {
109  $trimmed_info = trim($info);
110  if ($trimmed_info) {
111  $this->tpl->setCurrentBlock('info');
112  $this->tpl->setVariable('VAL_INFO', $trimmed_info);
113  $this->tpl->parseCurrentBlock();
114  }
115  }
116 
117  if ($a_set['automatic_generated']) {
118  $this->tpl->setVariable("VAL_AUTOMATIC_GENERATED", $this->lng->txt("didactic_auto_generated"));
119  }
120 
121  $this->tpl->setVariable(
122  'VAL_IMAGE',
123  $a_set['enabled'] ?
124  ilUtil::getImagePath('icon_ok.svg') :
125  ilUtil::getImagePath('icon_not_ok.svg')
126  );
127  $this->tpl->setVariable(
128  'VAL_ENABLED_TXT',
129  $a_set['enabled'] ?
130  $this->lng->txt('active') :
131  $this->lng->txt('inactive')
132  );
133 
134  $atxt = '';
135  foreach ((array) $a_set['assignments'] as $obj_type) {
136  $atxt .= ($this->lng->txt('objs_' . $obj_type) . '<br/>');
137  }
138  $this->tpl->setVariable('VAL_APPLICABLE', $atxt);
139 
140  $this->ctrl->setParameterByClass(
141  get_class($this->getParentObject()),
142  'tplid',
143  $a_set['id']
144  );
145 
146  if (count($a_set['scope'])) {
147  $this->tpl->setCurrentBlock('scope_txt');
148  $this->tpl->setVariable('LOCAL_OR_GLOBAL', $this->lng->txt('didactic_scope_list_header'));
149  $this->tpl->parseCurrentBlock();
150 
151  foreach ($a_set['scope'] as $ref_id) {
152  $this->tpl->setCurrentBlock('scope_entry');
153  $this->tpl->setVariable('LINK_HREF', ilLink::_getLink($ref_id));
154  $this->tpl->setVariable('LINK_NAME', ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)));
155  $this->tpl->parseCurrentBlock();
156  }
157  } else {
158  $this->tpl->setCurrentBlock('scope_txt');
159  $this->tpl->setVariable(
160  'LOCAL_OR_GLOBAL',
161  isset($a_set['local']) ? $this->lng->txt('meta_local') : $this->lng->txt('meta_global')
162  );
163  $this->tpl->parseCurrentBlock();
164  }
165 
166  if ($this->access->checkAccess('write', '', $this->ref_id)) {
167  $actions = new ilAdvancedSelectionListGUI();
168  $actions->setId((string) $a_set['id']);
169  $actions->setListTitle($this->lng->txt("actions"));
170  // Edit
171  $actions->addItem(
172  $this->lng->txt('settings'),
173  '',
174  $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'editTemplate')
175  );
176 
177  // Copy
178  $actions->addItem(
179  $this->lng->txt('copy'),
180  '',
181  $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'copyTemplate')
182  );
183 
184  // Export
185  if (!$a_set['automatic_generated']) {
186  $actions->addItem(
187  $this->lng->txt('didactic_do_export'),
188  '',
189  $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'exportTemplate')
190  );
191  }
192  $this->tpl->setVariable('ACTION_DROPDOWN', $actions->getHTML());
193  } elseif (!$a_set['automatic_generated']) {
194  //don't use dropdown if just one item is given ...
195  // Export
196  $this->tpl->setCurrentBlock('action_link');
197  $this->tpl->setVariable(
198  'A_LINK',
199  $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'exportTemplate')
200  );
201  $this->tpl->setVariable('A_TEXT', $this->lng->txt('didactic_do_export'));
202  $this->tpl->parseCurrentBlock();
203  } else {
204  $this->tpl->touchBlock('action_link');
205  }
206  }
207 }
setData(array $a_data)
Description of ilDidacticTemplateSettingsTableGUI.
setFormAction(string $a_form_action, bool $a_multipart=false)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
setId(string $a_val)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
static _lookupTitle(int $obj_id)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
__construct(object $a_parent_obj, string $a_parent_cmd, int $ref_id)
__construct(Container $dic, ilPlugin $plugin)
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)
parse(ilDidacticTemplateSettingsTableFilter $filter)
Parse didactic templates.
addMultiCommand(string $a_cmd, string $a_text)