ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSessionOverviewGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 {
34  protected $course_ref_id = null;
35  protected $course_id = null;
36 
37  protected $lng;
38  protected $tpl;
39  protected $ctrl;
40 
48  public function __construct($a_crs_ref_id, ilParticipants $a_members)
49  {
50  global $tpl, $ilCtrl, $lng;
51 
52  $this->ctrl = $ilCtrl;
53  $this->tpl = $tpl;
54  $this->lng = $lng;
55  $this->lng->loadLanguageModule('event');
56  $this->lng->loadLanguageModule('crs');
57 
58  $this->course_ref_id = $a_crs_ref_id;
59  $this->course_id = ilObject::_lookupObjId($this->course_ref_id);
60  $this->members_obj = $a_members;
61  }
62 
70  public function executeCommand()
71  {
72  $next_class = $this->ctrl->getNextClass($this);
73  $cmd = $this->ctrl->getCmd();
74 
75  switch($next_class)
76  {
77  default:
78  if(!$cmd)
79  {
80  $cmd = "listSessions";
81  }
82  $this->$cmd();
83  break;
84  }
85  }
93  public function listSessions()
94  {
95  global $ilErr,$ilAccess, $ilUser,$tree;
96 
97  if(!$ilAccess->checkAccess('write','',$this->course_ref_id))
98  {
99  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
100  }
101 
102  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.sess_list.html','Modules/Session');
103  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
104 
105  // display button
106  $this->tpl->setCurrentBlock("btn_cell");
107  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'exportCSV'));
108  $this->tpl->setVariable("BTN_TXT",$this->lng->txt('event_csv_export'));
109  $this->tpl->parseCurrentBlock();
110 
111  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
112 
113  $this->tpl->addBlockfile("EVENTS_TABLE","events_table", "tpl.table.html");
114  $this->tpl->addBlockfile('TBL_CONTENT','tbl_content','tpl.sess_list_row.html','Modules/Session');
115 
116  $members = $this->members_obj->getParticipants();
117  $members = ilUtil::_sortIds($members,'usr_data','lastname','usr_id');
118 
119  // Table
120  $tbl = new ilTableGUI();
121  $tbl->setTitle($this->lng->txt("event_overview"),
122  'icon_usr.png',
123  $this->lng->txt('obj_usr'));
124  $this->ctrl->setParameter($this,'offset',(int) $_GET['offset']);
125 
126  $events = array();
127  foreach($tree->getSubtree($tree->getNodeData($this->course_ref_id),false,'sess') as $event_id)
128  {
129  $tmp_event = ilObjectFactory::getInstanceByRefId($event_id,false);
130  if(!is_object($tmp_event) or !$ilAccess->checkAccess('write','',$event_id))
131  {
132  continue;
133  }
134  $events[] = $tmp_event;
135  }
136 
137  $headerNames = array();
138  $headerVars = array();
139  $colWidth = array();
140 
141  $headerNames[] = $this->lng->txt('name');
142  $headerVars[] = "name";
143  $colWidth[] = '20%';
144 
145  for ($i = 1; $i <= count($events); $i++)
146  {
147  $headerNames[] = $i;
148  $headerVars[] = "event_".$i;
149  $colWidth[] = 80/count($events)."%";
150  }
151 
152  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
153  $tbl->setHeaderNames($headerNames);
154  $tbl->setHeaderVars($headerVars, $this->ctrl->getParameterArray($this,'listSessions'));
155  $tbl->setColumnWidth($colWidth);
156 
157  $tbl->setOrderColumn($_GET["sort_by"]);
158  $tbl->setOrderDirection($_GET["sort_order"]);
159  $tbl->setOffset($_GET["offset"]);
160  $tbl->setLimit($ilUser->getPref("hits_per_page"));
161  $tbl->setMaxCount(count($members));
162  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
163 
164  $sliced_users = array_slice($members,$_GET['offset'],$_SESSION['tbl_limit']);
165  $tbl->disable('sort');
166  $tbl->render();
167 
168  $counter = 0;
169  foreach($sliced_users as $user_id)
170  {
171  foreach($events as $event_obj)
172  {
173  $this->tpl->setCurrentBlock("eventcols");
174 
175  $event_part = new ilEventParticipants($event_obj->getId());
176 
177  {
178  $this->tpl->setVariable("IMAGE_PARTICIPATED", $event_part->hasParticipated($user_id) ?
179  ilUtil::getImagePath('icon_ok.png') :
180  ilUtil::getImagePath('icon_not_ok.png'));
181 
182  $this->tpl->setVariable("PARTICIPATED", $event_part->hasParticipated($user_id) ?
183  $this->lng->txt('event_participated') :
184  $this->lng->txt('event_not_participated'));
185  }
186 
187  $this->tpl->parseCurrentBlock();
188  }
189 
190  $this->tpl->setCurrentBlock("tbl_content");
191  $name = ilObjUser::_lookupName($user_id);
192  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor($counter++,'tblrow1','tblrow2'));
193  $this->tpl->setVariable("LASTNAME",$name['lastname']);
194  $this->tpl->setVariable("FIRSTNAME",$name['firstname']);
195  $this->tpl->setVariable("LOGIN",ilObjUser::_lookupLogin($user_id));
196  $this->tpl->parseCurrentBlock();
197  }
198 
199  $this->tpl->setVariable("HEAD_TXT_LEGEND", $this->lng->txt("legend"));
200  $this->tpl->setVariable("HEAD_TXT_DIGIT", $this->lng->txt("event_digit"));
201  $this->tpl->setVariable("HEAD_TXT_EVENT", $this->lng->txt("event"));
202  $this->tpl->setVariable("HEAD_TXT_LOCATION", $this->lng->txt("event_location"));
203  $this->tpl->setVariable("HEAD_TXT_DATE_TIME",$this->lng->txt("event_date_time"));
204  $i = 1;
205  foreach($events as $event_obj)
206  {
207  $this->tpl->setCurrentBlock("legend_loop");
208  $this->tpl->setVariable("LEGEND_CSS_ROW",ilUtil::switchColor($counter++,'tblrow1','tblrow2'));
209  $this->tpl->setVariable("LEGEND_DIGIT", $i++);
210  $this->tpl->setVariable("LEGEND_EVENT_TITLE", $event_obj->getTitle());
211  $this->tpl->setVariable("LEGEND_EVENT_DESCRIPTION", $event_obj->getDescription());
212  $this->tpl->setVariable("LEGEND_EVENT_LOCATION", $event_obj->getLocation());
213  $this->tpl->setVariable("LEGEND_EVENT_APPOINTMENT", $event_obj->getFirstAppointment()->appointmentToString());
214  $this->tpl->parseCurrentBlock();
215  }
216 
217  }
218 
226  public function exportCSV()
227  {
228  global $tree,$ilAccess;
229 
230  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
231  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
232 
233  $members = $this->members_obj->getParticipants();
234  $members = ilUtil::_sortIds($members,'usr_data','lastname','usr_id');
235 
236  $events = array();
237  foreach($tree->getSubtree($tree->getNodeData($this->course_ref_id),false,'sess') as $event_id)
238  {
239  $tmp_event = ilObjectFactory::getInstanceByRefId($event_id,false);
240  if(!is_object($tmp_event) or !$ilAccess->checkAccess('write','',$event_id))
241  {
242  continue;
243  }
244  $events[] = $tmp_event;
245  }
246 
247  $this->csv = new ilCSVWriter();
248  $this->csv->addColumn($this->lng->txt("lastname"));
249  $this->csv->addColumn($this->lng->txt("firstname"));
250  $this->csv->addColumn($this->lng->txt("login"));
251 
252  foreach($events as $event_obj)
253  {
254  // TODO: do not export relative dates
255  $this->csv->addColumn($event_obj->getTitle().' ('.$event_obj->getFirstAppointment()->appointmentToString().')');
256  }
257 
258  $this->csv->addRow();
259 
260  foreach($members as $user_id)
261  {
262  $name = ilObjUser::_lookupName($user_id);
263 
264  $this->csv->addColumn($name['lastname']);
265  $this->csv->addColumn($name['firstname']);
266  $this->csv->addColumn(ilObjUser::_lookupLogin($user_id));
267 
268  foreach($events as $event_obj)
269  {
270  $event_part = new ilEventParticipants((int) $event_obj->getId());
271 
272  $this->csv->addColumn($event_part->hasParticipated($user_id) ?
273  $this->lng->txt('event_participated') :
274  $this->lng->txt('event_not_participated'));
275  }
276 
277  $this->csv->addRow();
278  }
279  $date = new ilDate(time(),IL_CAL_UNIX);
280  ilUtil::deliverData($this->csv->getCSVString(),$date->get(IL_CAL_FKT_DATE,'Y-m-d')."_course_events.csv", "text/csv");
281  }
282 }
283 ?>