ILIAS  Release_3_10_x_branch Revision 61812
 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  parent::__construct($a_obj_id);
60  }
61 
70  public static function _getInstanceByObjId($a_obj_id)
71  {
72  if(isset(self::$instances[$a_obj_id]) and self::$instances[$a_obj_id])
73  {
74  return self::$instances[$a_obj_id];
75  }
76  return self::$instances[$a_obj_id] = new ilCourseParticipants($a_obj_id);
77  }
78 
79 
80 
81 
90  public function updatePassed($a_usr_id,$a_passed)
91  {
92  global $ilDB;
93 
94  $this->participants_status[$a_usr_id]['passed'] = (int) $a_passed;
95 
96  $query = "SELECT * FROM crs_members ".
97  "WHERE obj_id = ".$ilDB->quote($this->obj_id)." ".
98  "AND usr_id = ".$ilDB->quote($a_usr_id);
99  $res = $ilDB->query($query);
100  if($res->numRows())
101  {
102  $query = "UPDATE crs_members SET ".
103  "passed = ".$ilDB->quote((int) $a_passed)." ".
104  "WHERE obj_id = ".$ilDB->quote($this->obj_id)." ".
105  "AND usr_id = ".$ilDB->quote($a_usr_id);
106  }
107  else
108  {
109  $query = "INSERT INTO crs_members SET ".
110  "passed = ".$ilDB->quote((int) $a_passed).", ".
111  "obj_id = ".$ilDB->quote($this->obj_id).", ".
112  "usr_id = ".$ilDB->quote($a_usr_id);
113 
114  }
115  $res = $ilDB->query($query);
116  return true;
117 
118  }
119 
120 
121 
122 
123  // Subscription
124  function sendNotification($a_type, $a_usr_id)
125  {
126  global $ilObjDataCache,$ilUser;
127 
128  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_usr_id,false);
129 
130  $link = ("\n\n".$this->lng->txt('crs_mail_permanent_link'));
131  $link .= ("\n\n".ILIAS_HTTP_PATH."/goto.php?target=crs_".$this->ref_id."&client_id=".CLIENT_ID);
132 
133  switch($a_type)
134  {
135  case $this->NOTIFY_DISMISS_SUBSCRIBER:
136  $subject = $this->lng->txt("crs_reject_subscriber");
137  $body = $this->lng->txt("crs_reject_subscriber_body");
138  break;
139 
140  case $this->NOTIFY_ACCEPT_SUBSCRIBER:
141  $subject = $this->lng->txt("crs_accept_subscriber");
142  $body = $this->lng->txt("crs_accept_subscriber_body");
143  $body .= $link;
144  break;
145  case $this->NOTIFY_DISMISS_MEMBER:
146  $subject = $this->lng->txt("crs_dismiss_member");
147  $body = $this->lng->txt("crs_dismiss_member_body");
148  break;
149  case $this->NOTIFY_BLOCK_MEMBER:
150  $subject = $this->lng->txt("crs_blocked_member");
151  $body = $this->lng->txt("crs_blocked_member_body");
152  break;
153  case $this->NOTIFY_UNBLOCK_MEMBER:
154  $subject = $this->lng->txt("crs_unblocked_member");
155  $body = $this->lng->txt("crs_unblocked_member_body");
156  $body .= $link;
157  break;
158  case $this->NOTIFY_ACCEPT_USER:
159  $subject = $this->lng->txt("crs_added_member");
160  $body = $this->lng->txt("crs_added_member_body");
161  $body .= $link;
162  break;
163  case $this->NOTIFY_STATUS_CHANGED:
164  $subject = $this->lng->txt("crs_status_changed");
165  $body = $this->__buildStatusBody($tmp_user);
166  $body .= $link;
167  break;
168 
169  case $this->NOTIFY_SUBSCRIPTION_REQUEST:
170  $this->sendSubscriptionRequestToAdmins($a_usr_id);
171  return true;
172  break;
173 
174  case $this->NOTIFY_ADMINS:
175  $this->sendNotificationToAdmins($a_usr_id);
176 
177  return true;
178  break;
179  }
180  $subject = sprintf($subject,$ilObjDataCache->lookupTitle($this->obj_id));
181  $body = sprintf($body,$ilObjDataCache->lookupTitle($this->obj_id));
182 
183  include_once("Services/Mail/classes/class.ilMail.php");
184  $mail = new ilMail($ilUser->getId());
185  $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('system'));
186 
187  unset($tmp_user);
188  return true;
189  }
190 
192  {
193  global $ilDB,$ilObjDataCache;
194 
195 
196  include_once("Services/Mail/classes/class.ilFormatMail.php");
197 
198  $mail =& new ilFormatMail($a_usr_id);
199  $subject = sprintf($this->lng->txt("crs_cancel_subscription"),$ilObjDataCache->lookupTitle($this->obj_id));
200  $body = sprintf($this->lng->txt("crs_cancel_subscription_body"),$ilObjDataCache->lookupTitle($this->obj_id));
201  $body .= ("\n\n".$this->lng->txt('crs_mail_permanent_link'));
202  $body .= ("\n\n".ILIAS_HTTP_PATH."/goto.php?target=crs_".$this->ref_id."&client_id=".CLIENT_ID);
203 
204 
205  foreach($this->getNotificationRecipients() as $usr_id)
206  {
207  $tmp_user =& ilObjectFactory::getInstanceByObjId($usr_id,false);
208  $message = $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('system'));
209  unset($tmp_user);
210  }
211  return true;
212  }
213 
214 
216  {
217  global $ilDB,$ilObjDataCache,$ilUser;
218 
219  include_once("Services/Mail/classes/class.ilMail.php");
220 
221  $mail = new ilMail($ilUser->getId());
222  $subject = sprintf($this->lng->txt("crs_new_subscription_request"),$ilObjDataCache->lookupTitle($this->obj_id));
223  $body = sprintf($this->lng->txt("crs_new_subscription_request_body"),$ilObjDataCache->lookupTitle($this->obj_id));
224  $body .= ("\n\n".$this->lng->txt('crs_new_subscription_request_body2'));
225  $body .= ("\n\n".ILIAS_HTTP_PATH."/goto.php?target=crs_".$this->ref_id."&client_id=".CLIENT_ID);
226 
227  foreach($this->getNotificationRecipients() as $usr_id)
228  {
229  $tmp_user =& ilObjectFactory::getInstanceByObjId($usr_id,false);
230  $message = $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('system'));
231  }
232  return true;
233  }
234 
235 
236  function sendNotificationToAdmins($a_usr_id)
237  {
238  global $ilDB,$ilObjDataCache;
239 
240  include_once("Services/Mail/classes/class.ilFormatMail.php");
241 
242  $mail =& new ilFormatMail($a_usr_id);
243  $subject = sprintf($this->lng->txt("crs_new_subscription"),$ilObjDataCache->lookupTitle($this->obj_id));
244  $body = sprintf($this->lng->txt("crs_new_subscription_body"),$ilObjDataCache->lookupTitle($this->obj_id));
245  $body .= ("\n\n".ILIAS_HTTP_PATH."/goto.php?target=crs_".$this->ref_id."&client_id=".CLIENT_ID);
246 
247  foreach($this->getNotificationRecipients() as $usr_id)
248  {
249  if($this->isAdmin($usr_id) or $this->isTutor($usr_id))
250  {
251  $tmp_user =& ilObjectFactory::getInstanceByObjId($usr_id,false);
252  $message = $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('system'));
253  unset($tmp_user);
254  }
255  }
256  unset($mail);
257 
258  return true;
259  }
260 
261 
262  function __buildStatusBody(&$user_obj)
263  {
264  global $ilDB;
265 
266  $body = $this->lng->txt('crs_status_changed_body')."\n";
267  $body .= $this->lng->txt('login').': '.$user_obj->getLogin()."\n";
268  $body .= $this->lng->txt('role').': ';
269 
270  if($this->isAdmin($user_obj->getId()))
271  {
272  $body .= $this->lng->txt('crs_admin')."\n";
273  }
274  if($this->isTutor($user_obj->getId()))
275  {
276  $body .= $this->lng->txt('crs_tutor')."\n";
277  }
278  if($this->isMember($user_obj->getId()))
279  {
280  $body .= $this->lng->txt('crs_member')."\n";
281  }
282  $body .= $this->lng->txt('status').': ';
283 
284  if($this->isNotificationEnabled($user_obj->getId()))
285  {
286  $body .= $this->lng->txt("crs_notify")."\n";
287  }
288  else
289  {
290  $body .= $this->lng->txt("crs_no_notify")."\n";
291  }
292  if($this->isBlocked($user_obj->getId()))
293  {
294  $body .= $this->lng->txt("crs_blocked")."\n";
295  }
296  else
297  {
298  $body .= $this->lng->txt("crs_unblocked")."\n";
299  }
300  $passed = $this->hasPassed($user_obj->getId()) ? $this->lng->txt('yes') : $this->lng->txt('no');
301  $body .= $this->lng->txt('crs_passed').': '.$passed."\n";
302 
303  return $body;
304  }
305 
306 
307 }
308 ?>