ILIAS  Release_4_1_x_branch Revision 61804
 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 
8 
18 {
19  protected $web_res = null;
20  protected $invalid = array();
21 
25  public function __construct($a_parent_obj,$a_parent_cmd)
26  {
27  global $lng,$ilAccess,$ilCtrl;
28 
29  parent::__construct($a_parent_obj,$a_parent_cmd);
30 
31  // Initialize
32  $this->web_res = new ilLinkResourceItems($this->getParentObject()->object->getId());
33 
34 
35  $this->setTitle($lng->txt('webr_edit_links'));
36 
37  $this->addColumn('','','1px');
38  $this->addColumn($this->lng->txt('title'),'title','25%');
39  $this->addColumn($this->lng->txt('target'),'target','25%');
40  $this->addColumn($this->lng->txt('valid'),'valid','10px');
41  $this->addColumn($this->lng->txt('webr_active'),'active','10px');
42  $this->addColumn($this->lng->txt('webr_disable_check'),'disable_check','10px');
43  #$this->addColumn('','','10px');
44 
45  // TODO: Dynamic fields
46 
47  // TODO: sorting
48  $this->setEnableHeader(true);
49  $this->setFormAction($ilCtrl->getFormAction($this->getParentObject()));
50  $this->setRowTemplate("tpl.webr_editable_link_row.html", 'Modules/WebResource');
51  $this->setEnableTitle(true);
52  $this->setEnableNumInfo(true);
53  $this->setSelectAllCheckbox('link_ids');
54 
55  $this->addMultiCommand('confirmDeleteLink', $this->lng->txt('delete'));
56  $this->addCommandButton('updateLinks', $this->lng->txt('save'));
57  }
58 
64  public function setInvalidLinks($a_links)
65  {
66  $this->invalid = $a_links;
67  }
68 
73  public function getInvalidLinks()
74  {
75  return $this->invalid ? $this->invalid : array();
76  }
77 
83  public function parseSelectedLinks($a_link_ids)
84  {
85  $rows = array();
86  foreach($a_link_ids as $link_id)
87  {
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  {
111  $link_id = $link['id'];
112 
113  $tmp = $link;
114  $tmp['title'] = $_POST['links'][$link_id]['tit'];
115  $tmp['description'] = $_POST['links'][$link_id]['des'];
116  $tmp['target'] = $_POST['links'][$link_id]['tar'];
117  $tmp['valid'] = $_POST['links'][$link_id]['vali'];
118  $tmp['disable_check'] = $_POST['links'][$link_id]['che'];
119  $tmp['active'] = $_POST['links'][$link_id]['act'];
120  $tmp['value'] = $_POST['links'][$link_id]['val'];
121  $tmp['name'] = $_POST['links'][$link_id]['nam'];
122  $tmp['params'] = array();
123 
124  $rows[] = $tmp;
125  }
126  $this->setData($rows);
127  }
128 
129 
134  public function parse()
135  {
136  $rows = array();
137 
138  $items = $this->getWebResourceItems()->sortItems(
139  $this->getWebResourceItems()->getAllItems()
140  );
141 
142  foreach($items as $link)
143  {
144  $tmp['id'] = $link['link_id'];
145  $tmp['title'] = $link['title'];
146  $tmp['description'] = $link['description'];
147  $tmp['target'] = $link['target'];
148  $tmp['link_id'] = $link['link_id'];
149  $tmp['active'] = $link['active'];
150  $tmp['disable_check'] = $link['disable_check'];
151  $tmp['valid'] = $link['valid'];
152  $tmp['last_check'] = $link['last_check'];
153 
154  $tmp['params'] = ilParameterAppender::_getParams($link['link_id']);
155 
156  $rows[] = $tmp;
157  }
158  $this->setData($rows);
159  }
160 
164  protected function fillRow($a_set)
165  {
166  global $ilCtrl,$lng;
167 
168  if(in_array($a_set['id'], $this->getInvalidLinks()))
169  {
170  $this->tpl->setVariable('CSS_ROW','warn');
171  }
172 
173  // Check
174  $this->tpl->setVariable('VAL_ID',$a_set['id']);
175  $this->tpl->setVariable('VAL_CHECKBOX',
176  ilUtil::formCheckbox(false, 'link_ids[]',$a_set['id'])
177  );
178 
179  // Column title
180  $this->tpl->setVariable('TXT_TITLE',$this->lng->txt('title'));
181  $this->tpl->setVariable('VAL_TITLE',$a_set['title']);
182  $this->tpl->setVariable('TXT_DESC',$this->lng->txt('description'));
183  $this->tpl->setVariable('VAL_DESC',$a_set['description']);
184 
185  // Column Target
186  $this->tpl->setVariable('TXT_TARGET',$this->lng->txt('target'));
187  $this->tpl->setVariable('VAL_TARGET',$a_set['target']);
188 
189  $this->tpl->setVariable('TXT_LAST_CHECK',$this->lng->txt('webr_last_check_table'));
190  $this->tpl->setVariable('LAST_CHECK',
191  $a_set['last_check'] ?
192  ilDatePresentation::formatDate(new ilDateTime($a_set['last_check'],IL_CAL_UNIX)) :
193  $this->lng->txt('no_date')
194  );
195 
196  // Valid
197  $this->tpl->setVariable('VAL_VALID',
198  ilUtil::formCheckbox($a_set['valid'], 'links['.$a_set['id'].'][vali]', 1)
199  );
200 
201  // Active
202  $this->tpl->setVariable('VAL_ACTIVE',
203  ilUtil::formCheckbox($a_set['active'], 'links['.$a_set['id'].'][act]', 1)
204  );
205 
206  // Valid
207  $this->tpl->setVariable('VAL_CHECK',
208  ilUtil::formCheckbox($a_set['disable_check'], 'links['.$a_set['id'].'][che]', 1)
209  );
210 
211  // Dynamic parameters
212  foreach($a_set['params'] as $param_id => $param)
213  {
214  $this->tpl->setCurrentBlock('dyn_del_row');
215  $this->tpl->setVariable('TXT_DYN_DEL',$this->lng->txt('delete'));
216  $ilCtrl->setParameterByClass(get_class($this->getParentObject()),'param_id',$param_id);
217  $this->tpl->setVariable('DYN_DEL_LINK',$ilCtrl->getLinkTarget($this->getParentObject(),'deleteParameter'));
218  $this->tpl->setVariable('VAL_DYN',ilParameterAppender::parameterToInfo($param['name'],$param['value']));
219  $this->tpl->parseCurrentBlock();
220  }
221  if($a_set['params'])
222  {
223  $this->tpl->setCurrentBlock('dyn_del_rows');
224  $this->tpl->setVariable('TXT_EXISTING',$this->lng->txt('links_existing_params'));
225  $this->tpl->parseCurrentBlock();
226  }
227 
229  {
230  $this->tpl->setCurrentBlock('dyn_add');
231  $this->tpl->setVariable('TXT_DYN_ADD',$this->lng->txt('links_add_param'));
232 
233  $this->tpl->setVariable('TXT_DYN_NAME',$this->lng->txt('links_name'));
234  $this->tpl->setVariable('TXT_DYN_VALUE',$this->lng->txt('links_value'));
235  $this->tpl->setVariable('VAL_DYN_NAME',$a_set['name']);
236  $this->tpl->setVariable('DYN_ID',$a_set['id']);
237  $this->tpl->setVariable(
238  'SEL_DYN_VAL',
240  $a_set['value'] ? $a_set['value'] : 0,
241  'links['.$a_set['id'].'][val]',
243  false,
244  true)
245  );
246  $this->tpl->parseCurrentBlock();
247  }
248 
249 
250  // Edit
251  /*
252  $ilCtrl->setParameterByClass(get_class($this->getParentObject()), 'link_id', $a_set['id']);
253  $this->tpl->setVariable('EDIT_LINK',
254  $ilCtrl->getLinkTargetByClass(get_class($this->getParentObject()),'editLink')
255  );
256  $ilCtrl->clearParametersByClass(get_class($this->getParentObject()));
257  $this->tpl->setVariable('EDIT_ALT',$this->lng->txt('edit'));
258  */
259 
260  }
261 
262 
263 
264 
269  protected function getWebResourceItems()
270  {
271  return $this->web_res;
272  }
273 }
274 ?>