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 24include_once('./Services/Membership/classes/class.ilParticipants.php'); 25 26/** 27* 28* 29* @author Stefan Meyer <smeyer.ilias@gmx.de> 30* @version $Id$ 31* 32* @ingroup ModulesGroup 33*/ 34 35 36class ilGroupParticipants extends ilParticipants 37{ 38 const COMPONENT_NAME = 'Modules/Group'; 39 40 protected static $instances = array(); 41 42 /** 43 * Constructor 44 * 45 * @access protected 46 * @param int obj_id of container 47 */ 48 public function __construct($a_obj_id) 49 { 50 // ref based constructor 51 $refs = ilObject::_getAllReferences($a_obj_id); 52 parent::__construct(self::COMPONENT_NAME, array_pop($refs)); 53 } 54 55 /** 56 * Get singleton instance 57 * 58 * @access public 59 * @static 60 * 61 * @param int obj_id 62 * @return ilGroupParticipants 63 */ 64 public static function _getInstanceByObjId($a_obj_id) 65 { 66 if (isset(self::$instances[$a_obj_id]) and self::$instances[$a_obj_id]) { 67 return self::$instances[$a_obj_id]; 68 } 69 return self::$instances[$a_obj_id] = new ilGroupParticipants($a_obj_id); 70 } 71 72 /** 73 * Get member roles (not auto generated) 74 * @param int $a_ref_id 75 */ 76 public static function getMemberRoles($a_ref_id) 77 { 78 global $DIC; 79 80 $rbacreview = $DIC['rbacreview']; 81 82 $lrol = $rbacreview->getRolesOfRoleFolder($a_ref_id, false); 83 84 $roles = array(); 85 foreach ($lrol as $role) { 86 $title = ilObject::_lookupTitle($role); 87 switch (substr($title, 0, 8)) { 88 case 'il_grp_a': 89 case 'il_grp_m': 90 continue 2; 91 92 default: 93 $roles[$role] = $role; 94 } 95 } 96 return $roles; 97 } 98 99 /** 100 * Add user to role 101 * @param int $a_usr_id 102 * @param int $a_role 103 * @return boolean 104 */ 105 public function add($a_usr_id, $a_role) 106 { 107 if (parent::add($a_usr_id, $a_role)) { 108 $this->addDesktopItem($a_usr_id); 109 return true; 110 } 111 return false; 112 } 113 114 public function addSubscriber($a_usr_id) 115 { 116 global $DIC; 117 118 $ilAppEventHandler = $DIC['ilAppEventHandler']; 119 $ilLog = $DIC['ilLog']; 120 121 parent::addSubscriber($a_usr_id); 122 123 $GLOBALS['DIC']->logger()->grp()->info('Raise new event: Modules/Group addSubscriber.'); 124 $ilAppEventHandler->raise( 125 "Modules/Group", 126 'addSubscriber', 127 array( 128 'obj_id' => $this->getObjId(), 129 'usr_id' => $a_usr_id 130 ) 131 ); 132 } 133 134 135 136 /** 137 * Static function to check if a user is a participant of the container object 138 * 139 * @access public 140 * @param int ref_id 141 * @param int user id 142 * @static 143 */ 144 public static function _isParticipant($a_ref_id, $a_usr_id) 145 { 146 global $DIC; 147 148 $rbacreview = $DIC['rbacreview']; 149 $ilObjDataCache = $DIC['ilObjDataCache']; 150 $ilDB = $DIC['ilDB']; 151 $ilLog = $DIC['ilLog']; 152 153 $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id, false); 154 return $rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id, $local_roles); 155 } 156 157 /** 158 * Send notification mail 159 * @param int $a_type 160 * @param int $a_usr_id 161 * @return 162 */ 163 public function sendNotification($a_type, $a_usr_id, $a_force_sending_mail = false) 164 { 165 include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php'; 166 $mail = new ilGroupMembershipMailNotification(); 167 $mail->forceSendingMail($a_force_sending_mail); 168 169 switch ($a_type) { 170 case ilGroupMembershipMailNotification::TYPE_ADMISSION_MEMBER: 171 172 $mail->setType(ilGroupMembershipMailNotification::TYPE_ADMISSION_MEMBER); 173 $mail->setRefId($this->ref_id); 174 $mail->setRecipients(array($a_usr_id)); 175 $mail->send(); 176 break; 177 178 case ilGroupMembershipMailNotification::TYPE_DISMISS_MEMBER: 179 180 $mail->setType(ilGroupMembershipMailNotification::TYPE_DISMISS_MEMBER); 181 $mail->setRefId($this->ref_id); 182 $mail->setRecipients(array($a_usr_id)); 183 $mail->send(); 184 break; 185 186 case ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION: 187 188 $mail->setType(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION); 189 $mail->setAdditionalInformation(array('usr_id' => $a_usr_id)); 190 $mail->setRefId($this->ref_id); 191 $mail->setRecipients($this->getNotificationRecipients()); 192 $mail->send(); 193 break; 194 195 case ilGroupMembershipMailNotification::TYPE_UNSUBSCRIBE_MEMBER: 196 197 $mail->setType(ilGroupMembershipMailNotification::TYPE_UNSUBSCRIBE_MEMBER); 198 $mail->setRefId($this->ref_id); 199 $mail->setRecipients(array($a_usr_id)); 200 $mail->send(); 201 break; 202 203 case ilGroupMembershipMailNotification::TYPE_NOTIFICATION_UNSUBSCRIBE: 204 205 $mail->setType(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_UNSUBSCRIBE); 206 $mail->setAdditionalInformation(array('usr_id' => $a_usr_id)); 207 $mail->setRefId($this->ref_id); 208 $mail->setRecipients($this->getNotificationRecipients()); 209 $mail->send(); 210 break; 211 212 case ilGroupMembershipMailNotification::TYPE_SUBSCRIBE_MEMBER: 213 214 $mail->setType(ilGroupMembershipMailNotification::TYPE_SUBSCRIBE_MEMBER); 215 $mail->setRefId($this->ref_id); 216 $mail->setRecipients(array($a_usr_id)); 217 $mail->send(); 218 break; 219 220 case ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION_REQUEST: 221 222 $mail->setType(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION_REQUEST); 223 $mail->setAdditionalInformation(array('usr_id' => $a_usr_id)); 224 $mail->setRefId($this->ref_id); 225 $mail->setRecipients($this->getNotificationRecipients()); 226 $mail->send(); 227 break; 228 229 case ilGroupMembershipMailNotification::TYPE_REFUSED_SUBSCRIPTION_MEMBER: 230 231 $mail->setType(ilGroupMembershipMailNotification::TYPE_REFUSED_SUBSCRIPTION_MEMBER); 232 $mail->setRefId($this->ref_id); 233 $mail->setRecipients(array($a_usr_id)); 234 $mail->send(); 235 break; 236 237 case ilGroupMembershipMailNotification::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER: 238 239 $mail->setType(ilGroupMembershipMailNotification::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER); 240 $mail->setRefId($this->ref_id); 241 $mail->setRecipients(array($a_usr_id)); 242 $mail->send(); 243 break; 244 245 case ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER: 246 247 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php'); 248 $wl = new ilGroupWaitingList($this->obj_id); 249 $pos = $wl->getPosition($a_usr_id); 250 251 $mail->setType(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER); 252 $mail->setRefId($this->ref_id); 253 $mail->setRecipients(array($a_usr_id)); 254 $mail->setAdditionalInformation(array('position' => $pos)); 255 $mail->send(); 256 break; 257 258 case ilGroupMembershipMailNotification::TYPE_STATUS_CHANGED: 259 260 $mail->setType(ilGroupMembershipMailNotification::TYPE_STATUS_CHANGED); 261 $mail->setRefId($this->ref_id); 262 $mail->setRecipients(array($a_usr_id)); 263 $mail->send(); 264 break; 265 266 267 } 268 return true; 269 } 270} 271