ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
12 define("IL_CRS_ADMIN",1);
13 define("IL_CRS_TUTOR",3);
14 define("IL_CRS_MEMBER",2);
15 
16 define('IL_GRP_ADMIN',4);
17 define('IL_GRP_MEMBER',5);
18 
19 define("IL_ROLE_POSITION_ADMIN",1);
20 define("IL_ROLE_POSITION_TUTOR",2);
21 define("IL_ROLE_POSITION_MEMBER",3);
22 
23 
24 abstract class ilParticipants
25 {
26  protected $component = '';
27 
28  protected $obj_id = 0;
29  protected $type = '';
30  protected $ref_id = 0;
31 
32  protected $roles = array();
33  protected $role_data = array();
34  protected $roles_sorted = [];
35  protected $role_assignments = [];
36 
37  protected $participants = array();
38  protected $participants_status = array();
39  protected $members = array();
40  protected $tutors = array();
41  protected $admins = array();
42 
43  protected $subscribers = array();
44 
45  protected $ilDB;
46  protected $lng;
47 
48 
56  public function __construct($a_component_name, $a_obj_id)
57  {
58  global $ilDB,$lng;
59 
60  $this->ilDB = $ilDB;
61  $this->lng = $lng;
62 
63  $this->component = $a_component_name;
64 
65  $this->obj_id = $a_obj_id;
66  $this->type = ilObject::_lookupType($a_obj_id);
67  $ref_ids = ilObject::_getAllReferences($this->obj_id);
68  $this->ref_id = current($ref_ids);
69 
70  $this->readParticipants();
71  $this->readParticipantsStatus();
72  }
73 
81  public static function getInstanceByObjId($a_obj_id)
82  {
83  $type = ilObject::_lookupType($a_obj_id);
84  switch($type)
85  {
86  case 'crs':
87  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
89 
90  case 'grp':
91  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
93 
94  case 'sess':
95  include_once './Modules/Session/classes/class.ilSessionParticipants.php';
97 
98  default:
99  $GLOBALS['ilLog']->logStack();
100  $GLOBALS['ilLog']->write(__METHOD__.': Invalid obj_id given: '.$a_obj_id);
101  throw new InvalidArgumentException('Invalid obj id given');
102  }
103  }
104 
109  protected function getComponent()
110  {
111  return $this->component;
112  }
113 
114 
115 
121  public static function hasParticipantListAccess($a_obj_id, $a_usr_id = null)
122  {
123  if(!$a_usr_id)
124  {
125  $a_usr_id = $GLOBALS['ilUser']->getId();
126  }
127 
128  // if write access granted => return true
129  $refs = ilObject::_getAllReferences($a_obj_id);
130  $ref_id = end($refs);
131 
132  if($GLOBALS['ilAccess']->checkAccess('write','',$ref_id))
133  {
134  return true;
135  }
136  $part = self::getInstanceByObjId($a_obj_id);
137  if($part->isAssigned($a_usr_id))
138  {
139  if($part->getType() == 'crs')
140  {
141  // Check for show_members
142  include_once './Modules/Course/classes/class.ilObjCourse.php';
144  {
145  return false;
146  }
147  }
148  return true;
149  }
150  // User is not assigned to course/group => no read access
151  return false;
152  }
153 
165  public static function _getMembershipByType($a_usr_id,$a_type,$a_only_member_role = false)
166  {
167  global $ilDB;
168 
169  if (!is_array($a_type))
170  {
171  $a_type = array($a_type);
172  }
173 
174  // this will also dismiss local roles!
175  if ($a_only_member_role)
176  {
177  $j2 = "JOIN object_data obd2 ON (ua.rol_id = obd2.obj_id) ";
178  $a2 = 'AND obd2.title = '.$ilDB->concat(
179  array(
180  array($ilDB->quote('il_','text')),
181  array('obd.type'),
182  array($ilDB->quote('_member_','text')),
183  array('obr.ref_id'),
184  ),
185  false
186  );
187  }
188 
189  // #14290 - no role folder anymore
190  $query = "SELECT DISTINCT obd.obj_id,obr.ref_id FROM rbac_ua ua ".
191  "JOIN rbac_fa fa ON ua.rol_id = fa.rol_id ".
192  "JOIN object_reference obr ON fa.parent = obr.ref_id ".
193  "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
194  $j2.
195  "WHERE ".$ilDB->in("obd.type", $a_type, false, "text").
196  "AND fa.assign = 'y' ".
197  "AND ua.usr_id = ".$ilDB->quote($a_usr_id,'integer')." ".
198  $a2;
199  $res = $ilDB->query($query);
200  while($row = $ilDB->fetchObject($res))
201  {
202  $ref_ids[] = $row->obj_id;
203  }
204 
205  return $ref_ids ? $ref_ids : array();
206  }
207 
208 
209 
218  public static function _isParticipant($a_ref_id,$a_usr_id)
219  {
220  global $rbacreview,$ilObjDataCache,$ilDB,$ilLog;
221 
222  $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
223 
224  return $rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id, $local_roles);
225  }
226 
234  public static function lookupNumberOfParticipants($a_ref_id)
235  {
236  global $rbacreview;
237 
238  $lroles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
239  return $rbacreview->getNumberOfAssignedUsers($lroles);
240  }
241 
249  public static function lookupNumberOfMembers($a_ref_id)
250  {
251  global $rbacreview, $ilObjDataCache;
252 
253  $has_policies = $rbacreview->getLocalPolicies($a_ref_id);
254 
255  if(!$has_policies)
256  {
257  return 0;
258  }
259  $lroles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
260 
261  $memberRoles = array();
262  foreach($lroles as $role_id)
263  {
264  $title = $ilObjDataCache->lookupTitle($role_id);
265  switch(substr($title,0,8))
266  {
267  case 'il_crs_a':
268  case 'il_crs_t':
269  case 'il_grp_a':
270  break;
271 
272  default:
273  $memberRoles[] = $role_id;
274  break;
275  }
276  }
277  return $rbacreview->getNumberOfAssignedUsers($memberRoles);
278  }
279 
280 
290  public static function _isBlocked($a_obj_id,$a_usr_id)
291  {
292  global $ilDB;
293 
294  $query = "SELECT * FROM obj_members ".
295  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
296  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer')." ".
297  "AND blocked = ".$ilDB->quote(1,'integer');
298  $res = $ilDB->query($query);
299  return $res->numRows() ? true : false;
300  }
301 
311  public static function _hasPassed($a_obj_id,$a_usr_id)
312  {
313  global $ilDB;
314 
315  $query = "SELECT * FROM obj_members ".
316  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
317  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
318  "AND passed = '1'";
319  $res = $ilDB->query($query);
320  return $res->numRows() ? true : false;
321  }
322 
332  public static function _deleteAllEntries($a_obj_id)
333  {
334  global $ilDB;
335 
336  $query = "DELETE FROM obj_members ".
337  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
338  $res = $ilDB->manipulate($query);
339 
340  $query = "DELETE FROM il_subscribers ".
341  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
342  $res = $ilDB->manipulate($query);
343 
344  $query = 'DELETE FROM crs_waiting_list '.
345  'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
346  $ilDB->manipulate($query);
347 
348  return true;
349  }
350 
359  public static function _deleteUser($a_usr_id)
360  {
361  global $ilDB;
362 
363  $query = "DELETE FROM obj_members WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
364  $res = $ilDB->manipulate($query);
365 
366  $query = "DELETE FROM il_subscribers WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
367  $res = $ilDB->manipulate($query);
368 
369  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
371  }
372 
373  public static function getDefaultMemberRole($a_ref_id)
374  {
375  global $ilCtrl;
376 
377  $obj_id = ilObject::_lookupObjId($a_ref_id);
379 
380  if(!in_array($type,array('crs','grp')))
381  {
382  return 0;
383  }
384 
385  global $rbacreview;
386 
387 
388  $roles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
389 
390  foreach($roles as $role)
391  {
393  if(substr($title, 0, 13) == ('il_'.$type.'_member'))
394  {
395  return $role;
396  }
397  }
398  return 0;
399  }
400 
405  public function getObjId()
406  {
407  return $this->obj_id;
408  }
409 
414  public function getType()
415  {
416  return $this->type;
417  }
418 
425  public function getNotificationRecipients()
426  {
427  global $ilDB;
428 
429  $query = "SELECT * FROM obj_members ".
430  "WHERE notification = 1 ".
431  "AND obj_id = ".$ilDB->quote($this->obj_id)." ";
432  $res = $ilDB->query($query);
433  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
434  {
435  if($this->isAdmin($row->usr_id) or $this->isTutor($row->usr_id))
436  {
437  $recp[] = $row->usr_id;
438  }
439  }
440  return $recp ? $recp : array();
441  }
442 
449  public function getCountMembers()
450  {
451  return count($this->members);
452  }
453 
460  public function getCountParticipants()
461  {
462  return count($this->participants);
463  }
464 
465 
466 
467 
474  public function getParticipants()
475  {
476  return $this->participants ? $this->participants : array();
477  }
478 
486  public function getMembers()
487  {
488  return $this->members ? $this->members : array();
489  }
496  public function getAdmins()
497  {
498  return $this->admins ? $this->admins : array();
499  }
500 
505  public function getCountAdmins()
506  {
507  return count($this->getAdmins());
508  }
509 
510 
517  public function getTutors()
518  {
519  return $this->tutors ? $this->tutors : array();
520  }
521 
529  public function isAdmin($a_usr_id)
530  {
531  return in_array($a_usr_id,$this->admins) ? true : false;
532  }
533 
541  public function isTutor($a_usr_id)
542  {
543  return in_array($a_usr_id,$this->tutors) ? true : false;
544  }
545 
553  public function isMember($a_usr_id)
554  {
555  return in_array($a_usr_id,$this->members) ? true : false;
556  }
557 
558 
559 
560 
568  public function isAssigned($a_usr_id)
569  {
570  return in_array($a_usr_id,$this->participants);
571  }
572 
578  public function isLastAdmin($a_usr_id)
579  {
580  return in_array($a_usr_id,$this->getAdmins()) and count($this->getAdmins()) == 1;
581  }
582 
583 
591  public function getRoles()
592  {
593  return $this->roles ? $this->roles : array();
594  }
595 
603  public function getAssignedRoles($a_usr_id)
604  {
605  global $rbacreview;
606 
607  foreach($this->roles as $role)
608  {
609  if($rbacreview->isAssigned($a_usr_id,$role))
610  {
611  $assigned[] = $role;
612  }
613  }
614  return $assigned ? $assigned : array();
615  }
616 
625  public function updateRoleAssignments($a_usr_id,$a_roles)
626  {
627  global $rbacreview,$rbacadmin;
628 
629  $roles = $a_roles ? $a_roles : array();
630 
631  foreach($this->getRoles() as $role_id)
632  {
633  if($rbacreview->isAssigned($a_usr_id,$role_id))
634  {
635  if(!in_array($role_id,$roles))
636  {
637  $rbacadmin->deassignUser($role_id,$a_usr_id);
638  }
639  }
640  else
641  {
642  if(in_array($role_id,$roles))
643  {
644  $rbacadmin->assignUser($role_id,$a_usr_id);
645  }
646  }
647  }
648  $rbacreview->clearCaches();
649  $this->readParticipants();
650  $this->readParticipantsStatus();
651  }
652 
660  public function checkLastAdmin($a_usr_ids)
661  {
662  foreach($this->getAdmins() as $admin_id)
663  {
664  if(!in_array($admin_id,$a_usr_ids))
665  {
666  return true;
667  }
668  }
669  return false;
670  }
671 
679  public function isBlocked($a_usr_id)
680  {
681  if(isset($this->participants_status[$a_usr_id]))
682  {
683  return $this->participants_status[$a_usr_id]['blocked'] ? true : false;
684  }
685  return false;
686  }
687 
695  public function hasPassed($a_usr_id)
696  {
697  if(isset($this->participants_status[$a_usr_id]))
698  {
699  return $this->participants_status[$a_usr_id]['passed'] ? true : false;
700  }
701  return false;
702  }
703 
711  public function delete($a_usr_id)
712  {
713  global $rbacadmin,$ilDB;
714 
715  $this->dropDesktopItem($a_usr_id);
716  foreach($this->roles as $role_id)
717  {
718  $rbacadmin->deassignUser($role_id,$a_usr_id);
719  }
720 
721  $query = "DELETE FROM obj_members ".
722  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
723  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer');
724  $res = $ilDB->manipulate($query);
725 
726  $this->readParticipants();
727  $this->readParticipantsStatus();
728 
729  $GLOBALS['ilAppEventHandler']->raise(
730  $this->getComponent(),
731  "deleteParticipant",
732  array(
733  'obj_id' => $this->obj_id,
734  'usr_id' => $a_usr_id)
735  );
736 
737  return true;
738  }
739 
748  public function updateBlocked($a_usr_id,$a_blocked)
749  {
750  global $ilDB;
751 
752  $this->participants_status[$a_usr_id]['blocked'] = (int) $a_blocked;
753 
754  $query = "SELECT * FROM obj_members ".
755  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
756  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
757  $res = $ilDB->query($query);
758  if($res->numRows())
759  {
760  $query = "UPDATE obj_members SET ".
761  "blocked = ".$ilDB->quote((int) $a_blocked ,'integer')." ".
762  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
763  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
764  }
765  else
766  {
767  $query = "INSERT INTO obj_members (blocked,obj_id,usr_id,notification,passed) ".
768  "VALUES ( ".
769  $ilDB->quote((int) $a_blocked ,'integer').", ".
770  $ilDB->quote($this->obj_id ,'integer').", ".
771  $ilDB->quote($a_usr_id ,'integer').", ".
772  $ilDB->quote(0,'integer').", ".
773  $ilDB->quote(0,'integer').
774  ")";
775 
776  }
777  $res = $ilDB->manipulate($query);
778  return true;
779  }
780 
781  // cognos-blu-patch: begin
789  public function updateContact($a_usr_id, $a_contact)
790  {
791  global $ilDB;
792 
793  $ilDB->manipulate(
794  'UPDATE obj_members SET '.
795  'contact = '.$ilDB->quote($a_contact,'integer').' '.
796  'WHERE obj_id = '.$ilDB->quote($this->obj_id,'integer').' '.
797  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer'));
798 
799  $this->participants_status[$a_usr_id]['contact'] = $a_contact;
800  return TRUE;
801  }
802 
807  public function getContacts()
808  {
809  $contacts = array();
810  foreach((array) $this->participants_status as $usr_id => $status)
811  {
812  if($status['contact'])
813  {
814  $contacts[] = $usr_id;
815  }
816  }
817  return $contacts;
818  }
819 
820 
821  // cognos-blu-patch: end
822 
831  public function updateNotification($a_usr_id,$a_notification)
832  {
833  global $ilDB;
834 
835  $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
836 
837  $query = "SELECT * FROM obj_members ".
838  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
839  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
840  $res = $ilDB->query($query);
841  if($res->numRows())
842  {
843  $query = "UPDATE obj_members SET ".
844  "notification = ".$ilDB->quote((int) $a_notification ,'integer')." ".
845  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
846  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
847  }
848  else
849  {
850  $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) ".
851  "VALUES ( ".
852  $ilDB->quote((int) $a_notification ,'integer').", ".
853  $ilDB->quote($this->obj_id ,'integer').", ".
854  $ilDB->quote($a_usr_id ,'integer').", ".
855  $ilDB->quote(0,'integer').", ".
856  $ilDB->quote(0,'integer').
857  ")";
858 
859  }
860  $res = $ilDB->manipulate($query);
861  return true;
862  }
863 
864 
865 
866 
875  public function add($a_usr_id,$a_role)
876  {
877  global $rbacadmin,$ilLog,$ilAppEventHandler;
878 
879  if($this->isAssigned($a_usr_id))
880  {
881  return false;
882  }
883 
884  switch($a_role)
885  {
886  case IL_CRS_ADMIN:
887  $this->admins[] = $a_usr_id;
888  break;
889 
890  case IL_CRS_TUTOR:
891  $this->tutors[] = $a_usr_id;
892  break;
893 
894  case IL_CRS_MEMBER:
895  $this->members[] = $a_usr_id;
896  break;
897 
898  case IL_GRP_ADMIN:
899  $this->admins[] = $a_usr_id;
900  break;
901 
902  case IL_GRP_MEMBER:
903  $this->members[] = $a_usr_id;
904  break;
905  }
906 
907  $this->participants[] = $a_usr_id;
908  $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
909  $this->addDesktopItem($a_usr_id);
910 
911  // Delete subscription request
912  $this->deleteSubscriber($a_usr_id);
913 
914  include_once './Services/Membership/classes/class.ilWaitingList.php';
915  ilWaitingList::deleteUserEntry($a_usr_id,$this->obj_id);
916 
917  $ilLog->write(__METHOD__.': Raise new event: '.$this->getComponent().' addParticipant');
918  $ilAppEventHandler->raise(
919  $this->getComponent(),
920  "addParticipant",
921  array(
922  'obj_id' => $this->obj_id,
923  'usr_id' => $a_usr_id,
924  'role_id' => $a_role)
925  );
926  return true;
927  }
928 
929 
937  public function deleteParticipants($a_user_ids)
938  {
939  foreach($a_user_ids as $user_id)
940  {
941  $this->delete($user_id);
942  }
943  return true;
944  }
945 
953  public function addDesktopItem($a_usr_id)
954  {
955  if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
956  {
957  ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
958  }
959  return true;
960  }
961 
969  function dropDesktopItem($a_usr_id)
970  {
971  if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
972  {
973  ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
974  }
975 
976  return true;
977  }
978 
979 
980 
988  public function isNotificationEnabled($a_usr_id)
989  {
990  if(isset($this->participants_status[$a_usr_id]))
991  {
992  return $this->participants_status[$a_usr_id]['notification'] ? true : false;
993  }
994  return false;
995  }
996 
997  // cognos-blu-patch: begin
1002  public function isContact($a_usr_id)
1003  {
1004  if(isset($this->participants_status[$a_usr_id]))
1005  {
1006  return (bool) $this->participants_status[$a_usr_id]['contact'];
1007  }
1008  return FALSE;
1009  }
1010  // cognos-blu-patch: end
1011 
1012 
1017  public function getAutoGeneratedRoleId($a_role_type)
1018  {
1019  if(array_key_exists($a_role_type, $this->role_data))
1020  {
1021  return $this->role_data[$a_role_type];
1022  }
1023 
1024  return 0;
1025  }
1026 
1027 
1035  protected function readParticipants()
1036  {
1037  global $rbacreview,$ilObjDataCache,$ilLog;
1038 
1039  $GLOBALS['rbacreview']->clearCaches();
1040  $this->roles = $rbacreview->getRolesOfRoleFolder($this->ref_id,false);
1041 
1042  $users = array();
1043  $this->participants = array();
1044  $this->members = $this->admins = $this->tutors = array();
1045 
1046  $additional_roles = [];
1047  $auto_generated_roles = [];
1048  foreach($this->roles as $role_id)
1049  {
1050  $title = $ilObjDataCache->lookupTitle($role_id);
1051  switch(substr($title,0,8))
1052  {
1053  case 'il_crs_m':
1054  $auto_generated_roles[$role_id] = IL_ROLE_POSITION_MEMBER;
1055  $this->role_data[IL_CRS_MEMBER] = $role_id;
1056  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1057  $this->members = array_unique(array_merge($assigned,$this->members));
1058  $this->role_assignments[$role_id] = $assigned;
1059  break;
1060 
1061  case 'il_crs_a':
1062  $auto_generated_roles[$role_id] = IL_ROLE_POSITION_ADMIN;
1063  $this->role_data[IL_CRS_ADMIN] = $role_id;
1064  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1065  $this->admins = $rbacreview->assignedUsers($role_id);
1066  $this->role_assignments[$role_id] = $assigned;
1067  break;
1068 
1069  case 'il_crs_t':
1070  $auto_generated_roles[$role_id] = IL_ROLE_POSITION_TUTOR;
1071  $this->role_data[IL_CRS_TUTOR] = $role_id;
1072  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1073  $this->tutors = $rbacreview->assignedUsers($role_id);
1074  $this->role_assignments[$role_id] = $assigned;
1075  break;
1076 
1077  case 'il_grp_a':
1078  $auto_generated_roles[$role_id] = IL_ROLE_POSITION_ADMIN;
1079  $this->role_data[IL_GRP_ADMIN] = $role_id;
1080  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1081  $this->admins = $rbacreview->assignedUsers($role_id);
1082  $this->role_assignments[$role_id] = $assigned;
1083  break;
1084 
1085  case 'il_grp_m':
1086  $auto_generated_roles[$role_id] = IL_ROLE_POSITION_MEMBER;
1087  $this->role_data[IL_GRP_MEMBER] = $role_id;
1088  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1089  $this->members = $rbacreview->assignedUsers($role_id);
1090  $this->role_assignments[$role_id] = $assigned;
1091  break;
1092 
1093  default:
1094  $additional_roles[$role_id] = $title;
1095  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1096  $this->members = array_unique(array_merge($assigned,$this->members));
1097  $this->role_assignments[$role_id] = $assigned;
1098  break;
1099  }
1100  }
1101  asort($auto_generated_roles);
1102  asort($additional_roles);
1103  $this->roles_sorted = $auto_generated_roles + $additional_roles;
1104  }
1105 
1113  protected function readParticipantsStatus()
1114  {
1115  global $ilDB;
1116 
1117  $query = "SELECT * FROM obj_members ".
1118  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1119  $res = $ilDB->query($query);
1120  $this->participants_status = array();
1121  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1122  {
1123  $this->participants_status[$row->usr_id]['blocked'] = $row->blocked;
1124  $this->participants_status[$row->usr_id]['notification'] = $row->notification;
1125  $this->participants_status[$row->usr_id]['passed'] = $row->passed;
1126  // cognos-blu-patch: begin
1127  $this->participants_status[$row->usr_id]['contact'] = $row->contact;
1128  // cognos-blu-patch: end
1129  }
1130  }
1131 
1139  public function isGroupingMember($a_usr_id,$a_field = '')
1140  {
1141  global $rbacreview,$ilObjDataCache,$ilDB;
1142 
1143  // Used for membership limitations -> check membership by given field
1144  if($a_field)
1145  {
1146  include_once './Services/User/classes/class.ilObjUser.php';
1147 
1148  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_usr_id);
1149  switch($a_field)
1150  {
1151  case 'login':
1152  $and = "AND login = ".$ilDB->quote($tmp_user->getLogin(),'text')." ";
1153  break;
1154  case 'email':
1155  $and = "AND email = ".$ilDB->quote($tmp_user->getEmail(),'text')." ";
1156  break;
1157  case 'matriculation':
1158  $and = "AND matriculation = ".$ilDB->quote($tmp_user->getMatriculation(),'text')." ";
1159  break;
1160 
1161  default:
1162  $and = "AND usr_id = ".$ilDB->quote($a_usr_id,'integer'). " ";
1163  break;
1164  }
1165 
1166  if(!$this->getParticipants())
1167  {
1168  return false;
1169  }
1170 
1171  $query = "SELECT * FROM usr_data ud ".
1172  "WHERE ".$ilDB->in('usr_id',$this->getParticipants(),false,'integer')." ".
1173  $and;
1174 
1175  $res = $ilDB->query($query);
1176  return $res->numRows() ? true : false;
1177  }
1178  }
1179 
1180  public static function lookupSubscribers($a_obj_id)
1181  {
1182  global $ilDB;
1183 
1184  $subscribers = array();
1185  $query = "SELECT usr_id FROM il_subscribers ".
1186  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
1187  "ORDER BY sub_time ";
1188 
1189  $res = $ilDB->query($query);
1190  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1191  {
1192  $subscribers[] = $row->usr_id;
1193  }
1194  return $subscribers;
1195  }
1196 
1202  public function getSubscribers()
1203  {
1204  $this->readSubscribers();
1205 
1206  return $this->subscribers;
1207  }
1208 
1209 
1215  public function getCountSubscribers()
1216  {
1217  return count($this->getSubscribers());
1218  }
1219 
1225  public function getSubscriberData($a_usr_id)
1226  {
1227  return $this->readSubscriberData($a_usr_id);
1228  }
1229 
1230 
1231 
1237  public function assignSubscribers($a_usr_ids)
1238  {
1239  if(!is_array($a_usr_ids) or !count($a_usr_ids))
1240  {
1241  return false;
1242  }
1243  foreach($a_usr_ids as $id)
1244  {
1245  if(!$this->assignSubscriber($id))
1246  {
1247  return false;
1248  }
1249  }
1250  return true;
1251  }
1252 
1258  public function assignSubscriber($a_usr_id)
1259  {
1260  global $ilErr;
1261 
1262  $ilErr->setMessage("");
1263  if(!$this->isSubscriber($a_usr_id))
1264  {
1265  $ilErr->appendMessage($this->lng->txt("crs_user_notsubscribed"));
1266 
1267  return false;
1268  }
1269  if($this->isAssigned($a_usr_id))
1270  {
1271  $tmp_obj = ilObjectFactory::getInstanceByObjId($a_usr_id);
1272  $ilErr->appendMessage($tmp_obj->getLogin().": ".$this->lng->txt("crs_user_already_assigned"));
1273 
1274  return false;
1275  }
1276 
1277  if(!$tmp_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id))
1278  {
1279  $ilErr->appendMessage($this->lng->txt("crs_user_not_exists"));
1280 
1281  return false;
1282  }
1283 
1284  // TODO: must be group or course member role
1285  if($this instanceof ilCourseParticipants)
1286  {
1287  $this->add($tmp_obj->getId(),IL_CRS_MEMBER);
1288  }
1289  if($this instanceof ilGroupParticipants)
1290  {
1291  $this->add($tmp_obj->getId(),IL_GRP_MEMBER);
1292  }
1293  $this->deleteSubscriber($a_usr_id);
1294  return true;
1295  }
1296 
1302  public function autoFillSubscribers()
1303  {
1304  $this->readSubscribers();
1305 
1306  $counter = 0;
1307  foreach($this->subscribers as $subscriber)
1308  {
1309  if(!$this->assignSubscriber($subscriber))
1310  {
1311  continue;
1312  }
1313  else
1314  {
1315  // TODO: notification
1316  #$this->sendNotification($this->NOTIFY_ACCEPT_SUBSCRIBER,$subscriber);
1317  }
1318  ++$counter;
1319  }
1320 
1321  return $counter;
1322  }
1323 
1329  public function addSubscriber($a_usr_id)
1330  {
1331  global $ilDB;
1332 
1333  $query = "INSERT INTO il_subscribers (usr_id,obj_id,subject,sub_time) ".
1334  " VALUES (".
1335  $ilDB->quote($a_usr_id ,'integer').",".
1336  $ilDB->quote($this->obj_id ,'integer').", ".
1337  $ilDB->quote('','text').", ".
1338  $ilDB->quote(time() ,'integer').
1339  ")";
1340  $res = $ilDB->manipulate($query);
1341 
1342  return true;
1343  }
1344 
1345 
1351  public function updateSubscriptionTime($a_usr_id,$a_subtime)
1352  {
1353  global $ilDB;
1354 
1355  $query = "UPDATE il_subscribers ".
1356  "SET sub_time = ".$ilDB->quote($a_subtime ,'integer')." ".
1357  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1358  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1359  $res = $ilDB->manipulate($query);
1360 
1361  return true;
1362  }
1363 
1371  public function updateSubject($a_usr_id,$a_subject)
1372  {
1373  global $ilDB;
1374 
1375  $query = "UPDATE il_subscribers ".
1376  "SET subject = ".$ilDB->quote($a_subject ,'text')." ".
1377  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1378  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1379  $res = $ilDB->manipulate($query);
1380  return true;
1381  }
1382 
1383 
1389  public function deleteSubscriber($a_usr_id)
1390  {
1391  global $ilDB;
1392 
1393  $query = "DELETE FROM il_subscribers ".
1394  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1395  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1396  $res = $ilDB->manipulate($query);
1397 
1398  return true;
1399  }
1400 
1401 
1407  public function deleteSubscribers($a_usr_ids)
1408  {
1409  global $ilErr,$ilDB;
1410 
1411  if(!is_array($a_usr_ids) or !count($a_usr_ids))
1412  {
1413  $ilErr->setMessage('');
1414  $ilErr->appendMessage($this->lng->txt("no_usr_ids_given"));
1415 
1416  return false;
1417  }
1418  $query = "DELETE FROM il_subscribers ".
1419  "WHERE ".$ilDB->in('usr_id',(array) $a_usr_ids,false,'integer')." ".
1420  "AND obj_id = ".$ilDB->quote($this->obj_id,'integer');
1421  $res = $ilDB->query($query);
1422  return true;
1423  }
1424 
1425 
1431  public function isSubscriber($a_usr_id)
1432  {
1433  global $ilDB;
1434 
1435  $query = "SELECT * FROM il_subscribers ".
1436  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1437  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')."";
1438 
1439  $res = $ilDB->query($query);
1440  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1441  {
1442  return true;
1443  }
1444  return false;
1445  }
1446 
1453  public static function _isSubscriber($a_obj_id,$a_usr_id)
1454  {
1455  global $ilDB;
1456 
1457  $query = "SELECT * FROM il_subscribers ".
1458  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1459  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
1460 
1461  $res = $ilDB->query($query);
1462  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1463  {
1464  return true;
1465  }
1466  return false;
1467  }
1468 
1474  protected function readSubscribers()
1475  {
1476  global $ilDB;
1477 
1478  $this->subscribers = array();
1479 
1480  $query = "SELECT usr_id FROM il_subscribers ".
1481  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
1482  "ORDER BY sub_time ";
1483 
1484  $res = $this->ilDB->query($query);
1485  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1486  {
1487  // DELETE SUBSCRIPTION IF USER HAS BEEN DELETED
1488  if(!ilObjectFactory::getInstanceByObjId($row->usr_id,false))
1489  {
1490  $this->deleteSubscriber($row->usr_id);
1491  }
1492  $this->subscribers[] = $row->usr_id;
1493  }
1494  return true;
1495  }
1496 
1502  protected function readSubscriberData($a_usr_id)
1503  {
1504  global $ilDB;
1505 
1506  $query = "SELECT * FROM il_subscribers ".
1507  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
1508  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
1509 
1510  $res = $this->ilDB->query($query);
1511  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1512  {
1513  $data["time"] = $row->sub_time;
1514  $data["usr_id"] = $row->usr_id;
1515  $data['subject'] = $row->subject;
1516  }
1517  return $data ? $data : array();
1518  }
1519 
1520  public static function lookupSubscribersData($a_obj_id)
1521  {
1522  global $ilDB;
1523 
1524  $query = 'SELECT * FROM il_subscribers '.
1525  'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
1526  $res = $ilDB->query($query);
1527 
1528  $data = array();
1529  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1530  {
1531  $data[$row->usr_id]['time'] = $row->sub_time;
1532  $data[$row->usr_id]['usr_id'] = $row->usr_id;
1533  $data[$row->usr_id]['subject'] = $row->subject;
1534  }
1535  return $data;
1536  }
1537 
1545  public static function _getAllSupportContactsOfUser($a_usr_id,$a_type)
1546  {
1547  global $ilDB;
1548 
1549  // todo: join the two queries or alternatively reuse _getMembershipByType
1550  // for the first part
1551 
1552  // this will also dismiss local roles!
1553  $j2 = "JOIN object_data obd2 ON (ua.rol_id = obd2.obj_id) ";
1554  $a2 = "AND obd2.title LIKE 'il_".$a_type."_mem%' ";
1555 
1556  // #14290 - no role folder anymore
1557  $query = "SELECT DISTINCT obd.obj_id,obr.ref_id FROM rbac_ua ua ".
1558  "JOIN rbac_fa fa ON ua.rol_id = fa.rol_id ".
1559  "JOIN object_reference obr ON fa.parent = obr.ref_id ".
1560  "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
1561  $j2.
1562  "WHERE obd.type = ".$ilDB->quote($a_type,'text')." ".
1563  "AND fa.assign = 'y' ".
1564  "AND ua.usr_id = ".$ilDB->quote($a_usr_id,'integer')." ".
1565  $a2;
1566 
1567  $res = $ilDB->query($query);
1568  $obj_ids = array();
1569  while($row = $ilDB->fetchObject($res))
1570  {
1571  $obj_ids[] = $row->obj_id;
1572  }
1573 
1574  $set = $ilDB->query("SELECT obj_id, usr_id FROM obj_members ".
1575  " WHERE ".$ilDB->in("obj_id", $obj_ids, false, "integer").
1576  " AND contact = ".$ilDB->quote(1, "integer"));
1577  $res = array();
1578  while ($rec = $ilDB->fetchAssoc($set))
1579  {
1580  $res[] = $rec;
1581  }
1582 
1583  return $res;
1584  }
1585 
1591  public function setRoleOrderPosition($a_user_id)
1592  {
1593  $counter = 0;
1594  $sortable_assignments = '9999999999';
1595  foreach($this->roles_sorted as $role_id => $trash)
1596  {
1597  if(in_array($a_user_id,(array) $this->role_assignments[$role_id]))
1598  {
1599  $sortable_assignments = substr_replace($sortable_assignments,'1',$counter,1);
1600  }
1601  ++$counter;
1602  }
1603  return $sortable_assignments;
1604  }
1605 }
1606 ?>
getObjId()
get current obj_id
static _isParticipant($a_ref_id, $a_usr_id)
Static function to check if a user is a participant of the container object.
getCountMembers()
Get number of members (not participants)
global $ilErr
Definition: raiseError.php:16
static _getAllSupportContactsOfUser($a_usr_id, $a_type)
Get all support contacts for a user.
addDesktopItem($a_usr_id)
Add desktop item.
static _isSubscriber($a_obj_id, $a_usr_id)
check if user is subscriber
static _deleteAllEntries($a_obj_id)
Delete all entries Normally called for course deletion.
autoFillSubscribers()
Assign subscriber.
static lookupNumberOfParticipants($a_ref_id)
Lookup the number of participants (crs admins, tutors, members, grp admins, members) ...
static lookupNumberOfMembers($a_ref_id)
Lookup number of members ilRbacReview $rbacreview <type> $ilObjDataCache.
updateContact($a_usr_id, $a_contact)
Update contact setting type $ilDB.
readParticipantsStatus()
Read status of participants (blocked, notification, passed)
checkLastAdmin($a_usr_ids)
Check if user for deletion are last admins.
deleteParticipants($a_user_ids)
Delete users.
isAssigned($a_usr_id)
check if user is assigned
isLastAdmin($a_usr_id)
Check if user is last admin.
getCountAdmins()
Get number of admins.
static lookupSubscribers($a_obj_id)
updateBlocked($a_usr_id, $a_blocked)
Update blocked status.
static _deleteUser($a_usr_id)
Delete user.
const IL_GRP_ADMIN
query($sql, $a_handle_error=true)
Query.
assignSubscriber($a_usr_id)
Assign subscriber.
isAdmin($a_usr_id)
is user admin
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
isNotificationEnabled($a_usr_id)
check if notification is enabled
readSubscriberData($a_usr_id)
read subscribers
static _lookupTitle($a_id)
lookup object title
isMember($a_usr_id)
is user member
const IL_CRS_TUTOR
readSubscribers()
read subscribers
static getDefaultMemberRole($a_ref_id)
static _isBlocked($a_obj_id, $a_usr_id)
Check if user is blocked.
dropDesktopItem($a_usr_id)
Drop desktop item.
getAutoGeneratedRoleId($a_role_type)
Get role id of auto generated role type.
deleteSubscriber($a_usr_id)
Delete subsciber.
getAssignedRoles($a_usr_id)
Get assigned roles.
const IL_GRP_MEMBER
const IL_ROLE_POSITION_MEMBER
updateSubject($a_usr_id, $a_subject)
update subject
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
add($a_usr_id, $a_role)
Add user to course.
static hasParticipantListAccess($a_obj_id, $a_usr_id=null)
Check if (current) user has access to the participant list.
static _getAllReferences($a_id)
get all reference ids of object
updateNotification($a_usr_id, $a_notification)
Update notification status.
getCountSubscribers()
get number of subscribers
global $ilCtrl
Definition: ilias.php:18
const IL_CRS_MEMBER
static lookupShowMembersEnabled($a_obj_id)
Check if show member is enabled.
$counter
$a_type
Definition: workflow.php:93
setRoleOrderPosition($a_user_id)
Set role order position.
deleteSubscribers($a_usr_ids)
Delete subscibers.
getMembers()
Get all members ids (admins and tutors are not members) Use get participants to fetch all...
__construct($a_component_name, $a_obj_id)
Singleton Constructor.
updateSubscriptionTime($a_usr_id, $a_subtime)
Update subscription time.
isSubscriber($a_usr_id)
check if is subscriber
getCountParticipants()
Get number of participants.
getSubscribers()
get all subscribers
static _lookupObjId($a_id)
getParticipants()
Get all participants ids.
addSubscriber($a_usr_id)
Add subscriber.
static _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
drop an item from user&#39;s personal desktop
static _hasPassed($a_obj_id, $a_usr_id)
Check if user has passed course.
isContact($a_usr_id)
Check if user is contact.
const IL_CRS_ADMIN
Base class for course and group participants.
isBlocked($a_usr_id)
Check if user is blocked.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
hasPassed($a_usr_id)
Check if user has passed course.
getRoles()
Get course roles.
static lookupSubscribersData($a_obj_id)
assignSubscribers($a_usr_ids)
Assign subscribers.
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user&#39;s personal desktop
updateRoleAssignments($a_usr_id, $a_roles)
Update role assignments.
Database Wrapper.
Definition: class.ilDB.php:29
getAdmins()
Get all admins ids.
getComponent()
Get component name Used for raising events.
static _deleteUser($a_usr_id)
Delete user data.
const IL_ROLE_POSITION_ADMIN
getNotificationRecipients()
Get admin, tutor which have notification enabled.
getContacts()
get user ids which are confirgured as contact
static deleteUserEntry($a_usr_id, $a_obj_id)
Delete one user entry.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static getInstanceByObjId($a_obj_id)
Get instance by obj type.
isGroupingMember($a_usr_id, $a_field='')
Check grouping membership.
getType()
Get object type.
isTutor($a_usr_id)
is user tutor
getSubscriberData($a_usr_id)
get subscriber data
const IL_ROLE_POSITION_TUTOR
static _isDesktopItem($a_usr_id, $a_item_id, $a_type)
check wether an item is on the users desktop or not
readParticipants()
Read participants.
getTutors()
Get all tutors ids.