ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
20 abstract 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();
65  $this->readParticipantsStatus();
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  if (!is_array($a_type))
164  {
165  $a_type = array($a_type);
166  }
167 
168  // this will also dismiss local roles!
169  if ($a_only_member_role)
170  {
171  $j2 = "JOIN object_data obd2 ON (ua.rol_id = obd2.obj_id) ";
172  $a2 = 'AND obd2.title = '.$ilDB->concat(
173  array(
174  array($ilDB->quote('il_','text')),
175  array('obd.type'),
176  array($ilDB->quote('_member_','text')),
177  array('obr.ref_id'),
178  ),
179  false
180  );
181  }
182 
183  // #14290 - no role folder anymore
184  $query = "SELECT DISTINCT obd.obj_id,obr.ref_id FROM rbac_ua ua ".
185  "JOIN rbac_fa fa ON ua.rol_id = fa.rol_id ".
186  "JOIN object_reference obr ON fa.parent = obr.ref_id ".
187  "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
188  $j2.
189  "WHERE ".$ilDB->in("obd.type", $a_type, false, "text").
190  "AND fa.assign = 'y' ".
191  "AND ua.usr_id = ".$ilDB->quote($a_usr_id,'integer')." ".
192  $a2;
193  $res = $ilDB->query($query);
194  while($row = $ilDB->fetchObject($res))
195  {
196  $ref_ids[] = $row->obj_id;
197  }
198 
199  return $ref_ids ? $ref_ids : array();
200  }
201 
202 
203 
212  public static function _isParticipant($a_ref_id,$a_usr_id)
213  {
214  global $rbacreview,$ilObjDataCache,$ilDB,$ilLog;
215 
216  $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
217 
218  return $rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id, $local_roles);
219  }
220 
228  public static function lookupNumberOfParticipants($a_ref_id)
229  {
230  global $rbacreview;
231 
232  $lroles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
233  return $rbacreview->getNumberOfAssignedUsers($lroles);
234  }
235 
243  public static function lookupNumberOfMembers($a_ref_id)
244  {
245  global $rbacreview, $ilObjDataCache;
246 
247  $has_policies = $rbacreview->getLocalPolicies($a_ref_id);
248 
249  if(!$has_policies)
250  {
251  return 0;
252  }
253  $lroles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
254 
255  $memberRoles = array();
256  foreach($lroles as $role_id)
257  {
258  $title = $ilObjDataCache->lookupTitle($role_id);
259  switch(substr($title,0,8))
260  {
261  case 'il_crs_a':
262  case 'il_crs_t':
263  case 'il_grp_a':
264  break;
265 
266  default:
267  $memberRoles[] = $role_id;
268  break;
269  }
270  }
271  return $rbacreview->getNumberOfAssignedUsers($memberRoles);
272  }
273 
274 
284  public static function _isBlocked($a_obj_id,$a_usr_id)
285  {
286  global $ilDB;
287 
288  $query = "SELECT * FROM obj_members ".
289  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
290  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer')." ".
291  "AND blocked = ".$ilDB->quote(1,'integer');
292  $res = $ilDB->query($query);
293  return $res->numRows() ? true : false;
294  }
295 
305  public static function _hasPassed($a_obj_id,$a_usr_id)
306  {
307  global $ilDB;
308 
309  $query = "SELECT * FROM obj_members ".
310  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
311  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
312  "AND passed = '1'";
313  $res = $ilDB->query($query);
314  return $res->numRows() ? true : false;
315  }
316 
326  public static function _deleteAllEntries($a_obj_id)
327  {
328  global $ilDB;
329 
330  $query = "DELETE FROM obj_members ".
331  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
332  $res = $ilDB->manipulate($query);
333 
334  $query = "DELETE FROM il_subscribers ".
335  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
336  $res = $ilDB->manipulate($query);
337 
338  $query = 'DELETE FROM crs_waiting_list '.
339  'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
340  $ilDB->manipulate($query);
341 
342  return true;
343  }
344 
353  public static function _deleteUser($a_usr_id)
354  {
355  global $ilDB;
356 
357  $query = "DELETE FROM obj_members WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
358  $res = $ilDB->manipulate($query);
359 
360  $query = "DELETE FROM il_subscribers WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
361  $res = $ilDB->manipulate($query);
362 
363  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
365  }
366 
367  public static function getDefaultMemberRole($a_ref_id)
368  {
369  global $ilCtrl;
370 
371  $obj_id = ilObject::_lookupObjId($a_ref_id);
373 
374  if(!in_array($type,array('crs','grp')))
375  {
376  return 0;
377  }
378 
379  global $rbacreview;
380 
381 
382  $roles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
383 
384  foreach($roles as $role)
385  {
386  $title = ilObject::_lookupTitle($role);
387  if(substr($title, 0, 13) == ('il_'.$type.'_member'))
388  {
389  return $role;
390  }
391  }
392  return 0;
393  }
394 
399  public function getObjId()
400  {
401  return $this->obj_id;
402  }
403 
408  public function getType()
409  {
410  return $this->type;
411  }
412 
419  public function getNotificationRecipients()
420  {
421  global $ilDB;
422 
423  $query = "SELECT * FROM obj_members ".
424  "WHERE notification = 1 ".
425  "AND obj_id = ".$ilDB->quote($this->obj_id)." ";
426  $res = $ilDB->query($query);
427  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
428  {
429  if($this->isAdmin($row->usr_id) or $this->isTutor($row->usr_id))
430  {
431  $recp[] = $row->usr_id;
432  }
433  }
434  return $recp ? $recp : array();
435  }
436 
443  public function getCountMembers()
444  {
445  return count($this->members);
446  }
447 
454  public function getCountParticipants()
455  {
456  return count($this->participants);
457  }
458 
459 
460 
461 
468  public function getParticipants()
469  {
470  return $this->participants ? $this->participants : array();
471  }
472 
480  public function getMembers()
481  {
482  return $this->members ? $this->members : array();
483  }
490  public function getAdmins()
491  {
492  return $this->admins ? $this->admins : array();
493  }
494 
499  public function getCountAdmins()
500  {
501  return count($this->getAdmins());
502  }
503 
504 
511  public function getTutors()
512  {
513  return $this->tutors ? $this->tutors : array();
514  }
515 
523  public function isAdmin($a_usr_id)
524  {
525  return in_array($a_usr_id,$this->admins) ? true : false;
526  }
527 
535  public function isTutor($a_usr_id)
536  {
537  return in_array($a_usr_id,$this->tutors) ? true : false;
538  }
539 
547  public function isMember($a_usr_id)
548  {
549  return in_array($a_usr_id,$this->members) ? true : false;
550  }
551 
552 
553 
554 
562  public function isAssigned($a_usr_id)
563  {
564  return in_array($a_usr_id,$this->participants);
565  }
566 
572  public function isLastAdmin($a_usr_id)
573  {
574  return in_array($a_usr_id,$this->getAdmins()) and count($this->getAdmins()) == 1;
575  }
576 
577 
585  public function getRoles()
586  {
587  return $this->roles ? $this->roles : array();
588  }
589 
597  public function getAssignedRoles($a_usr_id)
598  {
599  global $rbacreview;
600 
601  foreach($this->roles as $role)
602  {
603  if($rbacreview->isAssigned($a_usr_id,$role))
604  {
605  $assigned[] = $role;
606  }
607  }
608  return $assigned ? $assigned : array();
609  }
610 
619  public function updateRoleAssignments($a_usr_id,$a_roles)
620  {
621  global $rbacreview,$rbacadmin;
622 
623  $roles = $a_roles ? $a_roles : array();
624 
625  foreach($this->getRoles() as $role_id)
626  {
627  if($rbacreview->isAssigned($a_usr_id,$role_id))
628  {
629  if(!in_array($role_id,$roles))
630  {
631  $rbacadmin->deassignUser($role_id,$a_usr_id);
632  }
633  }
634  else
635  {
636  if(in_array($role_id,$roles))
637  {
638  $rbacadmin->assignUser($role_id,$a_usr_id);
639  }
640  }
641  }
642  $rbacreview->clearCaches();
643  $this->readParticipants();
644  $this->readParticipantsStatus();
645  }
646 
654  public function checkLastAdmin($a_usr_ids)
655  {
656  foreach($this->getAdmins() as $admin_id)
657  {
658  if(!in_array($admin_id,$a_usr_ids))
659  {
660  return true;
661  }
662  }
663  return false;
664  }
665 
673  public function isBlocked($a_usr_id)
674  {
675  if(isset($this->participants_status[$a_usr_id]))
676  {
677  return $this->participants_status[$a_usr_id]['blocked'] ? true : false;
678  }
679  return false;
680  }
681 
689  public function hasPassed($a_usr_id)
690  {
691  if(isset($this->participants_status[$a_usr_id]))
692  {
693  return $this->participants_status[$a_usr_id]['passed'] ? true : false;
694  }
695  return false;
696  }
697 
705  public function delete($a_usr_id)
706  {
707  global $rbacadmin,$ilDB;
708 
709  $this->dropDesktopItem($a_usr_id);
710  foreach($this->roles as $role_id)
711  {
712  $rbacadmin->deassignUser($role_id,$a_usr_id);
713  }
714 
715  $query = "DELETE FROM obj_members ".
716  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
717  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer');
718  $res = $ilDB->manipulate($query);
719 
720  $this->readParticipants();
721  $this->readParticipantsStatus();
722 
723  $GLOBALS['ilAppEventHandler']->raise(
724  $this->getComponent(),
725  "deleteParticipant",
726  array(
727  'obj_id' => $this->obj_id,
728  'usr_id' => $a_usr_id)
729  );
730 
731  return true;
732  }
733 
742  public function updateBlocked($a_usr_id,$a_blocked)
743  {
744  global $ilDB;
745 
746  $this->participants_status[$a_usr_id]['blocked'] = (int) $a_blocked;
747 
748  $query = "SELECT * FROM obj_members ".
749  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
750  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
751  $res = $ilDB->query($query);
752  if($res->numRows())
753  {
754  $query = "UPDATE obj_members SET ".
755  "blocked = ".$ilDB->quote((int) $a_blocked ,'integer')." ".
756  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
757  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
758  }
759  else
760  {
761  $query = "INSERT INTO obj_members (blocked,obj_id,usr_id,notification,passed) ".
762  "VALUES ( ".
763  $ilDB->quote((int) $a_blocked ,'integer').", ".
764  $ilDB->quote($this->obj_id ,'integer').", ".
765  $ilDB->quote($a_usr_id ,'integer').", ".
766  $ilDB->quote(0,'integer').", ".
767  $ilDB->quote(0,'integer').
768  ")";
769 
770  }
771  $res = $ilDB->manipulate($query);
772  return true;
773  }
774 
775  // cognos-blu-patch: begin
783  public function updateContact($a_usr_id, $a_contact)
784  {
785  global $ilDB;
786 
787  $ilDB->manipulate(
788  'UPDATE obj_members SET '.
789  'contact = '.$ilDB->quote($a_contact,'integer').' '.
790  'WHERE obj_id = '.$ilDB->quote($this->obj_id,'integer').' '.
791  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer'));
792 
793  $this->participants_status[$a_usr_id]['contact'] = $a_contact;
794  return TRUE;
795  }
796 
801  public function getContacts()
802  {
803  $contacts = array();
804  foreach((array) $this->participants_status as $usr_id => $status)
805  {
806  if($status['contact'])
807  {
808  $contacts[] = $usr_id;
809  }
810  }
811  return $contacts;
812  }
813 
814 
815  // cognos-blu-patch: end
816 
825  public function updateNotification($a_usr_id,$a_notification)
826  {
827  global $ilDB;
828 
829  $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
830 
831  $query = "SELECT * FROM obj_members ".
832  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
833  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
834  $res = $ilDB->query($query);
835  if($res->numRows())
836  {
837  $query = "UPDATE obj_members SET ".
838  "notification = ".$ilDB->quote((int) $a_notification ,'integer')." ".
839  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
840  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
841  }
842  else
843  {
844  $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) ".
845  "VALUES ( ".
846  $ilDB->quote((int) $a_notification ,'integer').", ".
847  $ilDB->quote($this->obj_id ,'integer').", ".
848  $ilDB->quote($a_usr_id ,'integer').", ".
849  $ilDB->quote(0,'integer').", ".
850  $ilDB->quote(0,'integer').
851  ")";
852 
853  }
854  $res = $ilDB->manipulate($query);
855  return true;
856  }
857 
858 
859 
860 
869  public function add($a_usr_id,$a_role)
870  {
871  global $rbacadmin,$ilLog,$ilAppEventHandler;
872 
873  if($this->isAssigned($a_usr_id))
874  {
875  return false;
876  }
877 
878  switch($a_role)
879  {
880  case IL_CRS_ADMIN:
881  $this->admins[] = $a_usr_id;
882  break;
883 
884  case IL_CRS_TUTOR:
885  $this->tutors[] = $a_usr_id;
886  break;
887 
888  case IL_CRS_MEMBER:
889  $this->members[] = $a_usr_id;
890  break;
891 
892  case IL_GRP_ADMIN:
893  $this->admins[] = $a_usr_id;
894  break;
895 
896  case IL_GRP_MEMBER:
897  $this->members[] = $a_usr_id;
898  break;
899  }
900 
901  $this->participants[] = $a_usr_id;
902  $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
903  $this->addDesktopItem($a_usr_id);
904 
905  // Delete subscription request
906  $this->deleteSubscriber($a_usr_id);
907 
908  include_once './Services/Membership/classes/class.ilWaitingList.php';
909  ilWaitingList::deleteUserEntry($a_usr_id,$this->obj_id);
910 
911  $ilLog->write(__METHOD__.': Raise new event: '.$this->getComponent().' addParticipant');
912  $ilAppEventHandler->raise(
913  $this->getComponent(),
914  "addParticipant",
915  array(
916  'obj_id' => $this->obj_id,
917  'usr_id' => $a_usr_id,
918  'role_id' => $a_role)
919  );
920  return true;
921  }
922 
923 
931  public function deleteParticipants($a_user_ids)
932  {
933  foreach($a_user_ids as $user_id)
934  {
935  $this->delete($user_id);
936  }
937  return true;
938  }
939 
947  public function addDesktopItem($a_usr_id)
948  {
949  if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
950  {
951  ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
952  }
953  return true;
954  }
955 
963  function dropDesktopItem($a_usr_id)
964  {
965  if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
966  {
967  ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
968  }
969 
970  return true;
971  }
972 
973 
974 
982  public function isNotificationEnabled($a_usr_id)
983  {
984  if(isset($this->participants_status[$a_usr_id]))
985  {
986  return $this->participants_status[$a_usr_id]['notification'] ? true : false;
987  }
988  return false;
989  }
990 
991  // cognos-blu-patch: begin
996  public function isContact($a_usr_id)
997  {
998  if(isset($this->participants_status[$a_usr_id]))
999  {
1000  return (bool) $this->participants_status[$a_usr_id]['contact'];
1001  }
1002  return FALSE;
1003  }
1004  // cognos-blu-patch: end
1005 
1006 
1007 
1015  protected function readParticipants()
1016  {
1017  global $rbacreview,$ilObjDataCache,$ilLog;
1018 
1019  $GLOBALS['rbacreview']->clearCaches();
1020  $this->roles = $rbacreview->getRolesOfRoleFolder($this->ref_id,false);
1021 
1022  $users = array();
1023  $this->participants = array();
1024  $this->members = $this->admins = $this->tutors = array();
1025 
1026  foreach($this->roles as $role_id)
1027  {
1028  $title = $ilObjDataCache->lookupTitle($role_id);
1029  switch(substr($title,0,8))
1030  {
1031  case 'il_crs_m':
1032  $this->role_data[IL_CRS_MEMBER] = $role_id;
1033  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1034  $this->members = array_unique(array_merge($assigned,$this->members));
1035  break;
1036 
1037  case 'il_crs_a':
1038  $this->role_data[IL_CRS_ADMIN] = $role_id;
1039  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1040  $this->admins = $rbacreview->assignedUsers($role_id);
1041  break;
1042 
1043  case 'il_crs_t':
1044  $this->role_data[IL_CRS_TUTOR] = $role_id;
1045  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1046  $this->tutors = $rbacreview->assignedUsers($role_id);
1047  break;
1048 
1049  case 'il_grp_a':
1050  $this->role_data[IL_GRP_ADMIN] = $role_id;
1051  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1052  $this->admins = $rbacreview->assignedUsers($role_id);
1053  break;
1054 
1055  case 'il_grp_m':
1056  $this->role_data[IL_GRP_MEMBER] = $role_id;
1057  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1058  $this->members = $rbacreview->assignedUsers($role_id);
1059  break;
1060 
1061  default:
1062  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id),$this->participants));
1063  $this->members = array_unique(array_merge($assigned,$this->members));
1064  break;
1065  }
1066  }
1067  }
1068 
1076  protected function readParticipantsStatus()
1077  {
1078  global $ilDB;
1079 
1080  $query = "SELECT * FROM obj_members ".
1081  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1082  $res = $ilDB->query($query);
1083  $this->participants_status = array();
1084  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1085  {
1086  $this->participants_status[$row->usr_id]['blocked'] = $row->blocked;
1087  $this->participants_status[$row->usr_id]['notification'] = $row->notification;
1088  $this->participants_status[$row->usr_id]['passed'] = $row->passed;
1089  // cognos-blu-patch: begin
1090  $this->participants_status[$row->usr_id]['contact'] = $row->contact;
1091  // cognos-blu-patch: end
1092  }
1093  }
1094 
1102  public function isGroupingMember($a_usr_id,$a_field = '')
1103  {
1104  global $rbacreview,$ilObjDataCache,$ilDB;
1105 
1106  // Used for membership limitations -> check membership by given field
1107  if($a_field)
1108  {
1109  include_once './Services/User/classes/class.ilObjUser.php';
1110 
1111  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_usr_id);
1112  switch($a_field)
1113  {
1114  case 'login':
1115  $and = "AND login = ".$ilDB->quote($tmp_user->getLogin(),'text')." ";
1116  break;
1117  case 'email':
1118  $and = "AND email = ".$ilDB->quote($tmp_user->getEmail(),'text')." ";
1119  break;
1120  case 'matriculation':
1121  $and = "AND matriculation = ".$ilDB->quote($tmp_user->getMatriculation(),'text')." ";
1122  break;
1123 
1124  default:
1125  $and = "AND usr_id = ".$ilDB->quote($a_usr_id,'integer'). " ";
1126  break;
1127  }
1128 
1129  if(!$this->getParticipants())
1130  {
1131  return false;
1132  }
1133 
1134  $query = "SELECT * FROM usr_data ud ".
1135  "WHERE ".$ilDB->in('usr_id',$this->getParticipants(),false,'integer')." ".
1136  $and;
1137 
1138  $res = $ilDB->query($query);
1139  return $res->numRows() ? true : false;
1140  }
1141  }
1142 
1143  public static function lookupSubscribers($a_obj_id)
1144  {
1145  global $ilDB;
1146 
1147  $subscribers = array();
1148  $query = "SELECT usr_id FROM il_subscribers ".
1149  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
1150  "ORDER BY sub_time ";
1151 
1152  $res = $ilDB->query($query);
1153  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1154  {
1155  $subscribers[] = $row->usr_id;
1156  }
1157  return $subscribers;
1158  }
1159 
1165  public function getSubscribers()
1166  {
1167  $this->readSubscribers();
1168 
1169  return $this->subscribers;
1170  }
1171 
1172 
1178  public function getCountSubscribers()
1179  {
1180  return count($this->getSubscribers());
1181  }
1182 
1188  public function getSubscriberData($a_usr_id)
1189  {
1190  return $this->readSubscriberData($a_usr_id);
1191  }
1192 
1193 
1194 
1200  public function assignSubscribers($a_usr_ids)
1201  {
1202  if(!is_array($a_usr_ids) or !count($a_usr_ids))
1203  {
1204  return false;
1205  }
1206  foreach($a_usr_ids as $id)
1207  {
1208  if(!$this->assignSubscriber($id))
1209  {
1210  return false;
1211  }
1212  }
1213  return true;
1214  }
1215 
1221  public function assignSubscriber($a_usr_id)
1222  {
1223  global $ilErr;
1224 
1225  $ilErr->setMessage("");
1226  if(!$this->isSubscriber($a_usr_id))
1227  {
1228  $ilErr->appendMessage($this->lng->txt("crs_user_notsubscribed"));
1229 
1230  return false;
1231  }
1232  if($this->isAssigned($a_usr_id))
1233  {
1234  $tmp_obj = ilObjectFactory::getInstanceByObjId($a_usr_id);
1235  $ilErr->appendMessage($tmp_obj->getLogin().": ".$this->lng->txt("crs_user_already_assigned"));
1236 
1237  return false;
1238  }
1239 
1240  if(!$tmp_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id))
1241  {
1242  $ilErr->appendMessage($this->lng->txt("crs_user_not_exists"));
1243 
1244  return false;
1245  }
1246 
1247  // TODO: must be group or course member role
1248  $this->add($tmp_obj->getId(),IL_CRS_MEMBER);
1249  $this->deleteSubscriber($a_usr_id);
1250 
1251  return true;
1252  }
1253 
1259  public function autoFillSubscribers()
1260  {
1261  $this->readSubscribers();
1262 
1263  $counter = 0;
1264  foreach($this->subscribers as $subscriber)
1265  {
1266  if(!$this->assignSubscriber($subscriber))
1267  {
1268  continue;
1269  }
1270  else
1271  {
1272  // TODO: notification
1273  #$this->sendNotification($this->NOTIFY_ACCEPT_SUBSCRIBER,$subscriber);
1274  }
1275  ++$counter;
1276  }
1277 
1278  return $counter;
1279  }
1280 
1286  public function addSubscriber($a_usr_id)
1287  {
1288  global $ilDB;
1289 
1290  $query = "INSERT INTO il_subscribers (usr_id,obj_id,subject,sub_time) ".
1291  " VALUES (".
1292  $ilDB->quote($a_usr_id ,'integer').",".
1293  $ilDB->quote($this->obj_id ,'integer').", ".
1294  $ilDB->quote('','text').", ".
1295  $ilDB->quote(time() ,'integer').
1296  ")";
1297  $res = $ilDB->manipulate($query);
1298 
1299  return true;
1300  }
1301 
1302 
1308  public function updateSubscriptionTime($a_usr_id,$a_subtime)
1309  {
1310  global $ilDB;
1311 
1312  $query = "UPDATE il_subscribers ".
1313  "SET sub_time = ".$ilDB->quote($a_subtime ,'integer')." ".
1314  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1315  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1316  $res = $ilDB->manipulate($query);
1317 
1318  return true;
1319  }
1320 
1328  public function updateSubject($a_usr_id,$a_subject)
1329  {
1330  global $ilDB;
1331 
1332  $query = "UPDATE il_subscribers ".
1333  "SET subject = ".$ilDB->quote($a_subject ,'text')." ".
1334  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1335  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1336  $res = $ilDB->manipulate($query);
1337  return true;
1338  }
1339 
1340 
1346  public function deleteSubscriber($a_usr_id)
1347  {
1348  global $ilDB;
1349 
1350  $query = "DELETE FROM il_subscribers ".
1351  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1352  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
1353  $res = $ilDB->manipulate($query);
1354 
1355  return true;
1356  }
1357 
1358 
1364  public function deleteSubscribers($a_usr_ids)
1365  {
1366  global $ilErr,$ilDB;
1367 
1368  if(!is_array($a_usr_ids) or !count($a_usr_ids))
1369  {
1370  $ilErr->setMessage('');
1371  $ilErr->appendMessage($this->lng->txt("no_usr_ids_given"));
1372 
1373  return false;
1374  }
1375  $query = "DELETE FROM il_subscribers ".
1376  "WHERE ".$ilDB->in('usr_id',(array) $a_usr_ids,false,'integer')." ".
1377  "AND obj_id = ".$ilDB->quote($this->obj_id,'integer');
1378  $res = $ilDB->query($query);
1379  return true;
1380  }
1381 
1382 
1388  public function isSubscriber($a_usr_id)
1389  {
1390  global $ilDB;
1391 
1392  $query = "SELECT * FROM il_subscribers ".
1393  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1394  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')."";
1395 
1396  $res = $ilDB->query($query);
1397  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1398  {
1399  return true;
1400  }
1401  return false;
1402  }
1403 
1410  public static function _isSubscriber($a_obj_id,$a_usr_id)
1411  {
1412  global $ilDB;
1413 
1414  $query = "SELECT * FROM il_subscribers ".
1415  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
1416  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
1417 
1418  $res = $ilDB->query($query);
1419  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1420  {
1421  return true;
1422  }
1423  return false;
1424  }
1425 
1431  protected function readSubscribers()
1432  {
1433  global $ilDB;
1434 
1435  $this->subscribers = array();
1436 
1437  $query = "SELECT usr_id FROM il_subscribers ".
1438  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
1439  "ORDER BY sub_time ";
1440 
1441  $res = $this->ilDB->query($query);
1442  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1443  {
1444  // DELETE SUBSCRIPTION IF USER HAS BEEN DELETED
1445  if(!ilObjectFactory::getInstanceByObjId($row->usr_id,false))
1446  {
1447  $this->deleteSubscriber($row->usr_id);
1448  }
1449  $this->subscribers[] = $row->usr_id;
1450  }
1451  return true;
1452  }
1453 
1459  protected function readSubscriberData($a_usr_id)
1460  {
1461  global $ilDB;
1462 
1463  $query = "SELECT * FROM il_subscribers ".
1464  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
1465  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')."";
1466 
1467  $res = $this->ilDB->query($query);
1468  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1469  {
1470  $data["time"] = $row->sub_time;
1471  $data["usr_id"] = $row->usr_id;
1472  $data['subject'] = $row->subject;
1473  }
1474  return $data ? $data : array();
1475  }
1476 
1477  public static function lookupSubscribersData($a_obj_id)
1478  {
1479  global $ilDB;
1480 
1481  $query = 'SELECT * FROM il_subscribers '.
1482  'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
1483  $res = $ilDB->query($query);
1484 
1485  $data = array();
1486  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1487  {
1488  $data[$row->usr_id]['time'] = $row->sub_time;
1489  $data[$row->usr_id]['usr_id'] = $row->usr_id;
1490  $data[$row->usr_id]['subject'] = $row->subject;
1491  }
1492  return $data;
1493  }
1494 
1502  public static function _getAllSupportContactsOfUser($a_usr_id,$a_type)
1503  {
1504  global $ilDB;
1505 
1506  // todo: join the two queries or alternatively reuse _getMembershipByType
1507  // for the first part
1508 
1509  // this will also dismiss local roles!
1510  $j2 = "JOIN object_data obd2 ON (ua.rol_id = obd2.obj_id) ";
1511  $a2 = "AND obd2.title LIKE 'il_".$a_type."_mem%' ";
1512 
1513  // #14290 - no role folder anymore
1514  $query = "SELECT DISTINCT obd.obj_id,obr.ref_id FROM rbac_ua ua ".
1515  "JOIN rbac_fa fa ON ua.rol_id = fa.rol_id ".
1516  "JOIN object_reference obr ON fa.parent = obr.ref_id ".
1517  "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
1518  $j2.
1519  "WHERE obd.type = ".$ilDB->quote($a_type,'text')." ".
1520  "AND fa.assign = 'y' ".
1521  "AND ua.usr_id = ".$ilDB->quote($a_usr_id,'integer')." ".
1522  $a2;
1523 
1524  $res = $ilDB->query($query);
1525  $obj_ids = array();
1526  while($row = $ilDB->fetchObject($res))
1527  {
1528  $obj_ids[] = $row->obj_id;
1529  }
1530 
1531  $set = $ilDB->query("SELECT obj_id, usr_id FROM obj_members ".
1532  " WHERE ".$ilDB->in("obj_id", $obj_ids, false, "integer").
1533  " AND contact = ".$ilDB->quote(1, "integer"));
1534  $res = array();
1535  while ($rec = $ilDB->fetchAssoc($set))
1536  {
1537  $res[] = $rec;
1538  }
1539 
1540  return $res;
1541  }
1542 
1543 }
1544 ?>
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)
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
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.
deleteSubscriber($a_usr_id)
Delete subsciber.
getAssignedRoles($a_usr_id)
Get assigned roles.
const IL_GRP_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
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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.
deleteSubscribers($a_usr_ids)
Delete subscibers.
getMembers()
Get all members ids (admins and tutors are not members) Use get participants to fetch all...
$data
__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.
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
isBlocked($a_usr_id)
Check if user is blocked.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
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:28
getAdmins()
Get all admins ids.
getComponent()
Get component name Used for raising events.
static _deleteUser($a_usr_id)
Delete user data.
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.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
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
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.