ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilParticipants.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 
32 define("IL_CRS_ADMIN",1);
33 define("IL_CRS_TUTOR",3);
34 define("IL_CRS_MEMBER",2);
35 
36 define('IL_GRP_ADMIN',4);
37 define('IL_GRP_MEMBER',5);
38 
39 
41 {
42  protected $obj_id = 0;
43  protected $type = '';
44  protected $ref_id = 0;
45 
46  protected $roles = array();
47  protected $role_data = array();
48 
49  protected $participants = array();
50  protected $participants_status = array();
51  protected $members = array();
52  protected $tutors = array();
53  protected $admins = array();
54 
55  protected $subscribers = array();
56 
57  protected $ilDB;
58  protected $lng;
59 
60 
68  public function __construct($a_obj_id)
69  {
70  global $ilDB,$lng;
71 
72  $this->ilDB = $ilDB;
73  $this->lng = $lng;
74 
75  $this->obj_id = $a_obj_id;
76  $this->type = ilObject::_lookupType($a_obj_id);
77  $ref_ids = ilObject::_getAllReferences($this->obj_id);
78  $this->ref_id = current($ref_ids);
79 
80  $this->readParticipants();
81  $this->readParticipantsStatus();
82  }
83 
94  public static function _getMembershipByType($a_usr_id,$a_type)
95  {
96  global $ilDB;
97 
98  $query = "SELECT DISTINCT obd.obj_id,obr.ref_id FROM rbac_ua ua ".
99  "JOIN rbac_fa fa ON ua.rol_id = fa.rol_id ".
100  "JOIN tree t1 ON t1.child = fa.parent ".
101  "JOIN object_reference obr ON t1.parent = obr.ref_id ".
102  "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
103  "WHERE obd.type = ".$ilDB->quote($a_type,'text')." ".
104  "AND fa.assign = 'y' ".
105  "AND ua.usr_id = ".$ilDB->quote($a_usr_id,'integer')." ";
106  $res = $ilDB->query($query);
107 
108  while($row = $ilDB->fetchObject($res))
109  {
110  $ref_ids[] = $row->obj_id;
111  }
112 
113  return $ref_ids ? $ref_ids : array();
114  }
115 
116 
117 
126  public static function _isParticipant($a_ref_id,$a_usr_id)
127  {
128  global $rbacreview,$ilObjDataCache,$ilDB,$ilLog;
129 
130  $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
131  if(!isset($rolf['ref_id']) or !$rolf['ref_id'])
132  {
133  $title = $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($a_ref_id));
134  $ilLog->write(__METHOD__.': Found object without role folder. Ref_id: '.$a_ref_id.', title: '.$title);
135  $ilLog->logStack();
136 
137  return false;
138  }
139  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
140 
141  return $rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id, $local_roles);
142  }
143 
153  public static function _isBlocked($a_obj_id,$a_usr_id)
154  {
155  global $ilDB;
156 
157  $query = "SELECT * FROM crs_members ".
158  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
159  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer')." ".
160  "AND blocked = ".$ilDB->quote(1,'integer');
161  $res = $ilDB->query($query);
162  return $res->numRows() ? true : false;
163  }
164 
174  public static function _hasPassed($a_obj_id,$a_usr_id)
175  {
176  global $ilDB;
177 
178  $query = "SELECT * FROM crs_members ".
179  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
180  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
181  "AND passed = '1'";
182  $res = $ilDB->query($query);
183  return $res->numRows() ? true : false;
184  }
185 
195  public static function _deleteAllEntries($a_obj_id)
196  {
197  global $ilDB;
198 
199  $query = "DELETE FROM crs_members ".
200  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
201  $res = $ilDB->manipulate($query);
202 
203  $query = "DELETE FROM il_subscribers ".
204  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
205  $res = $ilDB->manipulate($query);
206 
207  return true;
208  }
209 
218  public static function _deleteUser($a_usr_id)
219  {
220  global $ilDB;
221 
222  $query = "DELETE FROM crs_members WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
223  $res = $ilDB->manipulate($query);
224 
225  $query = "DELETE FROM il_subscribers WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
226  $res = $ilDB->manipulate($query);
227 
228  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
230  }
231 
232  public static function getDefaultMemberRole($a_ref_id)
233  {
234  global $ilCtrl;
235 
236  $obj_id = ilObject::_lookupObjId($a_ref_id);
238 
239  if(!in_array($type,array('crs','grp')))
240  {
241  return 0;
242  }
243 
244  global $rbacreview;
245 
246 
247  $rolf = $rbacreview->getRoleFolderIdOfObject($a_ref_id);
248  $roles = $rbacreview->getRolesOfRoleFolder($rolf,false);
249 
250  foreach($roles as $role)
251  {
253  if(substr($title, 0, 13) == ('il_'.$type.'_member'))
254  {
255  return $role;
256  }
257  }
258  return 0;
259  }
260 
267  public function getNotificationRecipients()
268  {
269  global $ilDB;
270 
271  $query = "SELECT * FROM crs_members ".
272  "WHERE notification = 1 ".
273  "AND obj_id = ".$ilDB->quote($this->obj_id)." ";
274  $res = $ilDB->query($query);
275  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
276  {
277  if($this->isAdmin($row->usr_id) or $this->isTutor($row->usr_id))
278  {
279  $recp[] = $row->usr_id;
280  }
281  }
282  return $recp ? $recp : array();
283  }
284 
291  public function getCountMembers()
292  {
293  return count($this->members);
294  }
295 
302  public function getCountParticipants()
303  {
304  return count($this->participants);
305  }
306 
307 
308 
309 
316  public function getParticipants()
317  {
318  return $this->participants ? $this->participants : array();
319  }
320 
328  public function getMembers()
329  {
330  return $this->members ? $this->members : array();
331  }
338  public function getAdmins()
339  {
340  return $this->admins ? $this->admins : array();
341  }
342 
347  public function getCountAdmins()
348  {
349  return count($this->getAdmins());
350  }
351 
352 
359  public function getTutors()
360  {
361  return $this->tutors ? $this->tutors : array();
362  }
363 
371  public function isAdmin($a_usr_id)
372  {
373  return in_array($a_usr_id,$this->admins) ? true : false;
374  }
375 
383  public function isTutor($a_usr_id)
384  {
385  return in_array($a_usr_id,$this->tutors) ? true : false;
386  }
387 
395  public function isMember($a_usr_id)
396  {
397  return in_array($a_usr_id,$this->members) ? true : false;
398  }
399 
400 
401 
402 
410  public function isAssigned($a_usr_id)
411  {
412  return in_array($a_usr_id,$this->participants);
413  }
414 
420  public function isLastAdmin($a_usr_id)
421  {
422  return in_array($a_usr_id,$this->getAdmins()) and count($this->getAdmins()) == 1;
423  }
424 
425 
433  public function getRoles()
434  {
435  return $this->roles ? $this->roles : array();
436  }
437 
445  public function getAssignedRoles($a_usr_id)
446  {
447  global $rbacreview;
448 
449  foreach($this->roles as $role)
450  {
451  if($rbacreview->isAssigned($a_usr_id,$role))
452  {
453  $assigned[] = $role;
454  }
455  }
456  return $assigned ? $assigned : array();
457  }
458 
467  public function updateRoleAssignments($a_usr_id,$a_roles)
468  {
469  global $rbacreview,$rbacadmin;
470 
471  $roles = $a_roles ? $a_roles : array();
472 
473  foreach($this->getRoles() as $role_id)
474  {
475  if($rbacreview->isAssigned($a_usr_id,$role_id))
476  {
477  if(!in_array($role_id,$roles))
478  {
479  $rbacadmin->deassignUser($role_id,$a_usr_id);
480  }
481  }
482  else
483  {
484  if(in_array($role_id,$roles))
485  {
486  $rbacadmin->assignUser($role_id,$a_usr_id);
487  }
488  }
489  }
490  $this->readParticipants();
491  $this->readParticipantsStatus();
492  }
493 
501  public function checkLastAdmin($a_usr_ids)
502  {
503  foreach($this->getAdmins() as $admin_id)
504  {
505  if(!in_array($admin_id,$a_usr_ids))
506  {
507  return true;
508  }
509  }
510  return false;
511  }
512 
520  public function isBlocked($a_usr_id)
521  {
522  if(isset($this->participants_status[$a_usr_id]))
523  {
524  return $this->participants_status[$a_usr_id]['blocked'] ? true : false;
525  }
526  return false;
527  }
528 
536  public function hasPassed($a_usr_id)
537  {
538  if(isset($this->participants_status[$a_usr_id]))
539  {
540  return $this->participants_status[$a_usr_id]['passed'] ? true : false;
541  }
542  return false;
543  }
544 
552  public function delete($a_usr_id)
553  {
554  global $rbacadmin,$ilDB;
555 
556  $this->dropDesktopItem($a_usr_id);
557  foreach($this->roles as $role_id)
558  {
559  $rbacadmin->deassignUser($role_id,$a_usr_id);
560  }
561 
562  $query = "DELETE FROM crs_members ".
563  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
564  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer');
565  $res = $ilDB->manipulate($query);
566 
567  $this->readParticipants();
568  $this->readParticipantsStatus();
569 
570  return true;
571  }
572 
581  public function updateBlocked($a_usr_id,$a_blocked)
582  {
583  global $ilDB;
584 
585  $this->participants_status[$a_usr_id]['blocked'] = (int) $a_blocked;
586 
587  $query = "SELECT * FROM crs_members ".
588  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
589  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
590  $res = $ilDB->query($query);
591  if($res->numRows())
592  {
593  $query = "UPDATE crs_members SET ".
594  "blocked = ".$ilDB->quote((int) $a_blocked ,'integer')." ".
595  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
596  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
597  }
598  else
599  {
600  $query = "INSERT INTO crs_members (blocked,obj_id,usr_id,notification,passed) ".
601  "VALUES ( ".
602  $ilDB->quote((int) $a_blocked ,'integer').", ".
603  $ilDB->quote($this->obj_id ,'integer').", ".
604  $ilDB->quote($a_usr_id ,'integer').", ".
605  $ilDB->quote(0,'integer').", ".
606  $ilDB->quote(0,'integer').
607  ")";
608 
609  }
610  $res = $ilDB->manipulate($query);
611  return true;
612  }
613 
622  public function updateNotification($a_usr_id,$a_notification)
623  {
624  global $ilDB;
625 
626  $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
627 
628  $query = "SELECT * FROM crs_members ".
629  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
630  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
631  $res = $ilDB->query($query);
632  if($res->numRows())
633  {
634  $query = "UPDATE crs_members SET ".
635  "notification = ".$ilDB->quote((int) $a_notification ,'integer')." ".
636  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
637  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
638  }
639  else
640  {
641  $query = "INSERT INTO crs_members (notification,obj_id,usr_id,passed,blocked) ".
642  "VALUES ( ".
643  $ilDB->quote((int) $a_notification ,'integer').", ".
644  $ilDB->quote($this->obj_id ,'integer').", ".
645  $ilDB->quote($a_usr_id ,'integer').", ".
646  $ilDB->quote(0,'integer').", ".
647  $ilDB->quote(0,'integer').
648  ")";
649 
650  }
651  $res = $ilDB->manipulate($query);
652  return true;
653  }
654 
655 
656 
657 
666  public function add($a_usr_id,$a_role)
667  {
668  global $rbacadmin,$ilLog,$ilAppEventHandler;
669 
670  if($this->isAssigned($a_usr_id))
671  {
672  return false;
673  }
674 
675  switch($a_role)
676  {
677  case IL_CRS_ADMIN:
678  $this->admins[] = $a_usr_id;
679  break;
680 
681  case IL_CRS_TUTOR:
682  $this->tutors[] = $a_usr_id;
683  break;
684 
685  case IL_CRS_MEMBER:
686  $this->members[] = $a_usr_id;
687  break;
688 
689  case IL_GRP_ADMIN:
690  $this->admins[] = $a_usr_id;
691  break;
692 
693  case IL_GRP_MEMBER:
694  $this->members[] = $a_usr_id;
695  break;
696  }
697 
698  $this->participants[] = $a_usr_id;
699  $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
700  $this->addDesktopItem($a_usr_id);
701 
702  // Delete subscription request
703  $this->deleteSubscriber($a_usr_id);
704 
705  include_once './Services/Membership/classes/class.ilWaitingList.php';
706  ilWaitingList::deleteUserEntry($a_usr_id,$this->obj_id);
707 
708  if($this->type == 'crs') {
709  // Add event: used for ecs accounts
710  $ilLog->write(__METHOD__.': Raise new event: Modules/Course addParticipant');
711  $ilAppEventHandler->raise("Modules/Course", "addParticipant", array('usr_id' => $a_usr_id,'role_id' => $a_role));
712  }
713  return true;
714  }
715 
716 
724  public function deleteParticipants($a_user_ids)
725  {
726  foreach($a_user_ids as $user_id)
727  {
728  $this->delete($user_id);
729  }
730  return true;
731  }
732 
740  public function addDesktopItem($a_usr_id)
741  {
742  if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
743  {
744  ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
745  }
746  return true;
747  }
748 
756  function dropDesktopItem($a_usr_id)
757  {
758  if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
759  {
760  ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
761  }
762 
763  return true;
764  }
765 
766 
767 
775  public function isNotificationEnabled($a_usr_id)
776  {
777  if(isset($this->participants_status[$a_usr_id]))
778  {
779  return $this->participants_status[$a_usr_id]['notification'] ? true : false;
780  }
781  return false;
782  }
783 
784 
792  private function readParticipants()
793  {
794  global $rbacreview,$ilObjDataCache,$ilLog;
795 
796  $rolf = $rbacreview->getRoleFolderOfObject($this->ref_id);
797 
798  if(!isset($rolf['ref_id']) or !$rolf['ref_id'])
799  {
800  $title = $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($this->ref_id));
801  $ilLog->write(__METHOD__.': Found object without role folder. Ref_id: '.$this->ref_id.', title: '.$title);
802  $ilLog->logStack();
803  return false;
804  }
805 
806  $this->roles = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
807 
808  $users = array();
809  $this->participants = array();
810  $this->members = $this->admins = $this->tutors = array();
811 
812  foreach($this->roles as $role_id)
813  {
814  $title = $ilObjDataCache->lookupTitle($role_id);
815  switch(substr($title,0,8))
816  {
817  case 'il_crs_m':
818  $this->role_data[IL_CRS_MEMBER] = $role_id;
819  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
820  $this->members = array_unique(array_merge($assigned,$this->members));
821  break;
822 
823  case 'il_crs_a':
824  $this->role_data[IL_CRS_ADMIN] = $role_id;
825  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
826  $this->admins = $rbacreview->assignedUsers($role_id);
827  break;
828 
829  case 'il_crs_t':
830  $this->role_data[IL_CRS_TUTOR] = $role_id;
831  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
832  $this->tutors = $rbacreview->assignedUsers($role_id);
833  break;
834 
835  case 'il_grp_a':
836  $this->role_data[IL_GRP_ADMIN] = $role_id;
837  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
838  $this->admins = $rbacreview->assignedUsers($role_id);
839  break;
840 
841  case 'il_grp_m':
842  $this->role_data[IL_GRP_MEMBER] = $role_id;
843  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
844  $this->members = $rbacreview->assignedUsers($role_id);
845  break;
846 
847  default:
848  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
849  $this->members = array_unique(array_merge($assigned,$this->members));
850  break;
851  }
852  }
853  }
854 
862  private function readParticipantsStatus()
863  {
864  global $ilDB;
865 
866  $query = "SELECT * FROM crs_members ".
867  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
868  $res = $ilDB->query($query);
869  $this->participants_status = array();
870  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
871  {
872  $this->participants_status[$row->usr_id]['blocked'] = $row->blocked;
873  $this->participants_status[$row->usr_id]['notification'] = $row->notification;
874  $this->participants_status[$row->usr_id]['passed'] = $row->passed;
875  }
876  }
877 
885  public function isGroupingMember($a_usr_id,$a_field = '')
886  {
887  global $rbacreview,$ilObjDataCache,$ilDB;
888 
889  // Used for membership limitations -> check membership by given field
890  if($a_field)
891  {
892  include_once './Services/User/classes/class.ilObjUser.php';
893 
894  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_usr_id);
895  switch($a_field)
896  {
897  case 'login':
898  $and = "AND login = ".$ilDB->quote($tmp_user->getLogin(),'text')." ";
899  break;
900  case 'email':
901  $and = "AND email = ".$ilDB->quote($tmp_user->getEmail(),'text')." ";
902  break;
903  case 'matriculation':
904  $and = "AND matriculation = ".$ilDB->quote($tmp_user->getMatriculation(),'text')." ";
905  break;
906 
907  default:
908  $and = "AND usr_id = ".$ilDB->quote($a_usr_id,'integer'). " ";
909  break;
910  }
911 
912  if(!$this->getParticipants())
913  {
914  return false;
915  }
916 
917  $query = "SELECT * FROM usr_data ud ".
918  "WHERE ".$ilDB->in('usr_id',$this->getParticipants(),false,'integer')." ".
919  $and;
920 
921  $res = $ilDB->query($query);
922  return $res->numRows() ? true : false;
923  }
924  }
925 
931  public function getSubscribers()
932  {
933  $this->readSubscribers();
934 
935  return $this->subscribers;
936  }
937 
938 
944  public function getCountSubscribers()
945  {
946  return count($this->getSubscribers());
947  }
948 
954  public function getSubscriberData($a_usr_id)
955  {
956  return $this->readSubscriberData($a_usr_id);
957  }
958 
959 
960 
966  public function assignSubscribers($a_usr_ids)
967  {
968  if(!is_array($a_usr_ids) or !count($a_usr_ids))
969  {
970  return false;
971  }
972  foreach($a_usr_ids as $id)
973  {
974  if(!$this->assignSubscriber($id))
975  {
976  return false;
977  }
978  }
979  return true;
980  }
981 
987  public function assignSubscriber($a_usr_id)
988  {
989  global $ilErr;
990 
991  $ilErr->setMessage("");
992  if(!$this->isSubscriber($a_usr_id))
993  {
994  $ilErr->appendMessage($this->lng->txt("crs_user_notsubscribed"));
995 
996  return false;
997  }
998  if($this->isAssigned($a_usr_id))
999  {
1000  $tmp_obj = ilObjectFactory::getInstanceByObjId($a_usr_id);
1001  $ilErr->appendMessage($tmp_obj->getLogin().": ".$this->lng->txt("crs_user_already_assigned"));
1002 
1003  return false;
1004  }
1005 
1006  if(!$tmp_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id))
1007  {
1008  $ilErr->appendMessage($this->lng->txt("crs_user_not_exists"));
1009 
1010  return false;
1011  }
1012 
1013  // TODO: must be group or course member role
1014  $this->add($tmp_obj->getId(),IL_CRS_MEMBER);
1015  $this->deleteSubscriber($a_usr_id);
1016 
1017  return true;
1018  }
1019 
1025  public function autoFillSubscribers()
1026  {
1027  $this->readSubscribers();
1028 
1029  $counter = 0;
1030  foreach($this->subscribers as $subscriber)
1031  {
1032  if(!$this->assignSubscriber($subscriber))
1033  {
1034  continue;
1035  }
1036  else
1037  {
1038  // TODO: notification
1039  #$this->sendNotification($this->NOTIFY_ACCEPT_SUBSCRIBER,$subscriber);
1040  }
1041  ++$counter;
1042  }
1043 
1044  return $counter;
1045  }
1046 
1052  public function addSubscriber($a_usr_id)
1053  {
1054  global $ilDB;
1055 
1056  $query = "INSERT INTO il_subscribers (usr_id,obj_id,subject,sub_time) ".
1057  " VALUES (".
1058  $ilDB->quote($a_usr_id ,'integer').",".
1059  $ilDB->quote($this->obj_id ,'integer').", ".
1060  $ilDB->quote('','text').", ".
1061  $ilDB->quote(time() ,'integer').
1062  ")";
1063  $res = $ilDB->manipulate($query);
1064 
1065  return true;
1066  }
1067 
1068 
1074  public function updateSubscriptionTime($a_usr_id,$a_subtime)
1075  {
1076  global $ilDB;
1077 
1078  $query = "UPDATE il_subscribers ".
1079  "SET sub_time = ".$ilDB->quote($a_subtime ,'integer')." ".
1080  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1081  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1082  $res = $ilDB->manipulate($query);
1083 
1084  return true;
1085  }
1086 
1094  public function updateSubject($a_usr_id,$a_subject)
1095  {
1096  global $ilDB;
1097 
1098  $query = "UPDATE il_subscribers ".
1099  "SET subject = ".$ilDB->quote($a_subject ,'text')." ".
1100  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1101  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1102  $res = $ilDB->manipulate($query);
1103  return true;
1104  }
1105 
1106 
1112  public function deleteSubscriber($a_usr_id)
1113  {
1114  global $ilDB;
1115 
1116  $query = "DELETE FROM il_subscribers ".
1117  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1118  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1119  $res = $ilDB->manipulate($query);
1120 
1121  return true;
1122  }
1123 
1124 
1130  public function deleteSubscribers($a_usr_ids)
1131  {
1132  global $ilErr,$ilDB;
1133 
1134  if(!is_array($a_usr_ids) or !count($a_usr_ids))
1135  {
1136  $ilErr->setMessage('');
1137  $ilErr->appendMessage($this->lng->txt("no_usr_ids_given"));
1138 
1139  return false;
1140  }
1141  $query = "DELETE FROM il_subscribers ".
1142  "WHERE ".$ilDB->in('usr_id',(array) $a_usr_ids,false,'integer')." ".
1143  "AND obj_id = ".$ilDB->quote($this->obj_id,'integer');
1144  $res = $ilDB->query($query);
1145  return true;
1146  }
1147 
1148 
1154  public function isSubscriber($a_usr_id)
1155  {
1156  global $ilDB;
1157 
1158  $query = "SELECT * FROM il_subscribers ".
1159  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1160  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')."";
1161 
1162  $res = $ilDB->query($query);
1163  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1164  {
1165  return true;
1166  }
1167  return false;
1168  }
1169 
1176  public static function _isSubscriber($a_obj_id,$a_usr_id)
1177  {
1178  global $ilDB;
1179 
1180  $query = "SELECT * FROM il_subscribers ".
1181  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1182  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
1183 
1184  $res = $ilDB->query($query);
1185  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1186  {
1187  return true;
1188  }
1189  return false;
1190  }
1191 
1197  protected function readSubscribers()
1198  {
1199  global $ilDB;
1200 
1201  $this->subscribers = array();
1202 
1203  $query = "SELECT usr_id FROM il_subscribers ".
1204  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
1205  "ORDER BY sub_time ";
1206 
1207  $res = $this->ilDB->query($query);
1208  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1209  {
1210  // DELETE SUBSCRIPTION IF USER HAS BEEN DELETED
1211  if(!ilObjectFactory::getInstanceByObjId($row->usr_id,false))
1212  {
1213  $this->deleteSubscriber($row->usr_id);
1214  }
1215  $this->subscribers[] = $row->usr_id;
1216  }
1217  return true;
1218  }
1219 
1225  protected function readSubscriberData($a_usr_id)
1226  {
1227  global $ilDB;
1228 
1229  $query = "SELECT * FROM il_subscribers ".
1230  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
1231  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
1232 
1233  $res = $this->ilDB->query($query);
1234  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1235  {
1236  $data["time"] = $row->sub_time;
1237  $data["usr_id"] = $row->usr_id;
1238  $data['subject'] = $row->subject;
1239  }
1240  return $data ? $data : array();
1241  }
1242 }
1243 ?>