ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilWebResourceEditableLinkTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Table/classes/class.ilTable2GUI.php';
5 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
6 include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
7 include_once './Services/Form/classes/class.ilFormPropertyGUI.php';
8 include_once './Services/Form/classes/class.ilLinkInputGUI.php';
9 
19 {
20  protected $web_res = null;
21  protected $invalid = array();
22 
26  public function __construct($a_parent_obj, $a_parent_cmd)
27  {
28  global $lng,$ilAccess,$ilCtrl;
29 
30  parent::__construct($a_parent_obj, $a_parent_cmd);
31 
32  // Initialize
33  $this->web_res = new ilLinkResourceItems($this->getParentObject()->object->getId());
34 
35 
36  $this->setTitle($lng->txt('webr_edit_links'));
37 
38  $this->addColumn('', '', '1px');
39  $this->addColumn($this->lng->txt('title'), 'title', '25%');
40  $this->addColumn($this->lng->txt('target'), 'target', '25%');
41  $this->addColumn($this->lng->txt('valid'), 'valid', '10px');
42  $this->addColumn($this->lng->txt('webr_active'), 'active', '10px');
43  $this->addColumn($this->lng->txt('webr_disable_check'), 'disable_check', '10px');
44  #$this->addColumn('','','10px');
45 
46  // TODO: Dynamic fields
47 
48  // TODO: sorting
49  $this->setEnableHeader(true);
50  $this->setFormAction($ilCtrl->getFormAction($this->getParentObject()));
51  $this->setRowTemplate("tpl.webr_editable_link_row.html", 'Modules/WebResource');
52  $this->setEnableTitle(true);
53  $this->setEnableNumInfo(true);
54  $this->setSelectAllCheckbox('link_ids');
55 
56  $this->addMultiCommand('confirmDeleteLink', $this->lng->txt('delete'));
57  $this->addCommandButton('updateLinks', $this->lng->txt('save'));
58  }
59 
65  public function setInvalidLinks($a_links)
66  {
67  $this->invalid = $a_links;
68  }
69 
74  public function getInvalidLinks()
75  {
76  return $this->invalid ? $this->invalid : array();
77  }
78 
84  public function parseSelectedLinks($a_link_ids)
85  {
86  $rows = array();
87  foreach ($a_link_ids as $link_id) {
88  $link = $this->getWebResourceItems()->getItem($link_id);
89 
90  $tmp['id'] = $link['link_id'];
91  $tmp['title'] = $link['title'];
92  $tmp['description'] = $link['description'];
93  $tmp['target'] = $link['target'];
94  $tmp['link_id'] = $link['link_id'];
95  $tmp['active'] = $link['active'];
96  $tmp['disable_check'] = $link['disable_check'];
97  $tmp['valid'] = $link['valid'];
98  $tmp['last_check'] = $link['last_check'];
99  $tmp['params'] = array();
100 
101  $rows[] = $tmp;
102  }
103  $this->setData($rows);
104  }
105 
106  public function updateFromPost()
107  {
108  $rows = array();
109  foreach ($this->getData() as $link) {
110  $link_id = $link['id'];
111 
112  $tmp = $link;
113  $tmp['title'] = $_POST['links'][$link_id]['tit'];
114  $tmp['description'] = $_POST['links'][$link_id]['des'];
115  $tmp['target'] = $_POST['links'][$link_id]['tar'];
116  $tmp['valid'] = $_POST['links'][$link_id]['vali'];
117  $tmp['disable_check'] = $_POST['links'][$link_id]['che'];
118  $tmp['active'] = $_POST['links'][$link_id]['act'];
119  $tmp['value'] = $_POST['links'][$link_id]['val'];
120  $tmp['name'] = $_POST['links'][$link_id]['nam'];
121  $tmp['params'] = array();
122 
123  // var_dump($_POST, $link_id);
124 
125  // var_dump($_POST['tar_'.$link_id.'_ajax_type']);
126  // var_dump($_POST['tar_'.$link_id.'_ajax_id']);
127 
128  $rows[] = $tmp;
129  }
130  $this->setData($rows);
131  }
132 
133 
138  public function parse()
139  {
140  $rows = array();
141 
142  $items = $this->getWebResourceItems()->sortItems(
143  $this->getWebResourceItems()->getAllItems()
144  );
145 
146  foreach ($items as $link) {
147  $tmp['id'] = $link['link_id'];
148  $tmp['title'] = $link['title'];
149  $tmp['description'] = $link['description'];
150  $tmp['target'] = $link['target'];
151  $tmp['link_id'] = $link['link_id'];
152  $tmp['active'] = $link['active'];
153  $tmp['disable_check'] = $link['disable_check'];
154  $tmp['valid'] = $link['valid'];
155  $tmp['last_check'] = $link['last_check'];
156 
157  $tmp['params'] = ilParameterAppender::_getParams($link['link_id']);
158 
159  $rows[] = $tmp;
160  }
161  $this->setData($rows);
162  }
163 
167  protected function fillRow($a_set)
168  {
169  global $ilCtrl,$lng;
170 
171  if (!stristr($a_set['target'], '|')) {
172  $this->tpl->setCurrentBlock('external');
173  $this->tpl->setVariable('VAL_ID', $a_set['id']);
174  $this->tpl->setVariable('VAL_TARGET', ilUtil::prepareFormOutput($a_set['target']));
175  $this->tpl->parseCurrentBlock();
176  } else {
177  $ilCtrl->setParameterByClass('ilinternallinkgui', 'postvar', 'tar_' . $a_set['id']);
178  $trigger_link = array(get_class($this->parent_obj), 'ilinternallinkgui');
179  $trigger_link = $ilCtrl->getLinkTargetByClass($trigger_link, '', false, true, false);
180  $ilCtrl->setParameterByClass('ilinternallinkgui', 'postvar', '');
181 
182  $this->tpl->setCurrentBlock('internal');
183  $this->tpl->setVariable('VAL_ID', $a_set['id']);
184  $this->tpl->setVariable('VAL_TRIGGER_INTERNAL', $trigger_link);
185  $this->tpl->setVariable('TXT_TRIGGER_INTERNAL', $this->lng->txt('edit'));
186 
187  // info about current link
188  if ($a_set['target']) {
189  $parts = explode('|', $a_set['target']);
190 
191  $this->tpl->setVariable('VAL_INTERNAL_TYPE', $parts[0]);
192  $this->tpl->setVariable('VAL_INTERNAL_ID', $parts[1]);
193 
194  $parts = ilLinkInputGUI::getTranslatedValue($a_set['target']);
195 
196  $this->tpl->setVariable('TXT_TRIGGER_INFO', $parts['type'] . ' "' .
197  $parts['name'] . '"');
198  }
199 
200  $this->tpl->parseCurrentBlock();
201  }
202 
203  $this->tpl->setVariable('TXT_LAST_CHECK', $this->lng->txt('webr_last_check_table'));
204  $this->tpl->setVariable(
205  'LAST_CHECK',
206  $a_set['last_check'] ?
207  ilDatePresentation::formatDate(new ilDateTime($a_set['last_check'], IL_CAL_UNIX)) :
208  $this->lng->txt('no_date')
209  );
210 
211  // Valid
212  $this->tpl->setVariable(
213  'VAL_VALID',
214  ilUtil::formCheckbox($a_set['valid'], 'links[' . $a_set['id'] . '][vali]', 1)
215  );
216 
217  // Active
218  $this->tpl->setVariable(
219  'VAL_ACTIVE',
220  ilUtil::formCheckbox($a_set['active'], 'links[' . $a_set['id'] . '][act]', 1)
221  );
222 
223  // Valid
224  $this->tpl->setVariable(
225  'VAL_CHECK',
226  ilUtil::formCheckbox($a_set['disable_check'], 'links[' . $a_set['id'] . '][che]', 1)
227  );
228 
229  // Dynamic parameters
230  foreach ($a_set['params'] as $param_id => $param) {
231  $this->tpl->setCurrentBlock('dyn_del_row');
232  $this->tpl->setVariable('TXT_DYN_DEL', $this->lng->txt('delete'));
233  $ilCtrl->setParameterByClass(get_class($this->getParentObject()), 'param_id', $param_id);
234  $this->tpl->setVariable('DYN_DEL_LINK', $ilCtrl->getLinkTarget($this->getParentObject(), 'deleteParameter'));
235  $this->tpl->setVariable('VAL_DYN', ilParameterAppender::parameterToInfo($param['name'], $param['value']));
236  $this->tpl->parseCurrentBlock();
237  }
238  if ($a_set['params']) {
239  $this->tpl->setCurrentBlock('dyn_del_rows');
240  $this->tpl->setVariable('TXT_EXISTING', $this->lng->txt('links_existing_params'));
241  $this->tpl->parseCurrentBlock();
242  }
243 
245  $this->tpl->setCurrentBlock('dyn_add');
246  $this->tpl->setVariable('TXT_DYN_ADD', $this->lng->txt('links_add_param'));
247 
248  $this->tpl->setVariable('TXT_DYN_NAME', $this->lng->txt('links_name'));
249  $this->tpl->setVariable('TXT_DYN_VALUE', $this->lng->txt('links_value'));
250  $this->tpl->setVariable('VAL_DYN_NAME', $a_set['name']);
251  $this->tpl->setVariable('DYN_ID', $a_set['id']);
252  $this->tpl->setVariable(
253  'SEL_DYN_VAL',
255  $a_set['value'] ? $a_set['value'] : 0,
256  'links[' . $a_set['id'] . '][val]',
258  false,
259  true
260  )
261  );
262  $this->tpl->parseCurrentBlock();
263  }
264 
265  if (in_array($a_set['id'], $this->getInvalidLinks())) {
266  $this->tpl->setVariable('CSS_ROW', 'warn');
267  }
268 
269  // Check
270  $this->tpl->setVariable('VAL_ID', $a_set['id']);
271  $this->tpl->setVariable(
272  'VAL_CHECKBOX',
273  ilUtil::formCheckbox(false, 'link_ids[]', $a_set['id'])
274  );
275 
276  // Column title
277  $this->tpl->setVariable('TXT_TITLE', $this->lng->txt('title'));
278  $this->tpl->setVariable('VAL_TITLE', ilUtil::prepareFormOutput($a_set['title']));
279  $this->tpl->setVariable('TXT_DESC', $this->lng->txt('description'));
280  $this->tpl->setVariable('VAL_DESC', ilUtil::prepareFormOutput($a_set['description']));
281 
282  // Column Target
283  $this->tpl->setVariable('TXT_TARGET', $this->lng->txt('target'));
284  }
285 
290  protected function getWebResourceItems()
291  {
292  return $this->web_res;
293  }
294 }
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static getTranslatedValue($a_value)
setEnableNumInfo($a_val)
Set enable num info.
static _getOptionSelect()
Get options as array.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
__construct($a_parent_obj, $a_parent_cmd)
Constructor.
const IL_CAL_UNIX
getParentObject()
Get parent object.
global $ilCtrl
Definition: ilias.php:18
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
static parameterToInfo($a_name, $a_value)
Get info text describing an existing dynamic link.
Class ilTable2GUI.
addMultiCommand($a_cmd, $a_text)
Add Command button.
Date and time handling
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
$rows
Definition: xhr_table.php:10
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
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.
Create new PHPExcel object
obj_idprivate
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.
Class ilObjLinkResourceGUI.
setEnableHeader($a_enableheader)
Set Enable Header.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
setEnableTitle($a_enabletitle)
Set Enable Title.
static _getParams($a_link_id)
Get dynamic parameter definitions.
static _isEnabled()
Check if dynamic parameters are enabled.
$_POST["username"]
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public