ILIAS  eassessment Revision 61809
 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 
91  public function updatePassed($a_usr_id,$a_passed)
92  {
93  global $ilDB;
94 
95  $this->participants_status[$a_usr_id]['passed'] = (int) $a_passed;
96 
97  $query = "SELECT * FROM crs_members ".
98  "WHERE obj_id = ".$ilDB->quote($this->obj_id,'integer')." ".
99  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer');
100  $res = $ilDB->query($query);
101  if($res->numRows())
102  {
103  $query = "UPDATE crs_members SET ".
104  "passed = ".$ilDB->quote((int) $a_passed,'integer')." ".
105  "WHERE obj_id = ".$ilDB->quote($this->obj_id,'integer')." ".
106  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer');
107  }
108  else
109  {
110  $query = "INSERT INTO crs_members (passed,obj_id,usr_id,notification,blocked) ".
111  "VALUES ( ".
112  $ilDB->quote((int) $a_passed,'integer').", ".
113  $ilDB->quote($this->obj_id,'integer').", ".
114  $ilDB->quote($a_usr_id,'integer').", ".
115  $ilDB->quote(0,'integer').", ".
116  $ilDB->quote(0,'integer')." ".
117  ")";
118 
119  }
120  $res = $ilDB->manipulate($query);
121  return true;
122 
123  }
124 
125 
126 
127 
128  // Subscription
129  function sendNotification($a_type, $a_usr_id)
130  {
131  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
132 
133  global $ilObjDataCache,$ilUser;
134 
135  switch($a_type)
136  {
137  case $this->NOTIFY_DISMISS_SUBSCRIBER:
140  $mail->setRefId($this->ref_id);
141  $mail->setRecipients(array($a_usr_id));
142  $mail->send();
143  break;
144 
145  case $this->NOTIFY_ACCEPT_SUBSCRIBER:
148  $mail->setRefId($this->ref_id);
149  $mail->setRecipients(array($a_usr_id));
150  $mail->send();
151  break;
152 
153  case $this->NOTIFY_DISMISS_MEMBER:
156  $mail->setRefId($this->ref_id);
157  $mail->setRecipients(array($a_usr_id));
158  $mail->send();
159  break;
160 
161  case $this->NOTIFY_BLOCK_MEMBER:
164  $mail->setRefId($this->ref_id);
165  $mail->setRecipients(array($a_usr_id));
166  $mail->send();
167  break;
168 
169  case $this->NOTIFY_UNBLOCK_MEMBER:
172  $mail->setRefId($this->ref_id);
173  $mail->setRecipients(array($a_usr_id));
174  $mail->send();
175  break;
176 
177  case $this->NOTIFY_ACCEPT_USER:
180  $mail->setRefId($this->ref_id);
181  $mail->setRecipients(array($a_usr_id));
182  $mail->send();
183  break;
184 
185  case $this->NOTIFY_STATUS_CHANGED:
188  $mail->setRefId($this->ref_id);
189  $mail->setRecipients(array($a_usr_id));
190  $mail->send();
191  break;
192 
193  case $this->NOTIFY_UNSUBSCRIBE:
196  $mail->setRefId($this->ref_id);
197  $mail->setRecipients(array($a_usr_id));
198  $mail->send();
199  break;
200 
201  case $this->NOTIFY_REGISTERED:
204  $mail->setRefId($this->ref_id);
205  $mail->setRecipients(array($a_usr_id));
206  $mail->send();
207  break;
208 
209  case $this->NOTIFY_WAITING_LIST:
210  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
211  $wl = new ilCourseWaitingList($this->obj_id);
212  $pos = $wl->getPosition($a_usr_id);
213 
216  $mail->setRefId($this->ref_id);
217  $mail->setRecipients(array($a_usr_id));
218  $mail->setAdditionalInformation(array('position' => $pos));
219  $mail->send();
220  break;
221 
222  case $this->NOTIFY_SUBSCRIPTION_REQUEST:
223  $this->sendSubscriptionRequestToAdmins($a_usr_id);
224  break;
225 
226  case $this->NOTIFY_ADMINS:
227  $this->sendNotificationToAdmins($a_usr_id);
228  return true;
229  break;
230  }
231  return true;
232  }
233 
235  {
236  global $ilDB,$ilObjDataCache;
237 
238  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
241  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
242  $mail->setRefId($this->ref_id);
243  $mail->setRecipients($this->getNotificationRecipients());
244  $mail->send();
245  return true;
246  }
247 
248 
249  public function sendSubscriptionRequestToAdmins($a_usr_id)
250  {
251  global $ilDB,$ilObjDataCache;
252 
253  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
256  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
257  $mail->setRefId($this->ref_id);
258  $mail->setRecipients($this->getNotificationRecipients());
259  $mail->send();
260  return true;
261  }
262 
263 
264  public function sendNotificationToAdmins($a_usr_id)
265  {
266  global $ilDB,$ilObjDataCache;
267 
268  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
271  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
272  $mail->setRefId($this->ref_id);
273  $mail->setRecipients($this->getNotificationRecipients());
274  $mail->send();
275  return true;
276  }
277 
278 
279  function __buildStatusBody(&$user_obj)
280  {
281  global $ilDB;
282 
283  $body = $this->lng->txt('crs_status_changed_body')."\n";
284  $body .= $this->lng->txt('login').': '.$user_obj->getLogin()."\n";
285  $body .= $this->lng->txt('role').': ';
286 
287  if($this->isAdmin($user_obj->getId()))
288  {
289  $body .= $this->lng->txt('crs_admin')."\n";
290  }
291  if($this->isTutor($user_obj->getId()))
292  {
293  $body .= $this->lng->txt('crs_tutor')."\n";
294  }
295  if($this->isMember($user_obj->getId()))
296  {
297  $body .= $this->lng->txt('crs_member')."\n";
298  }
299  $body .= $this->lng->txt('status').': ';
300 
301  if($this->isNotificationEnabled($user_obj->getId()))
302  {
303  $body .= $this->lng->txt("crs_notify")."\n";
304  }
305  else
306  {
307  $body .= $this->lng->txt("crs_no_notify")."\n";
308  }
309  if($this->isBlocked($user_obj->getId()))
310  {
311  $body .= $this->lng->txt("crs_blocked")."\n";
312  }
313  else
314  {
315  $body .= $this->lng->txt("crs_unblocked")."\n";
316  }
317  $passed = $this->hasPassed($user_obj->getId()) ? $this->lng->txt('yes') : $this->lng->txt('no');
318  $body .= $this->lng->txt('crs_passed').': '.$passed."\n";
319 
320  return $body;
321  }
322 
323 
324 }
325 ?>