ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilParticipants.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12define("IL_CRS_ADMIN",1);
13define("IL_CRS_TUTOR",3);
14define("IL_CRS_MEMBER",2);
15
16define('IL_GRP_ADMIN',4);
17define('IL_GRP_MEMBER',5);
18
19
20abstract class ilParticipants
21{
22 protected $component = '';
23
24 protected $obj_id = 0;
25 protected $type = '';
26 protected $ref_id = 0;
27
28 protected $roles = array();
29 protected $role_data = array();
30
31 protected $participants = array();
32 protected $participants_status = array();
33 protected $members = array();
34 protected $tutors = array();
35 protected $admins = array();
36
37 protected $subscribers = array();
38
39 protected $ilDB;
40 protected $lng;
41
42
50 public function __construct($a_component_name, $a_obj_id)
51 {
52 global $ilDB,$lng;
53
54 $this->ilDB = $ilDB;
55 $this->lng = $lng;
56
57 $this->component = $a_component_name;
58
59 $this->obj_id = $a_obj_id;
60 $this->type = ilObject::_lookupType($a_obj_id);
61 $ref_ids = ilObject::_getAllReferences($this->obj_id);
62 $this->ref_id = current($ref_ids);
63
64 $this->readParticipants();
66 }
67
75 public static function getInstanceByObjId($a_obj_id)
76 {
77 $type = ilObject::_lookupType($a_obj_id);
78 switch($type)
79 {
80 case 'crs':
81 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
83
84 case 'grp':
85 include_once './Modules/Group/classes/class.ilGroupParticipants.php';
87
88 case 'sess':
89 include_once './Modules/Session/classes/class.ilSessionParticipants.php';
91
92 default:
93 $GLOBALS['ilLog']->logStack();
94 $GLOBALS['ilLog']->write(__METHOD__.': Invalid obj_id given: '.$a_obj_id);
95 throw new InvalidArgumentException('Invalid obj id given');
96 }
97 }
98
103 protected function getComponent()
104 {
105 return $this->component;
106 }
107
108
109
115 public static function hasParticipantListAccess($a_obj_id, $a_usr_id = null)
116 {
117 if(!$a_usr_id)
118 {
119 $a_usr_id = $GLOBALS['ilUser']->getId();
120 }
121
122 // if write access granted => return true
123 $refs = ilObject::_getAllReferences($a_obj_id);
124 $ref_id = end($refs);
125
126 if($GLOBALS['ilAccess']->checkAccess('write','',$ref_id))
127 {
128 return true;
129 }
130 $part = self::getInstanceByObjId($a_obj_id);
131 if($part->isAssigned($a_usr_id))
132 {
133 if($part->getType() == 'crs')
134 {
135 // Check for show_members
136 include_once './Modules/Course/classes/class.ilObjCourse.php';
138 {
139 return false;
140 }
141 }
142 return true;
143 }
144 // User is not assigned to course/group => no read access
145 return false;
146 }
147
159 public static function _getMembershipByType($a_usr_id,$a_type,$a_only_member_role = false)
160 {
161 global $ilDB;
162
163 // this will also dismiss local roles!
164 if ($a_only_member_role)
165 {
166 $j2 = "JOIN object_data obd2 ON (ua.rol_id = obd2.obj_id) ";
167 $a2 = "AND obd2.title LIKE 'il_".$a_type."_mem%' ";
168 }
169
170 // #14290 - no role folder anymore
171 $query = "SELECT DISTINCT obd.obj_id,obr.ref_id FROM rbac_ua ua ".
172 "JOIN rbac_fa fa ON ua.rol_id = fa.rol_id ".
173 "JOIN object_reference obr ON fa.parent = obr.ref_id ".
174 "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
175 $j2.
176 "WHERE obd.type = ".$ilDB->quote($a_type,'text')." ".
177 "AND fa.assign = 'y' ".
178 "AND ua.usr_id = ".$ilDB->quote($a_usr_id,'integer')." ".
179 $a2;
180
181 $res = $ilDB->query($query);
182 while($row = $ilDB->fetchObject($res))
183 {
184 $ref_ids[] = $row->obj_id;
185 }
186
187 return $ref_ids ? $ref_ids : array();
188 }
189
190
191
200 public static function _isParticipant($a_ref_id,$a_usr_id)
201 {
202 global $rbacreview,$ilObjDataCache,$ilDB,$ilLog;
203
204 $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
205
206 return $rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id, $local_roles);
207 }
208
216 public static function lookupNumberOfParticipants($a_ref_id)
217 {
218 global $rbacreview;
219
220 $lroles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
221 return $rbacreview->getNumberOfAssignedUsers($lroles);
222 }
223
231 public static function lookupNumberOfMembers($a_ref_id)
232 {
233 global $rbacreview, $ilObjDataCache;
234
235 $has_policies = $rbacreview->getLocalPolicies($a_ref_id);
236
237 if(!$has_policies)
238 {
239 return 0;
240 }
241 $lroles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
242
243 $memberRoles = array();
244 foreach($lroles as $role_id)
245 {
246 $title = $ilObjDataCache->lookupTitle($role_id);
247 switch(substr($title,0,8))
248 {
249 case 'il_crs_a':
250 case 'il_crs_t':
251 case 'il_grp_a':
252 break;
253
254 default:
255 $memberRoles[] = $role_id;
256 break;
257 }
258 }
259 return $rbacreview->getNumberOfAssignedUsers($memberRoles);
260 }
261
262
272 public static function _isBlocked($a_obj_id,$a_usr_id)
273 {
274 global $ilDB;
275
276 $query = "SELECT * FROM obj_members ".
277 "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
278 "AND usr_id = ".$ilDB->quote($a_usr_id,'integer')." ".
279 "AND blocked = ".$ilDB->quote(1,'integer');
280 $res = $ilDB->query($query);
281 return $res->numRows() ? true : false;
282 }
283
293 public static function _hasPassed($a_obj_id,$a_usr_id)
294 {
295 global $ilDB;
296
297 $query = "SELECT * FROM obj_members ".
298 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
299 "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
300 "AND passed = '1'";
301 $res = $ilDB->query($query);
302 return $res->numRows() ? true : false;
303 }
304
314 public static function _deleteAllEntries($a_obj_id)
315 {
316 global $ilDB;
317
318 $query = "DELETE FROM obj_members ".
319 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
320 $res = $ilDB->manipulate($query);
321
322 $query = "DELETE FROM il_subscribers ".
323 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
324 $res = $ilDB->manipulate($query);
325
326 $query = 'DELETE FROM crs_waiting_list '.
327 'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
328 $ilDB->manipulate($query);
329
330 return true;
331 }
332
341 public static function _deleteUser($a_usr_id)
342 {
343 global $ilDB;
344
345 $query = "DELETE FROM obj_members WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
346 $res = $ilDB->manipulate($query);
347
348 $query = "DELETE FROM il_subscribers WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
349 $res = $ilDB->manipulate($query);
350
351 include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
353 }
354
355 public static function getDefaultMemberRole($a_ref_id)
356 {
357 global $ilCtrl;
358
359 $obj_id = ilObject::_lookupObjId($a_ref_id);
361
362 if(!in_array($type,array('crs','grp')))
363 {
364 return 0;
365 }
366
367 global $rbacreview;
368
369
370 $roles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
371
372 foreach($roles as $role)
373 {
374 $title = ilObject::_lookupTitle($role);
375 if(substr($title, 0, 13) == ('il_'.$type.'_member'))
376 {
377 return $role;
378 }
379 }
380 return 0;
381 }
382
387 public function getObjId()
388 {
389 return $this->obj_id;
390 }
391
396 public function getType()
397 {
398 return $this->type;
399 }
400
408 {
409 global $ilDB;
410
411 $query = "SELECT * FROM obj_members ".
412 "WHERE notification = 1 ".
413 "AND obj_id = ".$ilDB->quote($this->obj_id)." ";
414 $res = $ilDB->query($query);
415 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
416 {
417 if($this->isAdmin($row->usr_id) or $this->isTutor($row->usr_id))
418 {
419 $recp[] = $row->usr_id;
420 }
421 }
422 return $recp ? $recp : array();
423 }
424
431 public function getCountMembers()
432 {
433 return count($this->members);
434 }
435
442 public function getCountParticipants()
443 {
444 return count($this->participants);
445 }
446
447
448
449
456 public function getParticipants()
457 {
458 return $this->participants ? $this->participants : array();
459 }
460
468 public function getMembers()
469 {
470 return $this->members ? $this->members : array();
471 }
478 public function getAdmins()
479 {
480 return $this->admins ? $this->admins : array();
481 }
482
487 public function getCountAdmins()
488 {
489 return count($this->getAdmins());
490 }
491
492
499 public function getTutors()
500 {
501 return $this->tutors ? $this->tutors : array();
502 }
503
511 public function isAdmin($a_usr_id)
512 {
513 return in_array($a_usr_id,$this->admins) ? true : false;
514 }
515
523 public function isTutor($a_usr_id)
524 {
525 return in_array($a_usr_id,$this->tutors) ? true : false;
526 }
527
535 public function isMember($a_usr_id)
536 {
537 return in_array($a_usr_id,$this->members) ? true : false;
538 }
539
540
541
542
550 public function isAssigned($a_usr_id)
551 {
552 return in_array($a_usr_id,$this->participants);
553 }
554
560 public function isLastAdmin($a_usr_id)
561 {
562 return in_array($a_usr_id,$this->getAdmins()) and count($this->getAdmins()) == 1;
563 }
564
565
573 public function getRoles()
574 {
575 return $this->roles ? $this->roles : array();
576 }
577
585 public function getAssignedRoles($a_usr_id)
586 {
587 global $rbacreview;
588
589 foreach($this->roles as $role)
590 {
591 if($rbacreview->isAssigned($a_usr_id,$role))
592 {
593 $assigned[] = $role;
594 }
595 }
596 return $assigned ? $assigned : array();
597 }
598
607 public function updateRoleAssignments($a_usr_id,$a_roles)
608 {
609 global $rbacreview,$rbacadmin;
610
611 $roles = $a_roles ? $a_roles : array();
612
613 foreach($this->getRoles() as $role_id)
614 {
615 if($rbacreview->isAssigned($a_usr_id,$role_id))
616 {
617 if(!in_array($role_id,$roles))
618 {
619 $rbacadmin->deassignUser($role_id,$a_usr_id);
620 }
621 }
622 else
623 {
624 if(in_array($role_id,$roles))
625 {
626 $rbacadmin->assignUser($role_id,$a_usr_id);
627 }
628 }
629 }
630 $this->readParticipants();
631 $this->readParticipantsStatus();
632 }
633
641 public function checkLastAdmin($a_usr_ids)
642 {
643 foreach($this->getAdmins() as $admin_id)
644 {
645 if(!in_array($admin_id,$a_usr_ids))
646 {
647 return true;
648 }
649 }
650 return false;
651 }
652
660 public function isBlocked($a_usr_id)
661 {
662 if(isset($this->participants_status[$a_usr_id]))
663 {
664 return $this->participants_status[$a_usr_id]['blocked'] ? true : false;
665 }
666 return false;
667 }
668
676 public function hasPassed($a_usr_id)
677 {
678 if(isset($this->participants_status[$a_usr_id]))
679 {
680 return $this->participants_status[$a_usr_id]['passed'] ? true : false;
681 }
682 return false;
683 }
684
692 public function delete($a_usr_id)
693 {
694 global $rbacadmin,$ilDB;
695
696 $this->dropDesktopItem($a_usr_id);
697 foreach($this->roles as $role_id)
698 {
699 $rbacadmin->deassignUser($role_id,$a_usr_id);
700 }
701
702 $query = "DELETE FROM obj_members ".
703 "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
704 "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer');
705 $res = $ilDB->manipulate($query);
706
707 $this->readParticipants();
708 $this->readParticipantsStatus();
709
710 $GLOBALS['ilAppEventHandler']->raise(
711 $this->getComponent(),
712 "deleteParticipant",
713 array(
714 'obj_id' => $this->obj_id,
715 'usr_id' => $a_usr_id)
716 );
717
718 return true;
719 }
720
729 public function updateBlocked($a_usr_id,$a_blocked)
730 {
731 global $ilDB;
732
733 $this->participants_status[$a_usr_id]['blocked'] = (int) $a_blocked;
734
735 $query = "SELECT * FROM obj_members ".
736 "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
737 "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
738 $res = $ilDB->query($query);
739 if($res->numRows())
740 {
741 $query = "UPDATE obj_members SET ".
742 "blocked = ".$ilDB->quote((int) $a_blocked ,'integer')." ".
743 "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
744 "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
745 }
746 else
747 {
748 $query = "INSERT INTO obj_members (blocked,obj_id,usr_id,notification,passed) ".
749 "VALUES ( ".
750 $ilDB->quote((int) $a_blocked ,'integer').", ".
751 $ilDB->quote($this->obj_id ,'integer').", ".
752 $ilDB->quote($a_usr_id ,'integer').", ".
753 $ilDB->quote(0,'integer').", ".
754 $ilDB->quote(0,'integer').
755 ")";
756
757 }
758 $res = $ilDB->manipulate($query);
759 return true;
760 }
761
770 public function updateNotification($a_usr_id,$a_notification)
771 {
772 global $ilDB;
773
774 $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
775
776 $query = "SELECT * FROM obj_members ".
777 "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
778 "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
779 $res = $ilDB->query($query);
780 if($res->numRows())
781 {
782 $query = "UPDATE obj_members SET ".
783 "notification = ".$ilDB->quote((int) $a_notification ,'integer')." ".
784 "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
785 "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
786 }
787 else
788 {
789 $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) ".
790 "VALUES ( ".
791 $ilDB->quote((int) $a_notification ,'integer').", ".
792 $ilDB->quote($this->obj_id ,'integer').", ".
793 $ilDB->quote($a_usr_id ,'integer').", ".
794 $ilDB->quote(0,'integer').", ".
795 $ilDB->quote(0,'integer').
796 ")";
797
798 }
799 $res = $ilDB->manipulate($query);
800 return true;
801 }
802
803
804
805
814 public function add($a_usr_id,$a_role)
815 {
816 global $rbacadmin,$ilLog,$ilAppEventHandler;
817
818 if($this->isAssigned($a_usr_id))
819 {
820 return false;
821 }
822
823 switch($a_role)
824 {
825 case IL_CRS_ADMIN:
826 $this->admins[] = $a_usr_id;
827 break;
828
829 case IL_CRS_TUTOR:
830 $this->tutors[] = $a_usr_id;
831 break;
832
833 case IL_CRS_MEMBER:
834 $this->members[] = $a_usr_id;
835 break;
836
837 case IL_GRP_ADMIN:
838 $this->admins[] = $a_usr_id;
839 break;
840
841 case IL_GRP_MEMBER:
842 $this->members[] = $a_usr_id;
843 break;
844 }
845
846 $this->participants[] = $a_usr_id;
847 $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
848 $this->addDesktopItem($a_usr_id);
849
850 // Delete subscription request
851 $this->deleteSubscriber($a_usr_id);
852
853 include_once './Services/Membership/classes/class.ilWaitingList.php';
854 ilWaitingList::deleteUserEntry($a_usr_id,$this->obj_id);
855
856 $ilLog->write(__METHOD__.': Raise new event: Modules/Course|Group addParticipant');
857 $ilAppEventHandler->raise(
858 $this->getComponent(),
859 "addParticipant",
860 array(
861 'obj_id' => $this->obj_id,
862 'usr_id' => $a_usr_id,
863 'role_id' => $a_role)
864 );
865 return true;
866 }
867
868
876 public function deleteParticipants($a_user_ids)
877 {
878 foreach($a_user_ids as $user_id)
879 {
880 $this->delete($user_id);
881 }
882 return true;
883 }
884
892 public function addDesktopItem($a_usr_id)
893 {
894 if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
895 {
896 ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
897 }
898 return true;
899 }
900
908 function dropDesktopItem($a_usr_id)
909 {
910 if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
911 {
912 ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
913 }
914
915 return true;
916 }
917
918
919
927 public function isNotificationEnabled($a_usr_id)
928 {
929 if(isset($this->participants_status[$a_usr_id]))
930 {
931 return $this->participants_status[$a_usr_id]['notification'] ? true : false;
932 }
933 return false;
934 }
935
936
944 protected function readParticipants()
945 {
946 global $rbacreview,$ilObjDataCache,$ilLog;
947
948 $GLOBALS['rbacreview']->clearCaches();
949 $this->roles = $rbacreview->getRolesOfRoleFolder($this->ref_id,false);
950
951 $users = array();
952 $this->participants = array();
953 $this->members = $this->admins = $this->tutors = array();
954
955 foreach($this->roles as $role_id)
956 {
957 $title = $ilObjDataCache->lookupTitle($role_id);
958 switch(substr($title,0,8))
959 {
960 case 'il_crs_m':
961 $this->role_data[IL_CRS_MEMBER] = $role_id;
962 $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
963 $this->members = array_unique(array_merge($assigned,$this->members));
964 break;
965
966 case 'il_crs_a':
967 $this->role_data[IL_CRS_ADMIN] = $role_id;
968 $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
969 $this->admins = $rbacreview->assignedUsers($role_id);
970 break;
971
972 case 'il_crs_t':
973 $this->role_data[IL_CRS_TUTOR] = $role_id;
974 $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
975 $this->tutors = $rbacreview->assignedUsers($role_id);
976 break;
977
978 case 'il_grp_a':
979 $this->role_data[IL_GRP_ADMIN] = $role_id;
980 $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
981 $this->admins = $rbacreview->assignedUsers($role_id);
982 break;
983
984 case 'il_grp_m':
985 $this->role_data[IL_GRP_MEMBER] = $role_id;
986 $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
987 $this->members = $rbacreview->assignedUsers($role_id);
988 break;
989
990 default:
991 $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
992 $this->members = array_unique(array_merge($assigned,$this->members));
993 break;
994 }
995 }
996 }
997
1005 protected function readParticipantsStatus()
1006 {
1007 global $ilDB;
1008
1009 $query = "SELECT * FROM obj_members ".
1010 "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1011 $res = $ilDB->query($query);
1012 $this->participants_status = array();
1013 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1014 {
1015 $this->participants_status[$row->usr_id]['blocked'] = $row->blocked;
1016 $this->participants_status[$row->usr_id]['notification'] = $row->notification;
1017 $this->participants_status[$row->usr_id]['passed'] = $row->passed;
1018 }
1019 }
1020
1028 public function isGroupingMember($a_usr_id,$a_field = '')
1029 {
1030 global $rbacreview,$ilObjDataCache,$ilDB;
1031
1032 // Used for membership limitations -> check membership by given field
1033 if($a_field)
1034 {
1035 include_once './Services/User/classes/class.ilObjUser.php';
1036
1037 $tmp_user =& ilObjectFactory::getInstanceByObjId($a_usr_id);
1038 switch($a_field)
1039 {
1040 case 'login':
1041 $and = "AND login = ".$ilDB->quote($tmp_user->getLogin(),'text')." ";
1042 break;
1043 case 'email':
1044 $and = "AND email = ".$ilDB->quote($tmp_user->getEmail(),'text')." ";
1045 break;
1046 case 'matriculation':
1047 $and = "AND matriculation = ".$ilDB->quote($tmp_user->getMatriculation(),'text')." ";
1048 break;
1049
1050 default:
1051 $and = "AND usr_id = ".$ilDB->quote($a_usr_id,'integer'). " ";
1052 break;
1053 }
1054
1055 if(!$this->getParticipants())
1056 {
1057 return false;
1058 }
1059
1060 $query = "SELECT * FROM usr_data ud ".
1061 "WHERE ".$ilDB->in('usr_id',$this->getParticipants(),false,'integer')." ".
1062 $and;
1063
1064 $res = $ilDB->query($query);
1065 return $res->numRows() ? true : false;
1066 }
1067 }
1068
1069 public static function lookupSubscribers($a_obj_id)
1070 {
1071 global $ilDB;
1072
1073 $subscribers = array();
1074 $query = "SELECT usr_id FROM il_subscribers ".
1075 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
1076 "ORDER BY sub_time ";
1077
1078 $res = $ilDB->query($query);
1079 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1080 {
1081 $subscribers[] = $row->usr_id;
1082 }
1083 return $subscribers;
1084 }
1085
1091 public function getSubscribers()
1092 {
1093 $this->readSubscribers();
1094
1095 return $this->subscribers;
1096 }
1097
1098
1104 public function getCountSubscribers()
1105 {
1106 return count($this->getSubscribers());
1107 }
1108
1114 public function getSubscriberData($a_usr_id)
1115 {
1116 return $this->readSubscriberData($a_usr_id);
1117 }
1118
1119
1120
1126 public function assignSubscribers($a_usr_ids)
1127 {
1128 if(!is_array($a_usr_ids) or !count($a_usr_ids))
1129 {
1130 return false;
1131 }
1132 foreach($a_usr_ids as $id)
1133 {
1134 if(!$this->assignSubscriber($id))
1135 {
1136 return false;
1137 }
1138 }
1139 return true;
1140 }
1141
1147 public function assignSubscriber($a_usr_id)
1148 {
1149 global $ilErr;
1150
1151 $ilErr->setMessage("");
1152 if(!$this->isSubscriber($a_usr_id))
1153 {
1154 $ilErr->appendMessage($this->lng->txt("crs_user_notsubscribed"));
1155
1156 return false;
1157 }
1158 if($this->isAssigned($a_usr_id))
1159 {
1160 $tmp_obj = ilObjectFactory::getInstanceByObjId($a_usr_id);
1161 $ilErr->appendMessage($tmp_obj->getLogin().": ".$this->lng->txt("crs_user_already_assigned"));
1162
1163 return false;
1164 }
1165
1166 if(!$tmp_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id))
1167 {
1168 $ilErr->appendMessage($this->lng->txt("crs_user_not_exists"));
1169
1170 return false;
1171 }
1172
1173 // TODO: must be group or course member role
1174 $this->add($tmp_obj->getId(),IL_CRS_MEMBER);
1175 $this->deleteSubscriber($a_usr_id);
1176
1177 return true;
1178 }
1179
1185 public function autoFillSubscribers()
1186 {
1187 $this->readSubscribers();
1188
1189 $counter = 0;
1190 foreach($this->subscribers as $subscriber)
1191 {
1192 if(!$this->assignSubscriber($subscriber))
1193 {
1194 continue;
1195 }
1196 else
1197 {
1198 // TODO: notification
1199 #$this->sendNotification($this->NOTIFY_ACCEPT_SUBSCRIBER,$subscriber);
1200 }
1201 ++$counter;
1202 }
1203
1204 return $counter;
1205 }
1206
1212 public function addSubscriber($a_usr_id)
1213 {
1214 global $ilDB;
1215
1216 $query = "INSERT INTO il_subscribers (usr_id,obj_id,subject,sub_time) ".
1217 " VALUES (".
1218 $ilDB->quote($a_usr_id ,'integer').",".
1219 $ilDB->quote($this->obj_id ,'integer').", ".
1220 $ilDB->quote('','text').", ".
1221 $ilDB->quote(time() ,'integer').
1222 ")";
1223 $res = $ilDB->manipulate($query);
1224
1225 return true;
1226 }
1227
1228
1234 public function updateSubscriptionTime($a_usr_id,$a_subtime)
1235 {
1236 global $ilDB;
1237
1238 $query = "UPDATE il_subscribers ".
1239 "SET sub_time = ".$ilDB->quote($a_subtime ,'integer')." ".
1240 "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1241 "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1242 $res = $ilDB->manipulate($query);
1243
1244 return true;
1245 }
1246
1254 public function updateSubject($a_usr_id,$a_subject)
1255 {
1256 global $ilDB;
1257
1258 $query = "UPDATE il_subscribers ".
1259 "SET subject = ".$ilDB->quote($a_subject ,'text')." ".
1260 "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1261 "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1262 $res = $ilDB->manipulate($query);
1263 return true;
1264 }
1265
1266
1272 public function deleteSubscriber($a_usr_id)
1273 {
1274 global $ilDB;
1275
1276 $query = "DELETE FROM il_subscribers ".
1277 "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1278 "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1279 $res = $ilDB->manipulate($query);
1280
1281 return true;
1282 }
1283
1284
1290 public function deleteSubscribers($a_usr_ids)
1291 {
1292 global $ilErr,$ilDB;
1293
1294 if(!is_array($a_usr_ids) or !count($a_usr_ids))
1295 {
1296 $ilErr->setMessage('');
1297 $ilErr->appendMessage($this->lng->txt("no_usr_ids_given"));
1298
1299 return false;
1300 }
1301 $query = "DELETE FROM il_subscribers ".
1302 "WHERE ".$ilDB->in('usr_id',(array) $a_usr_ids,false,'integer')." ".
1303 "AND obj_id = ".$ilDB->quote($this->obj_id,'integer');
1304 $res = $ilDB->query($query);
1305 return true;
1306 }
1307
1308
1314 public function isSubscriber($a_usr_id)
1315 {
1316 global $ilDB;
1317
1318 $query = "SELECT * FROM il_subscribers ".
1319 "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1320 "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')."";
1321
1322 $res = $ilDB->query($query);
1323 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1324 {
1325 return true;
1326 }
1327 return false;
1328 }
1329
1336 public static function _isSubscriber($a_obj_id,$a_usr_id)
1337 {
1338 global $ilDB;
1339
1340 $query = "SELECT * FROM il_subscribers ".
1341 "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1342 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
1343
1344 $res = $ilDB->query($query);
1345 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1346 {
1347 return true;
1348 }
1349 return false;
1350 }
1351
1357 protected function readSubscribers()
1358 {
1359 global $ilDB;
1360
1361 $this->subscribers = array();
1362
1363 $query = "SELECT usr_id FROM il_subscribers ".
1364 "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
1365 "ORDER BY sub_time ";
1366
1367 $res = $this->ilDB->query($query);
1368 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1369 {
1370 // DELETE SUBSCRIPTION IF USER HAS BEEN DELETED
1371 if(!ilObjectFactory::getInstanceByObjId($row->usr_id,false))
1372 {
1373 $this->deleteSubscriber($row->usr_id);
1374 }
1375 $this->subscribers[] = $row->usr_id;
1376 }
1377 return true;
1378 }
1379
1385 protected function readSubscriberData($a_usr_id)
1386 {
1387 global $ilDB;
1388
1389 $query = "SELECT * FROM il_subscribers ".
1390 "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
1391 "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
1392
1393 $res = $this->ilDB->query($query);
1394 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1395 {
1396 $data["time"] = $row->sub_time;
1397 $data["usr_id"] = $row->usr_id;
1398 $data['subject'] = $row->subject;
1399 }
1400 return $data ? $data : array();
1401 }
1402
1403 public static function lookupSubscribersData($a_obj_id)
1404 {
1405 global $ilDB;
1406
1407 $query = 'SELECT * FROM il_subscribers '.
1408 'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
1409 $res = $ilDB->query($query);
1410
1411 $data = array();
1412 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1413 {
1414 $data[$row->usr_id]['time'] = $row->sub_time;
1415 $data[$row->usr_id]['usr_id'] = $row->usr_id;
1416 $data[$row->usr_id]['subject'] = $row->subject;
1417 }
1418 return $data;
1419 }
1420}
1421?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
const IL_CRS_ADMIN
Base class for course and group participants.
const IL_CRS_MEMBER
const IL_GRP_MEMBER
const IL_CRS_TUTOR
const IL_GRP_ADMIN
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Database Wrapper.
Definition: class.ilDB.php:29
query($sql, $a_handle_error=true)
Query.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static lookupShowMembersEnabled($a_obj_id)
Check if show member is enabled.
static _isDesktopItem($a_usr_id, $a_item_id, $a_type)
check wether an item is on the users desktop or not
static _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
drop an item from user's personal desktop
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user's personal desktop
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
getAdmins()
Get all admins ids.
getComponent()
Get component name Used for raising events.
isLastAdmin($a_usr_id)
Check if user is last admin.
isAssigned($a_usr_id)
check if user is assigned
updateSubject($a_usr_id, $a_subject)
update subject
assignSubscribers($a_usr_ids)
Assign subscribers.
static getDefaultMemberRole($a_ref_id)
isTutor($a_usr_id)
is user tutor
static hasParticipantListAccess($a_obj_id, $a_usr_id=null)
Check if (current) user has access to the participant list.
getParticipants()
Get all participants ids.
readParticipants()
Read participants.
static _isSubscriber($a_obj_id, $a_usr_id)
check if user is subscriber
deleteSubscriber($a_usr_id)
Delete subsciber.
static getInstanceByObjId($a_obj_id)
Get instance by obj type.
getRoles()
Get course roles.
getCountParticipants()
Get number of participants.
isMember($a_usr_id)
is user member
isAdmin($a_usr_id)
is user admin
getSubscriberData($a_usr_id)
get subscriber data
getType()
Get object type.
dropDesktopItem($a_usr_id)
Drop desktop item.
updateSubscriptionTime($a_usr_id, $a_subtime)
Update subscription time.
add($a_usr_id, $a_role)
Add user to course.
static _isParticipant($a_ref_id, $a_usr_id)
Static function to check if a user is a participant of the container object.
getAssignedRoles($a_usr_id)
Get assigned roles.
static lookupNumberOfParticipants($a_ref_id)
Lookup the number of participants (crs admins, tutors, members, grp admins, members)
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
static _isBlocked($a_obj_id, $a_usr_id)
Check if user is blocked.
readParticipantsStatus()
Read status of participants (blocked, notification, passed)
isGroupingMember($a_usr_id, $a_field='')
Check grouping membership.
updateNotification($a_usr_id, $a_notification)
Update notification status.
updateRoleAssignments($a_usr_id, $a_roles)
Update role assignments.
addDesktopItem($a_usr_id)
Add desktop item.
getCountSubscribers()
get number of subscribers
autoFillSubscribers()
Assign subscriber.
static lookupSubscribersData($a_obj_id)
getNotificationRecipients()
Get admin, tutor which have notification enabled.
static lookupSubscribers($a_obj_id)
deleteSubscribers($a_usr_ids)
Delete subscibers.
getMembers()
Get all members ids (admins and tutors are not members) Use get participants to fetch all.
isNotificationEnabled($a_usr_id)
check if notification is enabled
getSubscribers()
get all subscribers
getCountMembers()
Get number of members (not participants)
getObjId()
get current obj_id
assignSubscriber($a_usr_id)
Assign subscriber.
hasPassed($a_usr_id)
Check if user has passed course.
static _hasPassed($a_obj_id, $a_usr_id)
Check if user has passed course.
deleteParticipants($a_user_ids)
Delete users.
isSubscriber($a_usr_id)
check if is subscriber
static lookupNumberOfMembers($a_ref_id)
Lookup number of members @global ilRbacReview $rbacreview @global <type> $ilObjDataCache.
__construct($a_component_name, $a_obj_id)
Singleton Constructor.
static _deleteUser($a_usr_id)
Delete user data.
readSubscriberData($a_usr_id)
read subscribers
getCountAdmins()
Get number of admins.
checkLastAdmin($a_usr_ids)
Check if user for deletion are last admins.
static _deleteAllEntries($a_obj_id)
Delete all entries Normally called for course deletion.
readSubscribers()
read subscribers
getTutors()
Get all tutors ids.
addSubscriber($a_usr_id)
Add subscriber.
updateBlocked($a_usr_id, $a_blocked)
Update blocked status.
isBlocked($a_usr_id)
Check if user is blocked.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _deleteUser($a_usr_id)
Delete user.
static deleteUserEntry($a_usr_id, $a_obj_id)
Delete one user entry.
$GLOBALS['ct_recipient']
global $ilCtrl
Definition: ilias.php:18