ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseParticipants.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 
24 include_once('./Services/Membership/classes/class.ilParticipants.php');
25 
36 {
37  protected static $instances = array();
38 
45  public function __construct($a_obj_id)
46  {
47  $this->type = 'crs';
48 
49  $this->NOTIFY_DISMISS_SUBSCRIBER = 1;
50  $this->NOTIFY_ACCEPT_SUBSCRIBER = 2;
51  $this->NOTIFY_DISMISS_MEMBER = 3;
52  $this->NOTIFY_BLOCK_MEMBER = 4;
53  $this->NOTIFY_UNBLOCK_MEMBER = 5;
54  $this->NOTIFY_ACCEPT_USER = 6;
55  $this->NOTIFY_ADMINS = 7;
56  $this->NOTIFY_STATUS_CHANGED = 8;
57  $this->NOTIFY_SUBSCRIPTION_REQUEST = 9;
58 
59  $this->NOTIFY_REGISTERED = 10;
60  $this->NOTIFY_UNSUBSCRIBE = 11;
61  $this->NOTIFY_WAITING_LIST = 12;
62 
63  parent::__construct($a_obj_id);
64  }
65 
74  public static function _getInstanceByObjId($a_obj_id)
75  {
76  if(isset(self::$instances[$a_obj_id]) and self::$instances[$a_obj_id])
77  {
78  return self::$instances[$a_obj_id];
79  }
80  return self::$instances[$a_obj_id] = new ilCourseParticipants($a_obj_id);
81  }
82 
87  public static function getMemberRoles($a_ref_id)
88  {
89  global $rbacreview;
90 
91  $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
92  $lrol = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
93 
94  $roles = array();
95  foreach($lrol as $role)
96  {
98  switch(substr($title,0,8))
99  {
100  case 'il_crs_a':
101  case 'il_crs_t':
102  case 'il_crs_m':
103  continue;
104 
105  default:
106  $roles[$role] = $role;
107  }
108  }
109  return $roles;
110  }
111 
120  public function updatePassed($a_usr_id,$a_passed)
121  {
122  global $ilDB;
123 
124  $this->participants_status[$a_usr_id]['passed'] = (int) $a_passed;
125 
126  $query = "SELECT * FROM crs_members ".
127  "WHERE obj_id = ".$ilDB->quote($this->obj_id,'integer')." ".
128  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer');
129  $res = $ilDB->query($query);
130  if($res->numRows())
131  {
132  $query = "UPDATE crs_members SET ".
133  "passed = ".$ilDB->quote((int) $a_passed,'integer')." ".
134  "WHERE obj_id = ".$ilDB->quote($this->obj_id,'integer')." ".
135  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer');
136  }
137  else
138  {
139  $query = "INSERT INTO crs_members (passed,obj_id,usr_id,notification,blocked) ".
140  "VALUES ( ".
141  $ilDB->quote((int) $a_passed,'integer').", ".
142  $ilDB->quote($this->obj_id,'integer').", ".
143  $ilDB->quote($a_usr_id,'integer').", ".
144  $ilDB->quote(0,'integer').", ".
145  $ilDB->quote(0,'integer')." ".
146  ")";
147 
148  }
149  $res = $ilDB->manipulate($query);
150  return true;
151 
152  }
153 
154 
155 
156 
157  // Subscription
158  function sendNotification($a_type, $a_usr_id)
159  {
160  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
161 
162  global $ilObjDataCache,$ilUser;
163 
164  switch($a_type)
165  {
166  case $this->NOTIFY_DISMISS_SUBSCRIBER:
169  $mail->setRefId($this->ref_id);
170  $mail->setRecipients(array($a_usr_id));
171  $mail->send();
172  break;
173 
174  case $this->NOTIFY_ACCEPT_SUBSCRIBER:
177  $mail->setRefId($this->ref_id);
178  $mail->setRecipients(array($a_usr_id));
179  $mail->send();
180  break;
181 
182  case $this->NOTIFY_DISMISS_MEMBER:
185  $mail->setRefId($this->ref_id);
186  $mail->setRecipients(array($a_usr_id));
187  $mail->send();
188  break;
189 
190  case $this->NOTIFY_BLOCK_MEMBER:
193  $mail->setRefId($this->ref_id);
194  $mail->setRecipients(array($a_usr_id));
195  $mail->send();
196  break;
197 
198  case $this->NOTIFY_UNBLOCK_MEMBER:
201  $mail->setRefId($this->ref_id);
202  $mail->setRecipients(array($a_usr_id));
203  $mail->send();
204  break;
205 
206  case $this->NOTIFY_ACCEPT_USER:
209  $mail->setRefId($this->ref_id);
210  $mail->setRecipients(array($a_usr_id));
211  $mail->send();
212  break;
213 
214  case $this->NOTIFY_STATUS_CHANGED:
217  $mail->setRefId($this->ref_id);
218  $mail->setRecipients(array($a_usr_id));
219  $mail->send();
220  break;
221 
222  case $this->NOTIFY_UNSUBSCRIBE:
225  $mail->setRefId($this->ref_id);
226  $mail->setRecipients(array($a_usr_id));
227  $mail->send();
228  break;
229 
230  case $this->NOTIFY_REGISTERED:
233  $mail->setRefId($this->ref_id);
234  $mail->setRecipients(array($a_usr_id));
235  $mail->send();
236  break;
237 
238  case $this->NOTIFY_WAITING_LIST:
239  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
240  $wl = new ilCourseWaitingList($this->obj_id);
241  $pos = $wl->getPosition($a_usr_id);
242 
245  $mail->setRefId($this->ref_id);
246  $mail->setRecipients(array($a_usr_id));
247  $mail->setAdditionalInformation(array('position' => $pos));
248  $mail->send();
249  break;
250 
251  case $this->NOTIFY_SUBSCRIPTION_REQUEST:
252  $this->sendSubscriptionRequestToAdmins($a_usr_id);
253  break;
254 
255  case $this->NOTIFY_ADMINS:
256  $this->sendNotificationToAdmins($a_usr_id);
257  return true;
258  break;
259  }
260  return true;
261  }
262 
264  {
265  global $ilDB,$ilObjDataCache;
266 
267  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
270  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
271  $mail->setRefId($this->ref_id);
272  $mail->setRecipients($this->getNotificationRecipients());
273  $mail->send();
274  return true;
275  }
276 
277 
278  public function sendSubscriptionRequestToAdmins($a_usr_id)
279  {
280  global $ilDB,$ilObjDataCache;
281 
282  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
285  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
286  $mail->setRefId($this->ref_id);
287  $mail->setRecipients($this->getNotificationRecipients());
288  $mail->send();
289  return true;
290  }
291 
292 
293  public function sendNotificationToAdmins($a_usr_id)
294  {
295  global $ilDB,$ilObjDataCache;
296 
297  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
300  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
301  $mail->setRefId($this->ref_id);
302  $mail->setRecipients($this->getNotificationRecipients());
303  $mail->send();
304  return true;
305  }
306 
307 
308  function __buildStatusBody(&$user_obj)
309  {
310  global $ilDB;
311 
312  $body = $this->lng->txt('crs_status_changed_body')."\n";
313  $body .= $this->lng->txt('login').': '.$user_obj->getLogin()."\n";
314  $body .= $this->lng->txt('role').': ';
315 
316  if($this->isAdmin($user_obj->getId()))
317  {
318  $body .= $this->lng->txt('crs_admin')."\n";
319  }
320  if($this->isTutor($user_obj->getId()))
321  {
322  $body .= $this->lng->txt('crs_tutor')."\n";
323  }
324  if($this->isMember($user_obj->getId()))
325  {
326  $body .= $this->lng->txt('crs_member')."\n";
327  }
328  $body .= $this->lng->txt('status').': ';
329 
330  if($this->isNotificationEnabled($user_obj->getId()))
331  {
332  $body .= $this->lng->txt("crs_notify")."\n";
333  }
334  else
335  {
336  $body .= $this->lng->txt("crs_no_notify")."\n";
337  }
338  if($this->isBlocked($user_obj->getId()))
339  {
340  $body .= $this->lng->txt("crs_blocked")."\n";
341  }
342  else
343  {
344  $body .= $this->lng->txt("crs_unblocked")."\n";
345  }
346  $passed = $this->hasPassed($user_obj->getId()) ? $this->lng->txt('yes') : $this->lng->txt('no');
347  $body .= $this->lng->txt('crs_passed').': '.$passed."\n";
348 
349  return $body;
350  }
351 
352 
353 }
354 ?>