ILIAS  Release_4_0_x_branch Revision 61816
 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  protected 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 
81  $this->readParticipants();
82  $this->readParticipantsStatus();
83  }
84 
95  public static function _getMembershipByType($a_usr_id,$a_type)
96  {
97  global $ilDB;
98 
99  $query = "SELECT DISTINCT obd.obj_id,obr.ref_id FROM rbac_ua ua ".
100  "JOIN rbac_fa fa ON ua.rol_id = fa.rol_id ".
101  "JOIN tree t1 ON t1.child = fa.parent ".
102  "JOIN object_reference obr ON t1.parent = obr.ref_id ".
103  "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
104  "WHERE obd.type = ".$ilDB->quote($a_type,'text')." ".
105  "AND fa.assign = 'y' ".
106  "AND ua.usr_id = ".$ilDB->quote($a_usr_id,'integer')." ";
107  $res = $ilDB->query($query);
108 
109  while($row = $ilDB->fetchObject($res))
110  {
111  $ref_ids[] = $row->obj_id;
112  }
113 
114  return $ref_ids ? $ref_ids : array();
115  }
116 
117 
118 
127  public static function _isParticipant($a_ref_id,$a_usr_id)
128  {
129  global $rbacreview,$ilObjDataCache,$ilDB,$ilLog;
130 
131  $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
132  if(!isset($rolf['ref_id']) or !$rolf['ref_id'])
133  {
134  $title = $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($a_ref_id));
135  $ilLog->write(__METHOD__.': Found object without role folder. Ref_id: '.$a_ref_id.', title: '.$title);
136  $ilLog->logStack();
137 
138  return false;
139  }
140  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
141 
142  return $rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id, $local_roles);
143  }
144 
154  public static function _isBlocked($a_obj_id,$a_usr_id)
155  {
156  global $ilDB;
157 
158  $query = "SELECT * FROM crs_members ".
159  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
160  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer')." ".
161  "AND blocked = ".$ilDB->quote(1,'integer');
162  $res = $ilDB->query($query);
163  return $res->numRows() ? true : false;
164  }
165 
175  public static function _hasPassed($a_obj_id,$a_usr_id)
176  {
177  global $ilDB;
178 
179  $query = "SELECT * FROM crs_members ".
180  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
181  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
182  "AND passed = '1'";
183  $res = $ilDB->query($query);
184  return $res->numRows() ? true : false;
185  }
186 
196  public static function _deleteAllEntries($a_obj_id)
197  {
198  global $ilDB;
199 
200  $query = "DELETE FROM crs_members ".
201  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
202  $res = $ilDB->manipulate($query);
203 
204  $query = "DELETE FROM il_subscribers ".
205  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
206  $res = $ilDB->manipulate($query);
207 
208  return true;
209  }
210 
219  public static function _deleteUser($a_usr_id)
220  {
221  global $ilDB;
222 
223  $query = "DELETE FROM crs_members WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
224  $res = $ilDB->manipulate($query);
225 
226  $query = "DELETE FROM il_subscribers WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
227  $res = $ilDB->manipulate($query);
228 
229  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
231  }
232 
233  public static function getDefaultMemberRole($a_ref_id)
234  {
235  global $ilCtrl;
236 
237  $obj_id = ilObject::_lookupObjId($a_ref_id);
239 
240  if(!in_array($type,array('crs','grp')))
241  {
242  return 0;
243  }
244 
245  global $rbacreview;
246 
247 
248  $rolf = $rbacreview->getRoleFolderIdOfObject($a_ref_id);
249  $roles = $rbacreview->getRolesOfRoleFolder($rolf,false);
250 
251  foreach($roles as $role)
252  {
254  if(substr($title, 0, 13) == ('il_'.$type.'_member'))
255  {
256  return $role;
257  }
258  }
259  return 0;
260  }
261 
268  public function getNotificationRecipients()
269  {
270  global $ilDB;
271 
272  $query = "SELECT * FROM crs_members ".
273  "WHERE notification = 1 ".
274  "AND obj_id = ".$ilDB->quote($this->obj_id)." ";
275  $res = $ilDB->query($query);
276  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
277  {
278  if($this->isAdmin($row->usr_id) or $this->isTutor($row->usr_id))
279  {
280  $recp[] = $row->usr_id;
281  }
282  }
283  return $recp ? $recp : array();
284  }
285 
292  public function getCountMembers()
293  {
294  return count($this->members);
295  }
296 
303  public function getCountParticipants()
304  {
305  return count($this->participants);
306  }
307 
308 
309 
310 
317  public function getParticipants()
318  {
319  return $this->participants ? $this->participants : array();
320  }
321 
329  public function getMembers()
330  {
331  return $this->members ? $this->members : array();
332  }
339  public function getAdmins()
340  {
341  return $this->admins ? $this->admins : array();
342  }
349  public function getTutors()
350  {
351  return $this->tutors ? $this->tutors : array();
352  }
353 
361  public function isAdmin($a_usr_id)
362  {
363  return in_array($a_usr_id,$this->admins) ? true : false;
364  }
365 
373  public function isTutor($a_usr_id)
374  {
375  return in_array($a_usr_id,$this->tutors) ? true : false;
376  }
377 
385  public function isMember($a_usr_id)
386  {
387  return in_array($a_usr_id,$this->members) ? true : false;
388  }
389 
390 
391 
392 
400  public function isAssigned($a_usr_id)
401  {
402  return in_array($a_usr_id,$this->participants);
403  }
404 
410  public function isLastAdmin($a_usr_id)
411  {
412  return in_array($a_usr_id,$this->getAdmins()) and count($this->getAdmins()) == 1;
413  }
414 
415 
423  public function getRoles()
424  {
425  return $this->roles ? $this->roles : array();
426  }
427 
435  public function getAssignedRoles($a_usr_id)
436  {
437  global $rbacreview;
438 
439  foreach($this->roles as $role)
440  {
441  if($rbacreview->isAssigned($a_usr_id,$role))
442  {
443  $assigned[] = $role;
444  }
445  }
446  return $assigned ? $assigned : array();
447  }
448 
457  public function updateRoleAssignments($a_usr_id,$a_roles)
458  {
459  global $rbacreview,$rbacadmin;
460 
461  $roles = $a_roles ? $a_roles : array();
462 
463  foreach($this->getRoles() as $role_id)
464  {
465  if($rbacreview->isAssigned($a_usr_id,$role_id))
466  {
467  if(!in_array($role_id,$roles))
468  {
469  $rbacadmin->deassignUser($role_id,$a_usr_id);
470  }
471  }
472  else
473  {
474  if(in_array($role_id,$roles))
475  {
476  $rbacadmin->assignUser($role_id,$a_usr_id);
477  }
478  }
479  }
480  $this->readParticipants();
481  $this->readParticipantsStatus();
482  }
483 
491  public function checkLastAdmin($a_usr_ids)
492  {
493  foreach($this->getAdmins() as $admin_id)
494  {
495  if(!in_array($admin_id,$a_usr_ids))
496  {
497  return true;
498  }
499  }
500  return false;
501  }
502 
510  public function isBlocked($a_usr_id)
511  {
512  if(isset($this->participants_status[$a_usr_id]))
513  {
514  return $this->participants_status[$a_usr_id]['blocked'] ? true : false;
515  }
516  return false;
517  }
518 
526  public function hasPassed($a_usr_id)
527  {
528  if(isset($this->participants_status[$a_usr_id]))
529  {
530  return $this->participants_status[$a_usr_id]['passed'] ? true : false;
531  }
532  return false;
533  }
534 
542  public function delete($a_usr_id)
543  {
544  global $rbacadmin,$ilDB;
545 
546  $this->dropDesktopItem($a_usr_id);
547  foreach($this->roles as $role_id)
548  {
549  $rbacadmin->deassignUser($role_id,$a_usr_id);
550  }
551 
552  $query = "DELETE FROM crs_members ".
553  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
554  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer');
555  $res = $ilDB->manipulate($query);
556 
557  $this->readParticipants();
558  $this->readParticipantsStatus();
559 
560  return true;
561  }
562 
571  public function updateBlocked($a_usr_id,$a_blocked)
572  {
573  global $ilDB;
574 
575  $this->participants_status[$a_usr_id]['blocked'] = (int) $a_blocked;
576 
577  $query = "SELECT * FROM crs_members ".
578  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
579  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
580  $res = $ilDB->query($query);
581  if($res->numRows())
582  {
583  $query = "UPDATE crs_members SET ".
584  "blocked = ".$ilDB->quote((int) $a_blocked ,'integer')." ".
585  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
586  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
587  }
588  else
589  {
590  $query = "INSERT INTO crs_members (blocked,obj_id,usr_id,notification,passed) ".
591  "VALUES ( ".
592  $ilDB->quote((int) $a_blocked ,'integer').", ".
593  $ilDB->quote($this->obj_id ,'integer').", ".
594  $ilDB->quote($a_usr_id ,'integer').", ".
595  $ilDB->quote(0,'integer').", ".
596  $ilDB->quote(0,'integer').
597  ")";
598 
599  }
600  $res = $ilDB->manipulate($query);
601  return true;
602  }
603 
612  public function updateNotification($a_usr_id,$a_notification)
613  {
614  global $ilDB;
615 
616  $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
617 
618  $query = "SELECT * FROM crs_members ".
619  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
620  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
621  $res = $ilDB->query($query);
622  if($res->numRows())
623  {
624  $query = "UPDATE crs_members SET ".
625  "notification = ".$ilDB->quote((int) $a_notification ,'integer')." ".
626  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
627  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
628  }
629  else
630  {
631  $query = "INSERT INTO crs_members (notification,obj_id,usr_id,passed,blocked) ".
632  "VALUES ( ".
633  $ilDB->quote((int) $a_notification ,'integer').", ".
634  $ilDB->quote($this->obj_id ,'integer').", ".
635  $ilDB->quote($a_usr_id ,'integer').", ".
636  $ilDB->quote(0,'integer').", ".
637  $ilDB->quote(0,'integer').
638  ")";
639 
640  }
641  $res = $ilDB->manipulate($query);
642  return true;
643  }
644 
645 
646 
647 
656  public function add($a_usr_id,$a_role)
657  {
658  global $rbacadmin,$ilLog,$ilAppEventHandler;
659 
660  if($this->isAssigned($a_usr_id))
661  {
662  return false;
663  }
664 
665  switch($a_role)
666  {
667  case IL_CRS_ADMIN:
668  $this->admins[] = $a_usr_id;
669  break;
670 
671  case IL_CRS_TUTOR:
672  $this->tutors[] = $a_usr_id;
673  break;
674 
675  case IL_CRS_MEMBER:
676  $this->members[] = $a_usr_id;
677  break;
678 
679  case IL_GRP_ADMIN:
680  $this->admins[] = $a_usr_id;
681  break;
682 
683  case IL_GRP_MEMBER:
684  $this->members[] = $a_usr_id;
685  break;
686  }
687  $this->participants[] = $a_usr_id;
688  $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
689  $this->addDesktopItem($a_usr_id);
690 
691  // Delete subscription request
692  $this->deleteSubscriber($a_usr_id);
693 
694  include_once './Services/Membership/classes/class.ilWaitingList.php';
695  ilWaitingList::deleteUserEntry($a_usr_id,$this->obj_id);
696 
697  if($this->type == 'crs') {
698  // Add event: used for ecs accounts
699  $ilLog->write(__METHOD__.': Raise new event: Modules/Course addParticipant');
700  $ilAppEventHandler->raise("Modules/Course", "addParticipant", array('usr_id' => $a_usr_id,'role_id' => $a_role));
701  }
702  return true;
703  }
704 
705 
713  public function deleteParticipants($a_user_ids)
714  {
715  foreach($a_user_ids as $user_id)
716  {
717  $this->delete($user_id);
718  }
719  return true;
720  }
721 
729  public function addDesktopItem($a_usr_id)
730  {
731  if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
732  {
733  ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
734  }
735  return true;
736  }
737 
745  function dropDesktopItem($a_usr_id)
746  {
747  if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
748  {
749  ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
750  }
751 
752  return true;
753  }
754 
755 
756 
764  public function isNotificationEnabled($a_usr_id)
765  {
766  if(isset($this->participants_status[$a_usr_id]))
767  {
768  return $this->participants_status[$a_usr_id]['notification'] ? true : false;
769  }
770  return false;
771  }
772 
773 
781  private function readParticipants()
782  {
783  global $rbacreview,$ilObjDataCache,$ilLog;
784 
785  $rolf = $rbacreview->getRoleFolderOfObject($this->ref_id);
786  if(!isset($rolf['ref_id']) or !$rolf['ref_id'])
787  {
788  $title = $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($this->ref_id));
789  $ilLog->write(__METHOD__.': Found object without role folder. Ref_id: '.$this->ref_id.', title: '.$title);
790  $ilLog->logStack();
791  return false;
792  }
793 
794  $this->roles = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
795 
796  $users = array();
797  $this->participants = array();
798  $this->members = $this->admins = $this->tutors = array();
799  foreach($this->roles as $role_id)
800  {
801  $title = $ilObjDataCache->lookupTitle($role_id);
802  switch(substr($title,0,8))
803  {
804  case 'il_crs_m':
805  $this->role_data[IL_CRS_MEMBER] = $role_id;
806  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
807  $this->members = array_unique(array_merge($assigned,$this->members));
808  break;
809 
810  case 'il_crs_a':
811  $this->role_data[IL_CRS_ADMIN] = $role_id;
812  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
813  $this->admins = $rbacreview->assignedUsers($role_id);
814  break;
815 
816  case 'il_crs_t':
817  $this->role_data[IL_CRS_TUTOR] = $role_id;
818  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
819  $this->tutors = $rbacreview->assignedUsers($role_id);
820  break;
821 
822  case 'il_grp_a':
823  $this->role_data[IL_GRP_ADMIN] = $role_id;
824  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
825  $this->admins = $rbacreview->assignedUsers($role_id);
826  break;
827 
828  case 'il_grp_m':
829  $this->role_data[IL_GRP_MEMBER] = $role_id;
830  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
831  $this->members = $rbacreview->assignedUsers($role_id);
832  break;
833 
834  default:
835  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
836  $this->members = array_unique(array_merge($assigned,$this->members));
837  break;
838  }
839  }
840  }
841 
849  private function readParticipantsStatus()
850  {
851  global $ilDB;
852 
853  $query = "SELECT * FROM crs_members ".
854  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
855  $res = $ilDB->query($query);
856  $this->participants_status = array();
857  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
858  {
859  $this->participants_status[$row->usr_id]['blocked'] = $row->blocked;
860  $this->participants_status[$row->usr_id]['notification'] = $row->notification;
861  $this->participants_status[$row->usr_id]['passed'] = $row->passed;
862  }
863  }
864 
872  public function isGroupingMember($a_usr_id,$a_field = '')
873  {
874  global $rbacreview,$ilObjDataCache,$ilDB;
875 
876  // Used for membership limitations -> check membership by given field
877  if($a_field)
878  {
879  include_once './Services/User/classes/class.ilObjUser.php';
880 
881  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_usr_id);
882  switch($a_field)
883  {
884  case 'login':
885  $and = "AND login = ".$ilDB->quote($tmp_user->getLogin(),'text')." ";
886  break;
887  case 'email':
888  $and = "AND email = ".$ilDB->quote($tmp_user->getEmail(),'text')." ";
889  break;
890  case 'matriculation':
891  $and = "AND matriculation = ".$ilDB->quote($tmp_user->getMatriculation(),'text')." ";
892  break;
893 
894  default:
895  $and = "AND usr_id = ".$ilDB->quote($a_usr_id,'integer'). " ";
896  break;
897  }
898 
899  if(!$this->getParticipants())
900  {
901  return false;
902  }
903 
904  $query = "SELECT * FROM usr_data ud ".
905  "WHERE ".$ilDB->in('usr_id',$this->getParticipants(),false,'integer')." ".
906  $and;
907 
908  $res = $ilDB->query($query);
909  return $res->numRows() ? true : false;
910  }
911  }
912 
918  public function getSubscribers()
919  {
920  $this->readSubscribers();
921 
922  return $this->subscribers;
923  }
924 
925 
931  public function getCountSubscribers()
932  {
933  return count($this->getSubscribers());
934  }
935 
941  public function getSubscriberData($a_usr_id)
942  {
943  return $this->readSubscriberData($a_usr_id);
944  }
945 
946 
947 
953  public function assignSubscribers($a_usr_ids)
954  {
955  if(!is_array($a_usr_ids) or !count($a_usr_ids))
956  {
957  return false;
958  }
959  foreach($a_usr_ids as $id)
960  {
961  if(!$this->assignSubscriber($id))
962  {
963  return false;
964  }
965  }
966  return true;
967  }
968 
974  public function assignSubscriber($a_usr_id)
975  {
976  global $ilErr;
977 
978  $ilErr->setMessage("");
979  if(!$this->isSubscriber($a_usr_id))
980  {
981  $ilErr->appendMessage($this->lng->txt("crs_user_notsubscribed"));
982 
983  return false;
984  }
985  if($this->isAssigned($a_usr_id))
986  {
987  $tmp_obj = ilObjectFactory::getInstanceByObjId($a_usr_id);
988  $ilErr->appendMessage($tmp_obj->getLogin().": ".$this->lng->txt("crs_user_already_assigned"));
989 
990  return false;
991  }
992 
993  if(!$tmp_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id))
994  {
995  $ilErr->appendMessage($this->lng->txt("crs_user_not_exists"));
996 
997  return false;
998  }
999 
1000  // TODO: must be group or course member role
1001  $this->add($tmp_obj->getId(),IL_CRS_MEMBER);
1002  $this->deleteSubscriber($a_usr_id);
1003 
1004  return true;
1005  }
1006 
1012  public function autoFillSubscribers()
1013  {
1014  $this->readSubscribers();
1015 
1016  $counter = 0;
1017  foreach($this->subscribers as $subscriber)
1018  {
1019  if(!$this->assignSubscriber($subscriber))
1020  {
1021  continue;
1022  }
1023  else
1024  {
1025  // TODO: notification
1026  #$this->sendNotification($this->NOTIFY_ACCEPT_SUBSCRIBER,$subscriber);
1027  }
1028  ++$counter;
1029  }
1030 
1031  return $counter;
1032  }
1033 
1039  public function addSubscriber($a_usr_id)
1040  {
1041  global $ilDB;
1042 
1043  $query = "INSERT INTO il_subscribers (usr_id,obj_id,subject,sub_time) ".
1044  " VALUES (".
1045  $ilDB->quote($a_usr_id ,'integer').",".
1046  $ilDB->quote($this->obj_id ,'integer').", ".
1047  $ilDB->quote('','text').", ".
1048  $ilDB->quote(time() ,'integer').
1049  ")";
1050  $res = $ilDB->manipulate($query);
1051 
1052  return true;
1053  }
1054 
1055 
1061  public function updateSubscriptionTime($a_usr_id,$a_subtime)
1062  {
1063  global $ilDB;
1064 
1065  $query = "UPDATE il_subscribers ".
1066  "SET sub_time = ".$ilDB->quote($a_subtime ,'integer')." ".
1067  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1068  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1069  $res = $ilDB->manipulate($query);
1070 
1071  return true;
1072  }
1073 
1081  public function updateSubject($a_usr_id,$a_subject)
1082  {
1083  global $ilDB;
1084 
1085  $query = "UPDATE il_subscribers ".
1086  "SET subject = ".$ilDB->quote($a_subject ,'text')." ".
1087  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1088  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1089  $res = $ilDB->manipulate($query);
1090  return true;
1091  }
1092 
1093 
1099  public function deleteSubscriber($a_usr_id)
1100  {
1101  global $ilDB;
1102 
1103  $query = "DELETE FROM il_subscribers ".
1104  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1105  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1106  $res = $ilDB->manipulate($query);
1107 
1108  return true;
1109  }
1110 
1111 
1117  public function deleteSubscribers($a_usr_ids)
1118  {
1119  global $ilErr;
1120 
1121  if(!is_array($a_usr_ids) or !count($a_usr_ids))
1122  {
1123  $ilErr->setMessage('');
1124  $ilErr->appendMessage($this->lng->txt("no_usr_ids_given"));
1125 
1126  return false;
1127  }
1128  foreach($a_usr_ids as $id)
1129  {
1130  if(!$this->deleteSubscriber($id))
1131  {
1132  $ilErr->appendMessage($this->lng->txt("error_delete_subscriber"));
1133 
1134  return false;
1135  }
1136  }
1137  return true;
1138  }
1139 
1140 
1146  public function isSubscriber($a_usr_id)
1147  {
1148  global $ilDB;
1149 
1150  $query = "SELECT * FROM il_subscribers ".
1151  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1152  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')."";
1153 
1154  $res = $ilDB->query($query);
1155  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1156  {
1157  return true;
1158  }
1159  return false;
1160  }
1161 
1168  public static function _isSubscriber($a_obj_id,$a_usr_id)
1169  {
1170  global $ilDB;
1171 
1172  $query = "SELECT * FROM il_subscribers ".
1173  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1174  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
1175 
1176  $res = $ilDB->query($query);
1177  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1178  {
1179  return true;
1180  }
1181  return false;
1182  }
1183 
1189  protected function readSubscribers()
1190  {
1191  global $ilDB;
1192 
1193  $this->subscribers = array();
1194 
1195  $query = "SELECT usr_id FROM il_subscribers ".
1196  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
1197  "ORDER BY sub_time ";
1198 
1199  $res = $this->ilDB->query($query);
1200  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1201  {
1202  // DELETE SUBSCRIPTION IF USER HAS BEEN DELETED
1203  if(!ilObjectFactory::getInstanceByObjId($row->usr_id,false))
1204  {
1205  $this->deleteSubscriber($row->usr_id);
1206  }
1207  $this->subscribers[] = $row->usr_id;
1208  }
1209  return true;
1210  }
1211 
1217  protected function readSubscriberData($a_usr_id)
1218  {
1219  global $ilDB;
1220 
1221  $query = "SELECT * FROM il_subscribers ".
1222  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
1223  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
1224 
1225  $res = $this->ilDB->query($query);
1226  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1227  {
1228  $data["time"] = $row->sub_time;
1229  $data["usr_id"] = $row->usr_id;
1230  $data['subject'] = $row->subject;
1231  }
1232  return $data ? $data : array();
1233  }
1234 }
1235 ?>