ILIAS  Release_3_10_x_branch Revision 61812
 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 AS ua ".
100  "JOIN rbac_fa AS fa ON ua.rol_id = fa.rol_id ".
101  "JOIN tree AS t1 ON t1.child = fa.parent ".
102  "JOIN object_reference AS obr ON t1.parent = obr.ref_id ".
103  "JOIN object_data AS obd ON obr.obj_id = obd.obj_id ".
104  "WHERE obd.type = ".$ilDB->quote($a_type)." ".
105  "AND fa.assign = 'y' ".
106  "AND ua.usr_id = ".$ilDB->quote($a_usr_id)." ";
107  $res = $ilDB->query($query);
108 
109  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
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)." ".
160  "AND usr_id = ".$ilDB->quote($a_usr_id)." ".
161  "AND blocked = '1'";
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)." ".
181  "AND usr_id = ".$ilDB->quote($a_usr_id)." ".
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)." ";
202 
203  $ilDB->query($query);
204 
205  $query = "DELETE FROM il_subscribers ".
206  "WHERE obj_id = ".$ilDB->quote($a_obj_id)."";
207 
208  $ilDB->query($query);
209 
210  return true;
211  }
212 
221  public static function _deleteUser($a_usr_id)
222  {
223  global $ilDB;
224 
225  $query = "DELETE FROM crs_members WHERE usr_id = ".$ilDB->quote($a_usr_id)."";
226  $ilDB->query($query);
227 
228  $query = "DELETE FROM il_subscribers WHERE usr_id = ".$ilDB->quote($a_usr_id)."";
229  $ilDB->query($query);
230 
231  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
233  }
234 
241  public function getNotificationRecipients()
242  {
243  global $ilDB;
244 
245  $query = "SELECT * FROM crs_members ".
246  "WHERE notification = 1 ".
247  "AND obj_id = ".$ilDB->quote($this->obj_id)." ";
248  $res = $ilDB->query($query);
249  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
250  {
251  if($this->isAdmin($row->usr_id) or $this->isTutor($row->usr_id))
252  {
253  $recp[] = $row->usr_id;
254  }
255  }
256  return $recp ? $recp : array();
257  }
258 
265  public function getCountMembers()
266  {
267  return count($this->members);
268  }
269 
276  public function getCountParticipants()
277  {
278  return count($this->participants);
279  }
280 
281 
282 
283 
290  public function getParticipants()
291  {
292  return $this->participants ? $this->participants : array();
293  }
294 
302  public function getMembers()
303  {
304  return $this->members ? $this->members : array();
305  }
312  public function getAdmins()
313  {
314  return $this->admins ? $this->admins : array();
315  }
322  public function getTutors()
323  {
324  return $this->tutors ? $this->tutors : array();
325  }
326 
334  public function isAdmin($a_usr_id)
335  {
336  return in_array($a_usr_id,$this->admins) ? true : false;
337  }
338 
346  public function isTutor($a_usr_id)
347  {
348  return in_array($a_usr_id,$this->tutors) ? true : false;
349  }
350 
358  public function isMember($a_usr_id)
359  {
360  return in_array($a_usr_id,$this->members) ? true : false;
361  }
362 
363 
364 
365 
373  public function isAssigned($a_usr_id)
374  {
375  return in_array($a_usr_id,$this->participants);
376  }
377 
385  public function getRoles()
386  {
387  return $this->roles ? $this->roles : array();
388  }
389 
397  public function getAssignedRoles($a_usr_id)
398  {
399  global $rbacreview;
400 
401  foreach($this->roles as $role)
402  {
403  if($rbacreview->isAssigned($a_usr_id,$role))
404  {
405  $assigned[] = $role;
406  }
407  }
408  return $assigned ? $assigned : array();
409  }
410 
419  public function updateRoleAssignments($a_usr_id,$a_roles)
420  {
421  global $rbacreview,$rbacadmin;
422 
423  $roles = $a_roles ? $a_roles : array();
424 
425  foreach($this->getRoles() as $role_id)
426  {
427  if($rbacreview->isAssigned($a_usr_id,$role_id))
428  {
429  if(!in_array($role_id,$roles))
430  {
431  $rbacadmin->deassignUser($role_id,$a_usr_id);
432  }
433  }
434  else
435  {
436  if(in_array($role_id,$roles))
437  {
438  $rbacadmin->assignUser($role_id,$a_usr_id);
439  }
440  }
441  }
442  $this->readParticipants();
443  $this->readParticipantsStatus();
444  }
445 
453  public function checkLastAdmin($a_usr_ids)
454  {
455  foreach($this->getAdmins() as $admin_id)
456  {
457  if(!in_array($admin_id,$a_usr_ids))
458  {
459  return true;
460  }
461  }
462  return false;
463  }
464 
472  public function isBlocked($a_usr_id)
473  {
474  if(isset($this->participants_status[$a_usr_id]))
475  {
476  return $this->participants_status[$a_usr_id]['blocked'] ? true : false;
477  }
478  return false;
479  }
480 
488  public function hasPassed($a_usr_id)
489  {
490  if(isset($this->participants_status[$a_usr_id]))
491  {
492  return $this->participants_status[$a_usr_id]['passed'] ? true : false;
493  }
494  return false;
495  }
496 
504  public function delete($a_usr_id)
505  {
506  global $rbacadmin,$ilDB;
507 
508  $this->dropDesktopItem($a_usr_id);
509  foreach($this->roles as $role_id)
510  {
511  $rbacadmin->deassignUser($role_id,$a_usr_id);
512  }
513 
514  $query = "DELETE FROM crs_members ".
515  "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ".
516  "AND obj_id = ".$ilDB->quote($this->obj_id);
517  $ilDB->query($query);
518 
519  $this->readParticipants();
520  $this->readParticipantsStatus();
521 
522  return true;
523  }
524 
533  public function updateBlocked($a_usr_id,$a_blocked)
534  {
535  global $ilDB;
536 
537  $this->participants_status[$a_usr_id]['blocked'] = (int) $a_blocked;
538 
539  $query = "SELECT * FROM crs_members ".
540  "WHERE obj_id = ".$ilDB->quote($this->obj_id)." ".
541  "AND usr_id = ".$ilDB->quote($a_usr_id);
542  $res = $ilDB->query($query);
543  if($res->numRows())
544  {
545  $query = "UPDATE crs_members SET ".
546  "blocked = ".$ilDB->quote((int) $a_blocked)." ".
547  "WHERE obj_id = ".$ilDB->quote($this->obj_id)." ".
548  "AND usr_id = ".$ilDB->quote($a_usr_id);
549  }
550  else
551  {
552  $query = "INSERT INTO crs_members SET ".
553  "blocked = ".$ilDB->quote((int) $a_blocked).", ".
554  "obj_id = ".$ilDB->quote($this->obj_id).", ".
555  "usr_id = ".$ilDB->quote($a_usr_id);
556 
557  }
558  $res = $ilDB->query($query);
559  return true;
560  }
561 
570  public function updateNotification($a_usr_id,$a_notification)
571  {
572  global $ilDB;
573 
574  $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
575 
576  $query = "SELECT * FROM crs_members ".
577  "WHERE obj_id = ".$ilDB->quote($this->obj_id)." ".
578  "AND usr_id = ".$ilDB->quote($a_usr_id);
579  $res = $ilDB->query($query);
580  if($res->numRows())
581  {
582  $query = "UPDATE crs_members SET ".
583  "notification = ".$ilDB->quote((int) $a_notification)." ".
584  "WHERE obj_id = ".$ilDB->quote($this->obj_id)." ".
585  "AND usr_id = ".$ilDB->quote($a_usr_id);
586  }
587  else
588  {
589  $query = "INSERT INTO crs_members SET ".
590  "notification = ".$ilDB->quote((int) $a_notification).", ".
591  "obj_id = ".$ilDB->quote($this->obj_id).", ".
592  "usr_id = ".$ilDB->quote($a_usr_id).", ".
593  "passed = 0 ";
594 
595  }
596  $res = $ilDB->query($query);
597  return true;
598  }
599 
600 
601 
602 
611  public function add($a_usr_id,$a_role)
612  {
613  global $rbacadmin,$ilLog,$ilAppEventHandler;
614 
615  if($this->isAssigned($a_usr_id))
616  {
617  return false;
618  }
619 
620  switch($a_role)
621  {
622  case IL_CRS_ADMIN:
623  $this->admins[] = $a_usr_id;
624  break;
625 
626  case IL_CRS_TUTOR:
627  $this->tutors[] = $a_usr_id;
628  break;
629 
630  case IL_CRS_MEMBER:
631  $this->members[] = $a_usr_id;
632  break;
633 
634  case IL_GRP_ADMIN:
635  $this->admins[] = $a_usr_id;
636  break;
637 
638  case IL_GRP_MEMBER:
639  $this->members[] = $a_usr_id;
640  break;
641  }
642  $this->participants[] = $a_usr_id;
643  $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
644  $this->addDesktopItem($a_usr_id);
645 
646  if($this->type == 'crs') {
647  // Add event: used for ecs accounts
648  $ilLog->write(__METHOD__.': Raise new event: Modules/Course addParticipant');
649  $ilAppEventHandler->raise("Modules/Course", "addParticipant", array('usr_id' => $a_usr_id,'role_id' => $a_role));
650  }
651  return true;
652  }
653 
654 
662  public function deleteParticipants($a_user_ids)
663  {
664  foreach($a_user_ids as $user_id)
665  {
666  $this->delete($user_id);
667  }
668  return true;
669  }
670 
678  public function addDesktopItem($a_usr_id)
679  {
680  if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
681  {
682  ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
683  }
684  return true;
685  }
686 
694  function dropDesktopItem($a_usr_id)
695  {
696  if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
697  {
698  ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
699  }
700 
701  return true;
702  }
703 
704 
705 
713  public function isNotificationEnabled($a_usr_id)
714  {
715  if(isset($this->participants_status[$a_usr_id]))
716  {
717  return $this->participants_status[$a_usr_id]['notification'] ? true : false;
718  }
719  return false;
720  }
721 
722 
730  private function readParticipants()
731  {
732  global $rbacreview,$ilObjDataCache,$ilLog;
733 
734  $rolf = $rbacreview->getRoleFolderOfObject($this->ref_id);
735  if(!isset($rolf['ref_id']) or !$rolf['ref_id'])
736  {
737  $title = $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($this->ref_id));
738  $ilLog->write(__METHOD__.': Found object without role folder. Ref_id: '.$this->ref_id.', title: '.$title);
739  $ilLog->logStack();
740  return false;
741  }
742 
743  $this->roles = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
744 
745  $users = array();
746  $this->participants = array();
747  $this->members = $this->admins = $this->tutors = array();
748  foreach($this->roles as $role_id)
749  {
750  $title = $ilObjDataCache->lookupTitle($role_id);
751  switch(substr($title,0,8))
752  {
753  case 'il_crs_m':
754  $this->role_data[IL_CRS_MEMBER] = $role_id;
755  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
756  $this->members = array_unique(array_merge($assigned,$this->members));
757  break;
758 
759  case 'il_crs_a':
760  $this->role_data[IL_CRS_ADMIN] = $role_id;
761  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
762  $this->admins = $rbacreview->assignedUsers($role_id);
763  break;
764 
765  case 'il_crs_t':
766  $this->role_data[IL_CRS_TUTOR] = $role_id;
767  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
768  $this->tutors = $rbacreview->assignedUsers($role_id);
769  break;
770 
771  case 'il_grp_a':
772  $this->role_data[IL_GRP_ADMIN] = $role_id;
773  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
774  $this->admins = $rbacreview->assignedUsers($role_id);
775  break;
776 
777  case 'il_grp_m':
778  $this->role_data[IL_GRP_MEMBER] = $role_id;
779  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
780  $this->members = $rbacreview->assignedUsers($role_id);
781  break;
782 
783  default:
784  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
785  $this->members = array_unique(array_merge($assigned,$this->members));
786  break;
787  }
788  }
789  }
790 
798  private function readParticipantsStatus()
799  {
800  global $ilDB;
801 
802  $query = "SELECT * FROM crs_members ".
803  "WHERE obj_id = ".$ilDB->quote($this->obj_id)." ";
804  $res = $ilDB->query($query);
805  $this->participants_status = array();
806  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
807  {
808  $this->participants_status[$row->usr_id]['blocked'] = $row->blocked;
809  $this->participants_status[$row->usr_id]['notification'] = $row->notification;
810  $this->participants_status[$row->usr_id]['passed'] = $row->passed;
811  }
812  }
813 
821  public function isGroupingMember($a_usr_id,$a_field = '')
822  {
823  global $rbacreview,$ilObjDataCache,$ilDB;
824 
825  // Used for membership limitations -> check membership by given field
826  if($a_field)
827  {
828  include_once './Services/User/classes/class.ilObjUser.php';
829 
830  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_usr_id);
831  switch($a_field)
832  {
833  case 'login':
834  $and = "AND login = ".$ilDB->quote($tmp_user->getLogin())." ";
835  break;
836  case 'email':
837  $and = "AND email = ".$ilDB->quote($tmp_user->getEmail())." ";
838  break;
839  case 'matriculation':
840  $and = "AND matriculation = ".$ilDB->quote($tmp_user->getMatriculation())." ";
841  break;
842 
843  default:
844  $and = "AND usr_id = '".$a_usr_id."'";
845  break;
846  }
847 
848  if(!$this->getParticipants())
849  {
850  return false;
851  }
852 
853  $query = "SELECT * FROM usr_data as ud ".
854  "WHERE usr_id IN (".implode(",",ilUtil::quoteArray($this->getParticipants())).") ".
855  $and;
856  $res = $ilDB->query($query);
857  return $res->numRows() ? true : false;
858  }
859  }
860 
866  public function getSubscribers()
867  {
868  $this->readSubscribers();
869 
870  return $this->subscribers;
871  }
872 
873 
879  public function getCountSubscribers()
880  {
881  return count($this->getSubscribers());
882  }
883 
889  public function getSubscriberData($a_usr_id)
890  {
891  return $this->readSubscriberData($a_usr_id);
892  }
893 
894 
895 
901  public function assignSubscribers($a_usr_ids)
902  {
903  if(!is_array($a_usr_ids) or !count($a_usr_ids))
904  {
905  return false;
906  }
907  foreach($a_usr_ids as $id)
908  {
909  if(!$this->assignSubscriber($id))
910  {
911  return false;
912  }
913  }
914  return true;
915  }
916 
922  public function assignSubscriber($a_usr_id)
923  {
924  global $ilErr;
925 
926  $ilErr->setMessage("");
927  if(!$this->isSubscriber($a_usr_id))
928  {
929  $ilErr->appendMessage($this->lng->txt("crs_user_notsubscribed"));
930 
931  return false;
932  }
933  if($this->isAssigned($a_usr_id))
934  {
935  $tmp_obj = ilObjectFactory::getInstanceByObjId($a_usr_id);
936  $ilErr->appendMessage($tmp_obj->getLogin().": ".$this->lng->txt("crs_user_already_assigned"));
937 
938  return false;
939  }
940 
941  if(!$tmp_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id))
942  {
943  $ilErr->appendMessage($this->lng->txt("crs_user_not_exists"));
944 
945  return false;
946  }
947 
948  // TODO: must be group or course member role
949  $this->add($tmp_obj->getId(),IL_CRS_MEMBER);
950  $this->deleteSubscriber($a_usr_id);
951 
952  return true;
953  }
954 
960  public function autoFillSubscribers()
961  {
962  $this->readSubscribers();
963 
964  $counter = 0;
965  foreach($this->subscribers as $subscriber)
966  {
967  if(!$this->assignSubscriber($subscriber))
968  {
969  continue;
970  }
971  else
972  {
973  // TODO: notification
974  #$this->sendNotification($this->NOTIFY_ACCEPT_SUBSCRIBER,$subscriber);
975  }
976  ++$counter;
977  }
978 
979  return $counter;
980  }
981 
987  public function addSubscriber($a_usr_id)
988  {
989  global $ilDB;
990 
991  $query = "INSERT INTO il_subscribers ".
992  " VALUES (".$ilDB->quote($a_usr_id).",".$ilDB->quote($this->obj_id).",'', ".$ilDB->quote(time()).")";
993  $res = $this->ilDB->query($query);
994 
995  return true;
996  }
997 
998 
1004  public function updateSubscriptionTime($a_usr_id,$a_subtime)
1005  {
1006  global $ilDB;
1007 
1008  $query = "UPDATE il_subscribers ".
1009  "SET sub_time = ".$ilDB->quote($a_subtime)." ".
1010  "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ".
1011  "AND obj_id = ".$ilDB->quote($this->obj_id)." ";
1012 
1013  $ilDB->query($query);
1014 
1015  return true;
1016  }
1017 
1025  public function updateSubject($a_usr_id,$a_subject)
1026  {
1027  global $ilDB;
1028 
1029  $query = "UPDATE il_subscribers ".
1030  "SET subject = ".$ilDB->quote($a_subject)." ".
1031  "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ".
1032  "AND obj_id = ".$ilDB->quote($this->obj_id)." ";
1033  $ilDB->query($query);
1034  return true;
1035  }
1036 
1037 
1043  public function deleteSubscriber($a_usr_id)
1044  {
1045  global $ilDB;
1046 
1047  $query = "DELETE FROM il_subscribers ".
1048  "WHERE usr_id = ".$a_usr_id." ".
1049  "AND obj_id = ".$ilDB->quote($this->obj_id)." ";
1050 
1051  $res = $ilDB->query($query);
1052 
1053  return true;
1054  }
1055 
1056 
1062  public function deleteSubscribers($a_usr_ids)
1063  {
1064  global $ilErr;
1065 
1066  if(!is_array($a_usr_ids) or !count($a_usr_ids))
1067  {
1068  $ilErr->setMessage('');
1069  $ilErr->appendMessage($this->lng->txt("no_usr_ids_given"));
1070 
1071  return false;
1072  }
1073  foreach($a_usr_ids as $id)
1074  {
1075  if(!$this->deleteSubscriber($id))
1076  {
1077  $ilErr->appendMessage($this->lng->txt("error_delete_subscriber"));
1078 
1079  return false;
1080  }
1081  }
1082  return true;
1083  }
1084 
1085 
1091  public function isSubscriber($a_usr_id)
1092  {
1093  global $ilDB;
1094 
1095  $query = "SELECT * FROM il_subscribers ".
1096  "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ".
1097  "AND obj_id = ".$ilDB->quote($this->obj_id)."";
1098 
1099  $res = $ilDB->query($query);
1100 
1101  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1102  {
1103  return true;
1104  }
1105  return false;
1106  }
1107 
1114  public static function _isSubscriber($a_obj_id,$a_usr_id)
1115  {
1116  global $ilDB;
1117 
1118  $query = "SELECT * FROM il_subscribers ".
1119  "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ".
1120  "AND obj_id = ".$ilDB->quote($a_obj_id)."";
1121 
1122  $res = $ilDB->query($query);
1123 
1124  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1125  {
1126  return true;
1127  }
1128  return false;
1129  }
1130 
1136  protected function readSubscribers()
1137  {
1138  global $ilDB;
1139 
1140  $this->subscribers = array();
1141 
1142  $query = "SELECT usr_id FROM il_subscribers ".
1143  "WHERE obj_id = ".$ilDB->quote($this->obj_id)." ".
1144  "ORDER BY sub_time ";
1145 
1146  $res = $this->ilDB->query($query);
1147  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1148  {
1149  // DELETE SUBSCRIPTION IF USER HAS BEEN DELETED
1150  if(!ilObjectFactory::getInstanceByObjId($row->usr_id,false))
1151  {
1152  $this->deleteSubscriber($row->usr_id);
1153  }
1154  $this->subscribers[] = $row->usr_id;
1155  }
1156  return true;
1157  }
1158 
1164  protected function readSubscriberData($a_usr_id)
1165  {
1166  global $ilDB;
1167 
1168  $query = "SELECT * FROM il_subscribers ".
1169  "WHERE obj_id = ".$ilDB->quote($this->obj_id)." ".
1170  "AND usr_id = ".$ilDB->quote($a_usr_id)."";
1171 
1172  $res = $this->ilDB->query($query);
1173  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1174  {
1175  $data["time"] = $row->sub_time;
1176  $data["usr_id"] = $row->usr_id;
1177  $data['subject'] = $row->subject;
1178  }
1179  return $data ? $data : array();
1180  }
1181 }
1182 ?>