ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4include_once './Services/Table/classes/class.ilTable2GUI.php';
5include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
6include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
7include_once './Services/Form/classes/class.ilFormPropertyGUI.php';
8include_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 {
89 $link = $this->getWebResourceItems()->getItem($link_id);
90
91 $tmp['id'] = $link['link_id'];
92 $tmp['title'] = $link['title'];
93 $tmp['description'] = $link['description'];
94 $tmp['target'] = $link['target'];
95 $tmp['link_id'] = $link['link_id'];
96 $tmp['active'] = $link['active'];
97 $tmp['disable_check'] = $link['disable_check'];
98 $tmp['valid'] = $link['valid'];
99 $tmp['last_check'] = $link['last_check'];
100 $tmp['params'] = array();
101
102 $rows[] = $tmp;
103 }
104 $this->setData($rows);
105 }
106
107 public function updateFromPost()
108 {
109 $rows = array();
110 foreach($this->getData() as $link)
111 {
112 $link_id = $link['id'];
113
114 $tmp = $link;
115 $tmp['title'] = $_POST['links'][$link_id]['tit'];
116 $tmp['description'] = $_POST['links'][$link_id]['des'];
117 $tmp['target'] = $_POST['links'][$link_id]['tar'];
118 $tmp['valid'] = $_POST['links'][$link_id]['vali'];
119 $tmp['disable_check'] = $_POST['links'][$link_id]['che'];
120 $tmp['active'] = $_POST['links'][$link_id]['act'];
121 $tmp['value'] = $_POST['links'][$link_id]['val'];
122 $tmp['name'] = $_POST['links'][$link_id]['nam'];
123 $tmp['params'] = array();
124
125 // var_dump($_POST, $link_id);
126
127 // var_dump($_POST['tar_'.$link_id.'_ajax_type']);
128 // var_dump($_POST['tar_'.$link_id.'_ajax_id']);
129
130 $rows[] = $tmp;
131 }
132 $this->setData($rows);
133 }
134
135
140 public function parse()
141 {
142 $rows = array();
143
144 $items = $this->getWebResourceItems()->sortItems(
145 $this->getWebResourceItems()->getAllItems()
146 );
147
148 foreach($items as $link)
149 {
150 $tmp['id'] = $link['link_id'];
151 $tmp['title'] = $link['title'];
152 $tmp['description'] = $link['description'];
153 $tmp['target'] = $link['target'];
154 $tmp['link_id'] = $link['link_id'];
155 $tmp['active'] = $link['active'];
156 $tmp['disable_check'] = $link['disable_check'];
157 $tmp['valid'] = $link['valid'];
158 $tmp['last_check'] = $link['last_check'];
159
160 $tmp['params'] = ilParameterAppender::_getParams($link['link_id']);
161
162 $rows[] = $tmp;
163 }
164 $this->setData($rows);
165 }
166
170 protected function fillRow($a_set)
171 {
172 global $ilCtrl,$lng;
173
174 if(!stristr($a_set['target'], '|'))
175 {
176 $this->tpl->setCurrentBlock('external');
177 $this->tpl->setVariable('VAL_ID',$a_set['id']);
178 $this->tpl->setVariable('VAL_TARGET',ilUtil::prepareFormOutput($a_set['target']));
179 $this->tpl->parseCurrentBlock();
180 }
181 else
182 {
183 $ilCtrl->setParameterByClass('ilinternallinkgui', 'postvar','tar_'.$a_set['id']);
184 $trigger_link = array(get_class($this->parent_obj), 'ilinternallinkgui');
185 $trigger_link = $ilCtrl->getLinkTargetByClass($trigger_link, '', false, true, false);
186 $ilCtrl->setParameterByClass('ilinternallinkgui', 'postvar', '');
187
188 $this->tpl->setCurrentBlock('internal');
189 $this->tpl->setVariable('VAL_ID',$a_set['id']);
190 $this->tpl->setVariable('VAL_TRIGGER_INTERNAL',$trigger_link);
191 $this->tpl->setVariable('TXT_TRIGGER_INTERNAL',$this->lng->txt('edit'));
192
193 // info about current link
194 if($a_set['target'])
195 {
196 $parts = explode('|', $a_set['target']);
197
198 $this->tpl->setVariable('VAL_INTERNAL_TYPE',$parts[0]);
199 $this->tpl->setVariable('VAL_INTERNAL_ID',$parts[1]);
200
201 $parts = ilLinkInputGUI::getTranslatedValue($a_set['target']);
202
203 $this->tpl->setVariable('TXT_TRIGGER_INFO', $parts['type'].' "'.
204 $parts['name'].'"');
205 }
206
207 $this->tpl->parseCurrentBlock();
208 }
209
210 $this->tpl->setVariable('TXT_LAST_CHECK',$this->lng->txt('webr_last_check_table'));
211 $this->tpl->setVariable('LAST_CHECK',
212 $a_set['last_check'] ?
213 ilDatePresentation::formatDate(new ilDateTime($a_set['last_check'],IL_CAL_UNIX)) :
214 $this->lng->txt('no_date')
215 );
216
217 // Valid
218 $this->tpl->setVariable('VAL_VALID',
219 ilUtil::formCheckbox($a_set['valid'], 'links['.$a_set['id'].'][vali]', 1)
220 );
221
222 // Active
223 $this->tpl->setVariable('VAL_ACTIVE',
224 ilUtil::formCheckbox($a_set['active'], 'links['.$a_set['id'].'][act]', 1)
225 );
226
227 // Valid
228 $this->tpl->setVariable('VAL_CHECK',
229 ilUtil::formCheckbox($a_set['disable_check'], 'links['.$a_set['id'].'][che]', 1)
230 );
231
232 // Dynamic parameters
233 foreach($a_set['params'] as $param_id => $param)
234 {
235 $this->tpl->setCurrentBlock('dyn_del_row');
236 $this->tpl->setVariable('TXT_DYN_DEL',$this->lng->txt('delete'));
237 $ilCtrl->setParameterByClass(get_class($this->getParentObject()),'param_id',$param_id);
238 $this->tpl->setVariable('DYN_DEL_LINK',$ilCtrl->getLinkTarget($this->getParentObject(),'deleteParameter'));
239 $this->tpl->setVariable('VAL_DYN',ilParameterAppender::parameterToInfo($param['name'],$param['value']));
240 $this->tpl->parseCurrentBlock();
241 }
242 if($a_set['params'])
243 {
244 $this->tpl->setCurrentBlock('dyn_del_rows');
245 $this->tpl->setVariable('TXT_EXISTING',$this->lng->txt('links_existing_params'));
246 $this->tpl->parseCurrentBlock();
247 }
248
250 {
251 $this->tpl->setCurrentBlock('dyn_add');
252 $this->tpl->setVariable('TXT_DYN_ADD',$this->lng->txt('links_add_param'));
253
254 $this->tpl->setVariable('TXT_DYN_NAME',$this->lng->txt('links_name'));
255 $this->tpl->setVariable('TXT_DYN_VALUE',$this->lng->txt('links_value'));
256 $this->tpl->setVariable('VAL_DYN_NAME',$a_set['name']);
257 $this->tpl->setVariable('DYN_ID',$a_set['id']);
258 $this->tpl->setVariable(
259 'SEL_DYN_VAL',
261 $a_set['value'] ? $a_set['value'] : 0,
262 'links['.$a_set['id'].'][val]',
264 false,
265 true)
266 );
267 $this->tpl->parseCurrentBlock();
268 }
269
270 if(in_array($a_set['id'], $this->getInvalidLinks()))
271 {
272 $this->tpl->setVariable('CSS_ROW','warn');
273 }
274
275 // Check
276 $this->tpl->setVariable('VAL_ID',$a_set['id']);
277 $this->tpl->setVariable('VAL_CHECKBOX',
278 ilUtil::formCheckbox(false, 'link_ids[]',$a_set['id'])
279 );
280
281 // Column title
282 $this->tpl->setVariable('TXT_TITLE',$this->lng->txt('title'));
283 $this->tpl->setVariable('VAL_TITLE',ilUtil::prepareFormOutput($a_set['title']));
284 $this->tpl->setVariable('TXT_DESC',$this->lng->txt('description'));
285 $this->tpl->setVariable('VAL_DESC',ilUtil::prepareFormOutput($a_set['description']));
286
287 // Column Target
288 $this->tpl->setVariable('TXT_TARGET',$this->lng->txt('target'));
289 }
290
295 protected function getWebResourceItems()
296 {
297 return $this->web_res;
298 }
299}
300?>
const IL_CAL_UNIX
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
static getTranslatedValue($a_value)
Class ilObjLinkResourceGUI.
static parameterToInfo($a_name, $a_value)
Get info text describing an existing dynamic link.
static _getOptionSelect()
Get options as array.
static _getParams($a_link_id)
Get dynamic parameter definitions.
static _isEnabled()
Check if dynamic parameters are enabled.
Class ilTable2GUI.
setEnableHeader($a_enableheader)
Set Enable Header.
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.
getParentObject()
Get parent object.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setData($a_data)
set table data @access public
setEnableTitle($a_enabletitle)
Set Enable Title.
setEnableNumInfo($a_val)
Set enable num info.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
static formCheckbox($checked, $varname, $value, $disabled=false)
??? @access public
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.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
__construct($a_parent_obj, $a_parent_cmd)
Constructor
$_POST['username']
Definition: cron.php:12
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40