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 24/** 25* @author Stefan Meyer <meyer@leifos.com> 26* 27* @version $Id$ 28* 29* @package ilias-tracking 30* 31*/ 32 33include_once './Services/Tracking/classes/class.ilLPStatus.php'; 34include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php'; 35 36class ilLPStatusEvent extends ilLPStatus 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 118 /** 119 * Determine status 120 * 121 * @param integer object id 122 * @param integer user id 123 * @param object object (optional depends on object type) 124 * @return integer status 125 */ 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 158 /** 159 * Get members for object 160 * @param int $a_obj_id 161 * @param bool $a_is_crs_id 162 * @return array 163 */ 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 188 /** 189 * Get completed users for object 190 * 191 * @param int $a_obj_id 192 * @param array $a_user_ids 193 * @return array 194 */ 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 206 /** 207 * Get failed users for object 208 * 209 * @param int $a_obj_id 210 * @param array $a_user_ids 211 * @return array 212 */ 213 public static function _lookupFailedForObject($a_obj_id, $a_user_ids = null) 214 { 215 return array(); 216 } 217 218 /** 219 * Get in progress users for object 220 * 221 * @param int $a_obj_id 222 * @param array $a_user_ids 223 * @return array 224 */ 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} 236