ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
51 
52  $tpl = $DIC['tpl'];
53  $ilCtrl = $DIC['ilCtrl'];
54  $lng = $DIC['lng'];
55 
56  $this->ctrl = $ilCtrl;
57  $this->tpl = $tpl;
58  $this->lng = $lng;
59  $this->lng->loadLanguageModule('event');
60  $this->lng->loadLanguageModule('crs');
61 
62  $this->course_ref_id = $a_crs_ref_id;
63  $this->course_id = ilObject::_lookupObjId($this->course_ref_id);
64  $this->members_obj = $a_members;
65  }
66 
74  public function executeCommand()
75  {
76  $next_class = $this->ctrl->getNextClass($this);
77  $cmd = $this->ctrl->getCmd();
78 
79  switch ($next_class) {
80  default:
81  if (!$cmd) {
82  $cmd = "listSessions";
83  }
84  $this->$cmd();
85  break;
86  }
87  }
95  public function listSessions()
96  {
97  global $DIC;
98 
99  $ilToolbar = $DIC['ilToolbar'];
100  $ilErr = $DIC['ilErr'];
101 
102  if (!$GLOBALS['DIC']->access()->checkRbacOrPositionPermissionAccess('manage_members', 'manage_members', $this->course_ref_id)) {
103  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
104  }
105 
106  $ilToolbar->addButton(
107  $this->lng->txt('event_csv_export'),
108  $this->ctrl->getLinkTarget($this, 'exportCSV')
109  );
110 
111  include_once 'Modules/Session/classes/class.ilSessionOverviewTableGUI.php';
112 
113  $part = $this->members_obj->getParticipants();
114  $part = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
115  'manage_members',
116  'manage_members',
117  $this->course_ref_id,
118  $part
119  );
120 
121  $tbl = new ilSessionOverviewTableGUI($this, 'listSessions', $this->course_ref_id, $part);
122  $this->tpl->setContent($tbl->getHTML());
123  }
124 
132  public function exportCSV()
133  {
134  global $DIC;
135 
136  $tree = $DIC['tree'];
137  $ilAccess = $DIC['ilAccess'];
138 
139  include_once('Services/Utilities/classes/class.ilCSVWriter.php');
140  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
141 
142  $part = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
143  'manage_members',
144  'manage_members',
145  $this->course_ref_id,
146  $this->members_obj->getParticipants()
147  );
148  $members = ilUtil::_sortIds($part, 'usr_data', 'lastname', 'usr_id');
149 
150  $events = array();
151  foreach ($tree->getSubtree($tree->getNodeData($this->course_ref_id), false, 'sess') as $event_id) {
152  $tmp_event = ilObjectFactory::getInstanceByRefId($event_id, false);
153  if (!is_object($tmp_event) or !$ilAccess->checkAccess('manage_members', '', $event_id)) {
154  continue;
155  }
156  $events[] = $tmp_event;
157  }
158 
159  $this->csv = new ilCSVWriter();
160  $this->csv->addColumn($this->lng->txt("lastname"));
161  $this->csv->addColumn($this->lng->txt("firstname"));
162  $this->csv->addColumn($this->lng->txt("login"));
163 
164  foreach ($events as $event_obj) {
165  // TODO: do not export relative dates
166  $this->csv->addColumn($event_obj->getTitle() . ' (' . $event_obj->getFirstAppointment()->appointmentToString() . ')');
167  }
168 
169  $this->csv->addRow();
170 
171  foreach ($members as $user_id) {
172  $name = ilObjUser::_lookupName($user_id);
173 
174  $this->csv->addColumn($name['lastname']);
175  $this->csv->addColumn($name['firstname']);
176  $this->csv->addColumn(ilObjUser::_lookupLogin($user_id));
177 
178  foreach ($events as $event_obj) {
179  $event_part = new ilEventParticipants((int) $event_obj->getId());
180 
181  $this->csv->addColumn($event_part->hasParticipated($user_id) ?
182  $this->lng->txt('event_participated') :
183  $this->lng->txt('event_not_participated'));
184  }
185 
186  $this->csv->addRow();
187  }
188  $date = new ilDate(time(), IL_CAL_UNIX);
189  ilUtil::deliverData($this->csv->getCSVString(), $date->get(IL_CAL_FKT_DATE, 'Y-m-d') . "_course_events.csv", "text/csv");
190  }
191 }
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
Helper class to generate CSV files.
global $DIC
Definition: saml.php:7
$tbl
Definition: example_048.php:81
__construct($a_crs_ref_id, ilParticipants $a_members)
constructor
if($argc< 2) $events
Table presentation for session overview.
const IL_CAL_UNIX
$ilErr
Definition: raiseError.php:18
global $ilCtrl
Definition: ilias.php:18
Class for single dates.
static _sortIds($a_ids, $a_table, $a_field, $a_id_name)
Function that sorts ids by a given table field using WHERE IN E.g: __sort(array(6,7),&#39;usr_data&#39;,&#39;lastname&#39;,&#39;usr_id&#39;) => sorts by lastname.
static _lookupObjId($a_id)
const IL_CAL_FKT_DATE
exportCSV()
Events List CSV Export.
listSessions()
list sessions of all user
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.