ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
41 
42  $ilDB = $DIC['ilDB'];
43 
44  parent::__construct($a_obj_id);
45  $this->db = $ilDB;
46  }
47 
48  public static function _getNotAttempted($a_obj_id)
49  {
50  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
51 
52  $users = array();
53 
54  $members = self::getMembers($status_info['crs_id'], true);
55  if ($members) {
56  // diff in progress and completed (use stored result in LPStatusWrapper)
57  $users = array_diff((array) $members, ilLPStatusWrapper::_getInProgress($a_obj_id));
58  $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
59  }
60 
61  return $users;
62  }
63 
64  public static function _getInProgress($a_obj_id)
65  {
66  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
67 
68  // If registration is disabled in_progress is not available
69  if (!$status_info['registration']) {
70  return array();
71  }
72  // If event has occured in_progress is impossible
73  if ($status_info['starting_time'] < time()) {
74  return array();
75  }
76 
77  // Otherwise all users who registered will get the status in progress
78  return $status_info['registered_users'] ? $status_info['registered_users'] : array();
79  }
80 
81  public static function _getCompleted($a_obj_id)
82  {
83  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
84  return $status_info['participated_users'] ? $status_info['participated_users'] : array();
85  }
86 
87  public static function _getStatusInfo($a_obj_id)
88  {
89  $tree = $GLOBALS['DIC']->repositoryTree();
90 
91  $references = ilObject::_getAllReferences($a_obj_id);
92  $ref_id = end($references);
93 
94  $member_ref_id = null;
95  if ($id = $tree->checkForParentType($ref_id, 'grp')) {
96  $member_ref_id = $id;
97  } elseif ($id = $tree->checkForParentType($ref_id, 'crs')) {
98  $member_ref_id = $id;
99  }
100 
101  $status_info = array();
102  $status_info['crs_id'] = ilObject::_lookupObjId($member_ref_id);
103  $status_info['registration'] = ilObjSession::_lookupRegistrationEnabled($a_obj_id);
104  $status_info['title'] = ilObject::_lookupTitle($a_obj_id);
105  $status_info['description'] = ilObject::_lookupDescription($a_obj_id);
106 
107  $time_info = ilSessionAppointment::_lookupAppointment($a_obj_id);
108  $status_info['starting_time'] = $time_info['start'];
109  $status_info['ending_time'] = $time_info['end'];
110  $status_info['fullday'] = $time_info['fullday'];
111 
112  $status_info['registered_users'] = ilEventParticipants::_getRegistered($a_obj_id);
113  $status_info['participated_users'] = ilEventParticipants::_getParticipated($a_obj_id);
114 
115  return $status_info;
116  }
117 
126  public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
127  {
128  global $DIC;
129 
130  $ilObjDataCache = $DIC['ilObjDataCache'];
131 
132  $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
133  switch ($ilObjDataCache->lookupType($a_obj_id)) {
134  case 'sess':
135  include_once './Modules/Session/classes/class.ilEventParticipants.php';
136  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
137  include_once('./Modules/Session/classes/class.ilObjSession.php');
138 
139  $time_info = ilSessionAppointment::_lookupAppointment($a_obj_id);
140  $registration = ilObjSession::_lookupRegistrationEnabled($a_obj_id);
141 
142  // If registration is disabled in_progress is not available
143  // If event has occured in_progress is impossible
144  if ($registration && $time_info['start'] >= time()) {
145  // is user registered -> in progress
146  if (ilEventParticipants::_isRegistered($a_user_id, $a_obj_id)) {
147  $status = self::LP_STATUS_IN_PROGRESS_NUM;
148  }
149  }
150  if (ilEventParticipants::_hasParticipated($a_user_id, $a_obj_id)) {
151  $status = self::LP_STATUS_COMPLETED_NUM;
152  }
153  break;
154  }
155  return $status;
156  }
157 
164  protected static function getMembers($a_obj_id, $a_is_crs_id = false)
165  {
166  if (!$a_is_crs_id) {
167  $tree = $GLOBALS['DIC']->repositoryTree();
168  $references = ilObject::_getAllReferences($a_obj_id);
169  $ref_id = end($references);
170 
171  $member_ref_id = null;
172  if ($id = $tree->checkForParentType($ref_id, 'grp')) {
173  $member_ref_id = $id;
174  } elseif ($id = $tree->checkForParentType($ref_id, 'crs')) {
175  $member_ref_id = $id;
176  } else {
177  return [];
178  }
179  $member_obj_id = ilObject::_lookupObjId($member_ref_id);
180  } else {
181  $member_obj_id = $a_obj_id;
182  }
183 
184  $member_obj = ilParticipants::getInstanceByObjId($member_obj_id);
185  return $member_obj->getMembers();
186  }
187 
195  public static function _lookupCompletedForObject($a_obj_id, $a_user_ids = null)
196  {
197  if (!$a_user_ids) {
198  $a_user_ids = self::getMembers($a_obj_id);
199  if (!$a_user_ids) {
200  return array();
201  }
202  }
203  return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_COMPLETED_NUM, $a_user_ids);
204  }
205 
213  public static function _lookupFailedForObject($a_obj_id, $a_user_ids = null)
214  {
215  return array();
216  }
217 
225  public static function _lookupInProgressForObject($a_obj_id, $a_user_ids = null)
226  {
227  if (!$a_user_ids) {
228  $a_user_ids = self::getMembers($a_obj_id);
229  if (!$a_user_ids) {
230  return array();
231  }
232  }
233  return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_IN_PROGRESS_NUM, $a_user_ids);
234  }
235 }
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;.
global $DIC
Definition: saml.php:7
static _getNotAttempted($a_obj_id)
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)
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 ...
static _lookupFailedForObject($a_obj_id, $a_user_ids=null)
Get failed users for object.
static getInstanceByObjId($a_obj_id)
Get instance by obj type.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.