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