ILIAS  Release_4_0_x_branch Revision 61816
 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)
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  }
61 
69  public function executeCommand()
70  {
71  $next_class = $this->ctrl->getNextClass($this);
72  $cmd = $this->ctrl->getCmd();
73 
74  switch($next_class)
75  {
76  default:
77  if(!$cmd)
78  {
79  $cmd = "listSessions";
80  }
81  $this->$cmd();
82  break;
83  }
84  }
92  public function listSessions()
93  {
94  global $ilErr,$ilAccess, $ilUser,$tree;
95 
96  if(!$ilAccess->checkAccess('write','',$this->course_ref_id))
97  {
98  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
99  }
100 
101  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.sess_list.html','Modules/Session');
102  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
103 
104  // display button
105  $this->tpl->setCurrentBlock("btn_cell");
106  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'exportCSV'));
107  $this->tpl->setVariable("BTN_TXT",$this->lng->txt('event_csv_export'));
108  $this->tpl->parseCurrentBlock();
109 
110  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
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_obj = ilCourseParticipants::_getInstanceByObjId($this->course_id);
117  $members = $members_obj->getParticipants();
118  $members = ilUtil::_sortIds($members,'usr_data','lastname','usr_id');
119 
120  // Table
121  $tbl = new ilTableGUI();
122  $tbl->setTitle($this->lng->txt("event_overview"),
123  'icon_usr.gif',
124  $this->lng->txt('obj_usr'));
125  $this->ctrl->setParameter($this,'offset',(int) $_GET['offset']);
126 
127  $events = array();
128  foreach($tree->getSubtree($tree->getNodeData($this->course_ref_id),false,'sess') as $event_id)
129  {
130  $tmp_event = ilObjectFactory::getInstanceByRefId($event_id,false);
131  if(!is_object($tmp_event) or !$ilAccess->checkAccess('write','',$event_id))
132  {
133  continue;
134  }
135  $events[] = $tmp_event;
136  }
137 
138  $headerNames = array();
139  $headerVars = array();
140  $colWidth = array();
141 
142  $headerNames[] = $this->lng->txt('name');
143  $headerVars[] = "name";
144  $colWidth[] = '20%';
145 
146  for ($i = 1; $i <= count($events); $i++)
147  {
148  $headerNames[] = $i;
149  $headerVars[] = "event_".$i;
150  $colWidth[] = 80/count($events)."%";
151  }
152 
153  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
154  $tbl->setHeaderNames($headerNames);
155  $tbl->setHeaderVars($headerVars, $this->ctrl->getParameterArray($this,'listSessions'));
156  $tbl->setColumnWidth($colWidth);
157 
158  $tbl->setOrderColumn($_GET["sort_by"]);
159  $tbl->setOrderDirection($_GET["sort_order"]);
160  $tbl->setOffset($_GET["offset"]);
161  $tbl->setLimit($ilUser->getPref("hits_per_page"));
162  $tbl->setMaxCount(count($members));
163  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
164 
165  $sliced_users = array_slice($members,$_GET['offset'],$_SESSION['tbl_limit']);
166  $tbl->disable('sort');
167  $tbl->render();
168 
169  $counter = 0;
170  foreach($sliced_users as $user_id)
171  {
172  foreach($events as $event_obj)
173  {
174  $this->tpl->setCurrentBlock("eventcols");
175 
176  $event_part = new ilEventParticipants($event_obj->getId());
177 
178  {
179  $this->tpl->setVariable("IMAGE_PARTICIPATED", $event_part->hasParticipated($user_id) ?
180  ilUtil::getImagePath('icon_ok.gif') :
181  ilUtil::getImagePath('icon_not_ok.gif'));
182 
183  $this->tpl->setVariable("PARTICIPATED", $event_part->hasParticipated($user_id) ?
184  $this->lng->txt('event_participated') :
185  $this->lng->txt('event_not_participated'));
186  }
187 
188  $this->tpl->parseCurrentBlock();
189  }
190 
191  $this->tpl->setCurrentBlock("tbl_content");
192  $name = ilObjUser::_lookupName($user_id);
193  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor($counter++,'tblrow1','tblrow2'));
194  $this->tpl->setVariable("LASTNAME",$name['lastname']);
195  $this->tpl->setVariable("FIRSTNAME",$name['firstname']);
196  $this->tpl->setVariable("LOGIN",ilObjUser::_lookupLogin($user_id));
197  $this->tpl->parseCurrentBlock();
198  }
199 
200  $this->tpl->setVariable("HEAD_TXT_LEGEND", $this->lng->txt("legend"));
201  $this->tpl->setVariable("HEAD_TXT_DIGIT", $this->lng->txt("event_digit"));
202  $this->tpl->setVariable("HEAD_TXT_EVENT", $this->lng->txt("event"));
203  $this->tpl->setVariable("HEAD_TXT_LOCATION", $this->lng->txt("event_location"));
204  $this->tpl->setVariable("HEAD_TXT_DATE_TIME",$this->lng->txt("event_date_time"));
205  $i = 1;
206  foreach($events as $event_obj)
207  {
208  $this->tpl->setCurrentBlock("legend_loop");
209  $this->tpl->setVariable("LEGEND_CSS_ROW",ilUtil::switchColor($counter++,'tblrow1','tblrow2'));
210  $this->tpl->setVariable("LEGEND_DIGIT", $i++);
211  $this->tpl->setVariable("LEGEND_EVENT_TITLE", $event_obj->getTitle());
212  $this->tpl->setVariable("LEGEND_EVENT_DESCRIPTION", $event_obj->getDescription());
213  $this->tpl->setVariable("LEGEND_EVENT_LOCATION", $event_obj->getLocation());
214  $this->tpl->setVariable("LEGEND_EVENT_APPOINTMENT", $event_obj->getFirstAppointment()->appointmentToString());
215  $this->tpl->parseCurrentBlock();
216  }
217 
218  }
219 
227  public function exportCSV()
228  {
229  global $tree,$ilAccess;
230 
231  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
232  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
233  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
234 
235  $members_obj = ilCourseParticipants::_getInstanceByObjId($this->course_id);
236  $members = $members_obj->getParticipants();
237  $members = ilUtil::_sortIds($members,'usr_data','lastname','usr_id');
238 
239  $events = array();
240  foreach($tree->getSubtree($tree->getNodeData($this->course_ref_id),false,'sess') as $event_id)
241  {
242  $tmp_event = ilObjectFactory::getInstanceByRefId($event_id,false);
243  if(!is_object($tmp_event) or !$ilAccess->checkAccess('write','',$event_id))
244  {
245  continue;
246  }
247  $events[] = $tmp_event;
248  }
249 
250  $this->csv = new ilCSVWriter();
251  $this->csv->addColumn($this->lng->txt("lastname"));
252  $this->csv->addColumn($this->lng->txt("firstname"));
253  $this->csv->addColumn($this->lng->txt("login"));
254 
255  foreach($events as $event_obj)
256  {
257  // TODO: do not export relative dates
258  $this->csv->addColumn($event_obj->getTitle().' ('.$event_obj->getFirstAppointment()->appointmentToString().')');
259  }
260 
261  $this->csv->addRow();
262 
263  foreach($members as $user_id)
264  {
265  $name = ilObjUser::_lookupName($user_id);
266 
267  $this->csv->addColumn($name['lastname']);
268  $this->csv->addColumn($name['firstname']);
269  $this->csv->addColumn(ilObjUser::_lookupLogin($user_id));
270 
271  foreach($events as $event_obj)
272  {
273  $event_part = new ilEventParticipants((int) $event_obj->getId());
274 
275  $this->csv->addColumn($event_part->hasParticipated($user_id) ?
276  $this->lng->txt('event_participated') :
277  $this->lng->txt('event_not_participated'));
278  }
279 
280  $this->csv->addRow();
281  }
282  $date = new ilDate(time(),IL_CAL_UNIX);
283  ilUtil::deliverData($this->csv->getCSVString(),$date->get(IL_CAL_FKT_DATE,'Y-m-d')."_course_events.csv", "text/csv");
284  }
285 }
286 ?>