ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
10 
20 {
21  protected $web_res = null;
22  protected $invalid = array();
23 
27  public function __construct($a_parent_obj,$a_parent_cmd)
28  {
29  global $lng,$ilAccess,$ilCtrl;
30 
31  parent::__construct($a_parent_obj,$a_parent_cmd);
32 
33  // Initialize
34  $this->web_res = new ilLinkResourceItems($this->getParentObject()->object->getId());
35 
36 
37  $this->setTitle($lng->txt('webr_edit_links'));
38 
39  $this->addColumn('','','1px');
40  $this->addColumn($this->lng->txt('title'),'title','25%');
41  $this->addColumn($this->lng->txt('target'),'target','25%');
42  $this->addColumn($this->lng->txt('valid'),'valid','10px');
43  $this->addColumn($this->lng->txt('webr_active'),'active','10px');
44  $this->addColumn($this->lng->txt('webr_disable_check'),'disable_check','10px');
45  #$this->addColumn('','','10px');
46 
47  // TODO: Dynamic fields
48 
49  // TODO: sorting
50  $this->setEnableHeader(true);
51  $this->setFormAction($ilCtrl->getFormAction($this->getParentObject()));
52  $this->setRowTemplate("tpl.webr_editable_link_row.html", 'Modules/WebResource');
53  $this->setEnableTitle(true);
54  $this->setEnableNumInfo(true);
55  $this->setSelectAllCheckbox('link_ids');
56 
57  $this->addMultiCommand('confirmDeleteLink', $this->lng->txt('delete'));
58  $this->addCommandButton('updateLinks', $this->lng->txt('save'));
59  }
60 
66  public function setInvalidLinks($a_links)
67  {
68  $this->invalid = $a_links;
69  }
70 
75  public function getInvalidLinks()
76  {
77  return $this->invalid ? $this->invalid : array();
78  }
79 
85  public function parseSelectedLinks($a_link_ids)
86  {
87  $rows = array();
88  foreach($a_link_ids as $link_id)
89  {
90  $link = $this->getWebResourceItems()->getItem($link_id);
91 
92  $tmp['id'] = $link['link_id'];
93  $tmp['title'] = $link['title'];
94  $tmp['description'] = $link['description'];
95  $tmp['target'] = $link['target'];
96  $tmp['link_id'] = $link['link_id'];
97  $tmp['active'] = $link['active'];
98  $tmp['disable_check'] = $link['disable_check'];
99  $tmp['valid'] = $link['valid'];
100  $tmp['last_check'] = $link['last_check'];
101  $tmp['params'] = array();
102 
103  $rows[] = $tmp;
104  }
105  $this->setData($rows);
106  }
107 
108  public function updateFromPost()
109  {
110  $rows = array();
111  foreach($this->getData() as $link)
112  {
113  $link_id = $link['id'];
114 
115  $tmp = $link;
116  $tmp['title'] = $_POST['links'][$link_id]['tit'];
117  $tmp['description'] = $_POST['links'][$link_id]['des'];
118  $tmp['target'] = $_POST['links'][$link_id]['tar'];
119  $tmp['valid'] = $_POST['links'][$link_id]['vali'];
120  $tmp['disable_check'] = $_POST['links'][$link_id]['che'];
121  $tmp['active'] = $_POST['links'][$link_id]['act'];
122  $tmp['value'] = $_POST['links'][$link_id]['val'];
123  $tmp['name'] = $_POST['links'][$link_id]['nam'];
124  $tmp['params'] = array();
125 
126  // var_dump($_POST, $link_id);
127 
128  // var_dump($_POST['tar_'.$link_id.'_ajax_type']);
129  // var_dump($_POST['tar_'.$link_id.'_ajax_id']);
130 
131  $rows[] = $tmp;
132  }
133  $this->setData($rows);
134  }
135 
136 
141  public function parse()
142  {
143  $rows = array();
144 
145  $items = $this->getWebResourceItems()->sortItems(
146  $this->getWebResourceItems()->getAllItems()
147  );
148 
149  foreach($items as $link)
150  {
151  $tmp['id'] = $link['link_id'];
152  $tmp['title'] = $link['title'];
153  $tmp['description'] = $link['description'];
154  $tmp['target'] = $link['target'];
155  $tmp['link_id'] = $link['link_id'];
156  $tmp['active'] = $link['active'];
157  $tmp['disable_check'] = $link['disable_check'];
158  $tmp['valid'] = $link['valid'];
159  $tmp['last_check'] = $link['last_check'];
160 
161  $tmp['params'] = ilParameterAppender::_getParams($link['link_id']);
162 
163  $rows[] = $tmp;
164  }
165  $this->setData($rows);
166  }
167 
171  protected function fillRow($a_set)
172  {
173  global $ilCtrl,$lng;
174 
175  if(!stristr($a_set['target'], '|'))
176  {
177  $this->tpl->setCurrentBlock('external');
178  $this->tpl->setVariable('VAL_ID',$a_set['id']);
179  $this->tpl->setVariable('VAL_TARGET', ilUtil::prepareFormOutput($a_set['target']));
180  $this->tpl->parseCurrentBlock();
181  }
182  else
183  {
184  $ilCtrl->setParameterByClass('ilinternallinkgui', 'postvar','tar_'.$a_set['id']);
185  $trigger_link = array(get_class($this->parent_obj), 'ilinternallinkgui');
186  $trigger_link = $ilCtrl->getLinkTargetByClass($trigger_link, '', false, true, false);
187  $ilCtrl->setParameterByClass('ilinternallinkgui', 'postvar', '');
188 
189  $this->tpl->setCurrentBlock('internal');
190  $this->tpl->setVariable('VAL_ID',$a_set['id']);
191  $this->tpl->setVariable('VAL_TRIGGER_INTERNAL',$trigger_link);
192  $this->tpl->setVariable('TXT_TRIGGER_INTERNAL',$this->lng->txt('edit'));
193 
194  // info about current link
195  if($a_set['target'])
196  {
197  $parts = explode('|', $a_set['target']);
198 
199  $this->tpl->setVariable('VAL_INTERNAL_TYPE',$parts[0]);
200  $this->tpl->setVariable('VAL_INTERNAL_ID',$parts[1]);
201 
202  $parts = ilLinkInputGUI::getTranslatedValue($a_set['target']);
203 
204  $this->tpl->setVariable('TXT_TRIGGER_INFO', $parts['type'].' "'.
205  $parts['name'].'"');
206  }
207 
208  $this->tpl->parseCurrentBlock();
209  }
210 
211  $this->tpl->setVariable('TXT_LAST_CHECK',$this->lng->txt('webr_last_check_table'));
212  $this->tpl->setVariable('LAST_CHECK',
213  $a_set['last_check'] ?
214  ilDatePresentation::formatDate(new ilDateTime($a_set['last_check'],IL_CAL_UNIX)) :
215  $this->lng->txt('no_date')
216  );
217 
218  // Valid
219  $this->tpl->setVariable('VAL_VALID',
220  ilUtil::formCheckbox($a_set['valid'], 'links['.$a_set['id'].'][vali]', 1)
221  );
222 
223  // Active
224  $this->tpl->setVariable('VAL_ACTIVE',
225  ilUtil::formCheckbox($a_set['active'], 'links['.$a_set['id'].'][act]', 1)
226  );
227 
228  // Valid
229  $this->tpl->setVariable('VAL_CHECK',
230  ilUtil::formCheckbox($a_set['disable_check'], 'links['.$a_set['id'].'][che]', 1)
231  );
232 
233  // Dynamic parameters
234  foreach($a_set['params'] as $param_id => $param)
235  {
236  $this->tpl->setCurrentBlock('dyn_del_row');
237  $this->tpl->setVariable('TXT_DYN_DEL',$this->lng->txt('delete'));
238  $ilCtrl->setParameterByClass(get_class($this->getParentObject()),'param_id',$param_id);
239  $this->tpl->setVariable('DYN_DEL_LINK',$ilCtrl->getLinkTarget($this->getParentObject(),'deleteParameter'));
240  $this->tpl->setVariable('VAL_DYN',ilParameterAppender::parameterToInfo($param['name'],$param['value']));
241  $this->tpl->parseCurrentBlock();
242  }
243  if($a_set['params'])
244  {
245  $this->tpl->setCurrentBlock('dyn_del_rows');
246  $this->tpl->setVariable('TXT_EXISTING',$this->lng->txt('links_existing_params'));
247  $this->tpl->parseCurrentBlock();
248  }
249 
251  {
252  $this->tpl->setCurrentBlock('dyn_add');
253  $this->tpl->setVariable('TXT_DYN_ADD',$this->lng->txt('links_add_param'));
254 
255  $this->tpl->setVariable('TXT_DYN_NAME',$this->lng->txt('links_name'));
256  $this->tpl->setVariable('TXT_DYN_VALUE',$this->lng->txt('links_value'));
257  $this->tpl->setVariable('VAL_DYN_NAME',$a_set['name']);
258  $this->tpl->setVariable('DYN_ID',$a_set['id']);
259  $this->tpl->setVariable(
260  'SEL_DYN_VAL',
262  $a_set['value'] ? $a_set['value'] : 0,
263  'links['.$a_set['id'].'][val]',
265  false,
266  true)
267  );
268  $this->tpl->parseCurrentBlock();
269  }
270 
271  if(in_array($a_set['id'], $this->getInvalidLinks()))
272  {
273  $this->tpl->setVariable('CSS_ROW','warn');
274  }
275 
276  // Check
277  $this->tpl->setVariable('VAL_ID',$a_set['id']);
278  $this->tpl->setVariable('VAL_CHECKBOX',
279  ilUtil::formCheckbox(false, 'link_ids[]',$a_set['id'])
280  );
281 
282  // Column title
283  $this->tpl->setVariable('TXT_TITLE',$this->lng->txt('title'));
284  $this->tpl->setVariable('VAL_TITLE',ilUtil::prepareFormOutput($a_set['title']));
285  $this->tpl->setVariable('TXT_DESC',$this->lng->txt('description'));
286  $this->tpl->setVariable('VAL_DESC',ilUtil::prepareFormOutput($a_set['description']));
287 
288  // Column Target
289  $this->tpl->setVariable('TXT_TARGET',$this->lng->txt('target'));
290  }
291 
296  protected function getWebResourceItems()
297  {
298  return $this->web_res;
299  }
300 }
301 ?>