ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLPStatusEvent.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 include_once './Services/Tracking/classes/class.ilLPStatus.php';
34 include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
35 
37 {
38  public function __construct($a_obj_id)
39  {
40  global $ilDB;
41 
42  parent::__construct($a_obj_id);
43  $this->db = $ilDB;
44  }
45 
46  public static function _getNotAttempted($a_obj_id)
47  {
48  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
49 
50  $users = array();
51 
52  $members = self::getMembers($status_info['crs_id'], true);
53  if ($members) {
54  // diff in progress and completed (use stored result in LPStatusWrapper)
55  $users = array_diff((array) $members, ilLPStatusWrapper::_getInProgress($a_obj_id));
56  $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
57  }
58 
59  return $users;
60  }
61 
62  public static function _getInProgress($a_obj_id)
63  {
64  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
65 
66  // If registration is disabled in_progress is not available
67  if (!$status_info['registration']) {
68  return array();
69  }
70  // If event has occured in_progress is impossible
71  if ($status_info['starting_time'] < time()) {
72  return array();
73  }
74 
75  // Otherwise all users who registered will get the status in progress
76  return $status_info['registered_users'] ? $status_info['registered_users'] : array();
77  }
78 
79  public static function _getCompleted($a_obj_id)
80  {
81  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
82  return $status_info['participated_users'] ? $status_info['participated_users'] : array();
83  }
84 
85  public static function _getStatusInfo($a_obj_id)
86  {
87  $tree = $GLOBALS['DIC']->repositoryTree();
88 
89  $references = ilObject::_getAllReferences($a_obj_id);
90  $ref_id = end($references);
91 
92  $member_ref_id = null;
93  if ($id = $tree->checkForParentType($ref_id, 'grp')) {
94  $member_ref_id = $id;
95  } elseif ($id = $tree->checkForParentType($ref_id, 'crs')) {
96  $member_ref_id = $id;
97  }
98 
99  $status_info = array();
100  $status_info['crs_id'] = ilObject::_lookupObjId($member_ref_id);
101  $status_info['registration'] = ilObjSession::_lookupRegistrationEnabled($a_obj_id);
102  $status_info['title'] = ilObject::_lookupTitle($a_obj_id);
103  $status_info['description'] = ilObject::_lookupDescription($a_obj_id);
104 
105  $time_info = ilSessionAppointment::_lookupAppointment($a_obj_id);
106  $status_info['starting_time'] = $time_info['start'];
107  $status_info['ending_time'] = $time_info['end'];
108  $status_info['fullday'] = $time_info['fullday'];
109 
110  $status_info['registered_users'] = ilEventParticipants::_getRegistered($a_obj_id);
111  $status_info['participated_users'] = ilEventParticipants::_getParticipated($a_obj_id);
112 
113  return $status_info;
114  }
115 
124  public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
125  {
126  global $ilObjDataCache;
127 
128  $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
129  switch ($ilObjDataCache->lookupType($a_obj_id)) {
130  case 'sess':
131  include_once './Modules/Session/classes/class.ilEventParticipants.php';
132  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
133  include_once('./Modules/Session/classes/class.ilObjSession.php');
134 
135  $time_info = ilSessionAppointment::_lookupAppointment($a_obj_id);
136  $registration = ilObjSession::_lookupRegistrationEnabled($a_obj_id);
137 
138  // If registration is disabled in_progress is not available
139  // If event has occured in_progress is impossible
140  if ($registration && $time_info['start'] >= time()) {
141  // is user registered -> in progress
142  if (ilEventParticipants::_isRegistered($a_user_id, $a_obj_id)) {
143  $status = self::LP_STATUS_IN_PROGRESS_NUM;
144  }
145  }
146  if (ilEventParticipants::_hasParticipated($a_user_id, $a_obj_id)) {
147  $status = self::LP_STATUS_COMPLETED_NUM;
148  }
149  break;
150  }
151  return $status;
152  }
153 
160  protected static function getMembers($a_obj_id, $a_is_crs_id = false)
161  {
162  if (!$a_is_crs_id) {
163  $tree = $GLOBALS['DIC']->repositoryTree();
164  $references = ilObject::_getAllReferences($a_obj_id);
165  $ref_id = end($references);
166 
167  $member_ref_id = null;
168  if ($id = $tree->checkForParentType($ref_id, 'grp')) {
169  $member_ref_id = $id;
170  } elseif ($id = $tree->checkForParentType($ref_id, 'crs')) {
171  $member_ref_id = $id;
172  } else {
173  return [];
174  }
175  $member_obj_id = ilObject::_lookupObjId($member_ref_id);
176  } else {
177  $member_obj_id = $a_obj_id;
178  }
179 
180  $member_obj = ilParticipants::getInstanceByObjId($member_obj_id);
181  return $member_obj->getMembers();
182  }
183 
191  public static function _lookupCompletedForObject($a_obj_id, $a_user_ids = null)
192  {
193  if (!$a_user_ids) {
194  $a_user_ids = self::getMembers($a_obj_id);
195  if (!$a_user_ids) {
196  return array();
197  }
198  }
199  return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_COMPLETED_NUM, $a_user_ids);
200  }
201 
209  public static function _lookupFailedForObject($a_obj_id, $a_user_ids = null)
210  {
211  return array();
212  }
213 
221  public static function _lookupInProgressForObject($a_obj_id, $a_user_ids = null)
222  {
223  if (!$a_user_ids) {
224  $a_user_ids = self::getMembers($a_obj_id);
225  if (!$a_user_ids) {
226  return array();
227  }
228  }
229  return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_IN_PROGRESS_NUM, $a_user_ids);
230  }
231 }
static _getRegistered($a_event_id)
static _getParticipated($a_event_id)
static _getInProgress($a_obj_id)
Static function to read users who have the status &#39;in_progress&#39;.
static getMembers($a_obj_id, $a_is_crs_id=false)
Get members for object.
static _getCompleted($a_obj_id)
Static function to read the users who have the status &#39;completed&#39;.
static _getNotAttempted($a_obj_id)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
if(!array_key_exists('StateId', $_REQUEST)) $id
static _lookupTitle($a_id)
lookup object title
static _lookupInProgressForObject($a_obj_id, $a_user_ids=null)
Get in progress users for object.
static _isRegistered($a_usr_id, $a_event_id)
static _getAllReferences($a_id)
get all reference ids of object
static _hasParticipated($a_usr_id, $a_event_id)
static _lookupRegistrationEnabled($a_obj_id)
lookup registration enabled
static _lookupDescription($a_id)
lookup object description
static _lookupObjId($a_id)
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Determine status.
static _lookupCompletedForObject($a_obj_id, $a_user_ids=null)
Get completed users for object.
static _getStatusInfo($a_obj_id)
static _getInProgress($a_obj_id)
Create styles array
The data for the language used.
static _getStatusInfo($a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
$users
Definition: authpage.php:44
static _getCompleted($a_obj_id)
static _lookupAppointment($a_obj_id)
lookup appointment
global $ilDB
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static _lookupFailedForObject($a_obj_id, $a_user_ids=null)
Get failed users for object.
static getInstanceByObjId($a_obj_id)
Get instance by obj type.