ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilWebResourceLinkTableGUI.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("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
7 include_once './Services/Container/classes/class.ilContainerSorting.php';
8 include_once './Services/Container/classes/class.ilContainer.php';
9 include_once './Services/Container/classes/class.ilContainerSorting.php';
10 include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
11 
12 
23 {
24  protected $editable = false;
25  protected $web_res = null;
26 
27  protected $link_sort_mode = null;
28  protected $link_sort_enabled = false;
29 
33  public function __construct($a_parent_obj,$a_parent_cmd,$a_sorting = false)
34  {
35  global $lng,$ilAccess,$ilCtrl;
36 
37  parent::__construct($a_parent_obj,$a_parent_cmd);
38 
39  // Initialize
40  if($ilAccess->checkAccess('write','',$this->getParentObject()->object->getRefId()))
41  {
42  $this->editable = true;
43  }
44 
45  $this->enableLinkSorting($a_sorting);
46  $this->web_res = new ilLinkResourceItems($this->getParentObject()->object->getId());
47 
48 
49  $this->setTitle($lng->txt('web_resources'));
50 
51  if($this->isEditable())
52  {
53  if($this->isLinkSortingEnabled())
54  {
55  $this->setLimit(9999);
56  $this->addColumn($lng->txt('position'),'','10px');
57  $this->addColumn($lng->txt('title'),'','90%');
58  $this->addColumn('','','10%');
59 
60  $this->addMultiCommand('saveSorting', $this->lng->txt('sorting_save'));
61  }
62  else
63  {
64  $this->addColumn($lng->txt('title'),'','90%');
65  $this->addColumn('','','10%');
66  }
67 
68  }
69  else
70  {
71  $this->addColumn($lng->txt('title'),'','100%');
72  }
73 
74  $this->initSorting();
75 
76  $this->setEnableHeader(true);
77  $this->setFormAction($ilCtrl->getFormAction($this->getParentObject()));
78  $this->setRowTemplate("tpl.webr_link_row.html", 'Modules/WebResource');
79  $this->setEnableTitle(true);
80  $this->setEnableNumInfo(false);
81 
82  }
83 
89  public function enableLinkSorting($a_status)
90  {
91  $this->link_sort_enabled = $a_status;
92  }
93 
98  public function isLinkSortingEnabled()
99  {
100  return (bool) $this->link_sort_enabled;
101  }
102 
107  public function parse()
108  {
109 
110  $rows = array();
111 
112  $items = $this->getWebResourceItems()->getActivatedItems();
113  $items = $this->getWebResourceItems()->sortItems($items);
114 
115  $counter = 1;
116  foreach($items as $link)
117  {
119  {
120  $link = ilParameterAppender::_append($link);
121  }
122  $tmp['position'] = $counter++;
123  $tmp['title'] = $link['title'];
124  $tmp['description'] = $link['description'];
125  $tmp['target'] = $link['target'];
126  $tmp['link_id'] = $link['link_id'];
127 
128  $rows[] = $tmp;
129  }
130  $this->setData($rows);
131  }
132 
136  protected function fillRow($a_set)
137  {
138  global $ilCtrl,$lng;
139 
140  $this->tpl->setVariable('TITLE',$a_set['title']);
141  if(strlen($a_set['description']))
142  {
143  $this->tpl->setVariable('DESCRIPTION',$a_set['description']);
144  }
145  $this->tpl->setVariable('TARGET',$a_set['target']);
146 
147  if(!$this->isEditable())
148  {
149  return;
150  }
151 
152  if($this->isLinkSortingEnabled())
153  {
154  $this->tpl->setVariable('VAL_POS',sprintf('%.2f',$a_set['position']));
155  $this->tpl->setVariable('VAL_ITEM',$a_set['link_id']);
156  }
157 
158  $actions = new ilAdvancedSelectionListGUI();
159  $actions->setSelectionHeaderClass("small");
160  $actions->setItemLinkClass("xsmall");
161 
162  $actions->setListTitle($lng->txt('actions'));
163  $actions->setId($a_set['link_id']);
164 
165  $ilCtrl->setParameterByClass(get_class($this->getParentObject()), 'link_id', $a_set['link_id']);
166  $actions->addItem(
167  $lng->txt('edit'),
168  '',
169  $ilCtrl->getLinkTargetByClass(get_class($this->getParentObject()),'editLink')
170  );
171  $actions->addItem(
172  $lng->txt('webr_deactivate'),
173  '',
174  $ilCtrl->getLinkTargetByClass(get_class($this->getParentObject()),'deactivateLink')
175  );
176  $actions->addItem(
177  $lng->txt('delete'),
178  '',
179  $ilCtrl->getLinkTargetByClass(get_class($this->getParentObject()),'confirmDeleteLink')
180  );
181  $this->tpl->setVariable('ACTION_HTML',$actions->getHTML());
182  }
183 
184 
185 
186 
191  protected function getWebResourceItems()
192  {
193  return $this->web_res;
194  }
195 
196 
201  protected function isEditable()
202  {
203  return (bool) $this->editable;
204  }
205 
206  protected function initSorting()
207  {
208  $this->link_sort_mode = ilContainerSortingSettings::_lookupSortMode(
209  $this->getParentObject()->object->getId()
210  );
211  }
212 }
213 ?>