ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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_SESS_MEMBER', 6);
20 
21 define("IL_ROLE_POSITION_ADMIN", 1);
22 define("IL_ROLE_POSITION_TUTOR", 2);
23 define("IL_ROLE_POSITION_MEMBER", 3);
24 
25 
26 abstract class ilParticipants
27 {
28  protected $component = '';
29 
30  protected $obj_id = 0;
31  protected $type = '';
32  protected $ref_id = 0;
33 
34  protected $roles = array();
35  protected $role_data = array();
36  protected $roles_sorted = [];
37  protected $role_assignments = [];
38 
39  protected $participants = array();
40  protected $participants_status = array();
41  protected $members = array();
42  protected $tutors = array();
43  protected $admins = array();
44 
45  protected $subscribers = array();
46 
50  protected $ilDB;
51 
55  protected $lng;
56 
61  protected $logger = null;
62 
63 
72  public function __construct($a_component_name, $a_ref_id)
73  {
74  $this->ilDB = $GLOBALS['DIC']->database();
75  $this->lng = $GLOBALS['DIC']->language();
76  $this->logger = $GLOBALS['DIC']->logger()->mem();
77 
78  $this->component = $a_component_name;
79 
80  $this->ref_id = $a_ref_id;
81  $this->obj_id = ilObject::_lookupObjId($a_ref_id);
82  $this->type = ilObject::_lookupType($this->obj_id);
83 
84  $this->readParticipants();
85  $this->readParticipantsStatus();
86  }
87 
93  public static function getInstance($a_ref_id)
94  {
95  $obj_id = ilObject::_lookupObjId($a_ref_id);
97 
98  switch ($type) {
99  case 'crs':
100  case 'grp':
101  return self::getInstanceByObjId($obj_id);
102 
103  case 'sess':
104  include_once './Modules/Session/classes/class.ilSessionParticipants.php';
105  return ilSessionParticipants::getInstance($a_ref_id);
106 
107  default:
108  $GLOBALS['DIC']->logger()->mem()->logStack();
109  $GLOBALS['DIC']->logger()->mem()->warning('Invalid ref_id -> obj_id given: ' . $a_ref_id . ' -> ' . $obj_id);
110  throw new \InvalidArgumentException('Invalid obj_id given.');
111  }
112  }
113 
122  public static function getInstanceByObjId($a_obj_id)
123  {
124  $type = ilObject::_lookupType($a_obj_id);
125  switch ($type) {
126  case 'crs':
127  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
129 
130  case 'grp':
131  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
133 
134  case 'sess':
135  include_once './Modules/Session/classes/class.ilSessionParticipants.php';
137 
138  default:
139  $GLOBALS['ilLog']->logStack();
140  $GLOBALS['ilLog']->write(__METHOD__ . ': Invalid obj_id given: ' . $a_obj_id);
141  throw new InvalidArgumentException('Invalid obj id given');
142  }
143  }
144 
149  protected function getComponent()
150  {
151  return $this->component;
152  }
153 
154 
155 
161  public static function hasParticipantListAccess($a_obj_id, $a_usr_id = null)
162  {
163  global $DIC;
164 
165  $access = $DIC->access();
166 
167  if (!$a_usr_id) {
168  $a_usr_id = $GLOBALS['ilUser']->getId();
169  }
170 
171  // if write access granted => return true
172  $refs = ilObject::_getAllReferences($a_obj_id);
173  $ref_id = end($refs);
174 
175  if ($access->checkAccess('manage_members', '', $ref_id)) {
176  return true;
177  }
178  $part = self::getInstance($ref_id);
179  if ($part->isAssigned($a_usr_id)) {
180  if ($part->getType() == 'crs') {
181  if (!ilObjCourse::lookupShowMembersEnabled($a_obj_id)) {
182  return false;
183  }
184  }
185  if ($part->getType() == 'grp') {
186  if (!ilObjGroup::lookupShowMembersEnabled($a_obj_id)) {
187  return false;
188  }
189  }
190  return true;
191  }
192  // User is not assigned to course/group => no read access
193  return false;
194  }
195 
207  public static function _getMembershipByType($a_usr_id, $a_type, $a_only_member_role = false)
208  {
209  global $ilDB;
210 
211  if (!is_array($a_type)) {
212  $a_type = array($a_type);
213  }
214 
215  // this will also dismiss local roles!
216  if ($a_only_member_role) {
217  $j2 = "JOIN object_data obd2 ON (ua.rol_id = obd2.obj_id) ";
218  $a2 = 'AND obd2.title = ' . $ilDB->concat(
219  array(
220  array($ilDB->quote('il_', 'text')),
221  array('obd.type'),
222  array($ilDB->quote('_member_', 'text')),
223  array('obr.ref_id'),
224  ),
225  false
226  );
227  }
228 
229  // #14290 - no role folder anymore
230  $query = "SELECT DISTINCT obd.obj_id,obr.ref_id FROM rbac_ua ua " .
231  "JOIN rbac_fa fa ON ua.rol_id = fa.rol_id " .
232  "JOIN object_reference obr ON fa.parent = obr.ref_id " .
233  "JOIN object_data obd ON obr.obj_id = obd.obj_id " .
234  $j2 .
235  "WHERE " . $ilDB->in("obd.type", $a_type, false, "text") .
236  "AND fa.assign = 'y' " .
237  "AND ua.usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
238  $a2;
239  $res = $ilDB->query($query);
240  while ($row = $ilDB->fetchObject($res)) {
241  $ref_ids[] = $row->obj_id;
242  }
243 
244  return $ref_ids ? $ref_ids : array();
245  }
246 
247 
248 
257  public static function _isParticipant($a_ref_id, $a_usr_id)
258  {
259  global $rbacreview;
260 
261  $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id, false);
262 
263  return $rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id, $local_roles);
264  }
265 
273  public static function lookupNumberOfParticipants($a_ref_id)
274  {
275  global $rbacreview;
276 
277  $lroles = $rbacreview->getRolesOfRoleFolder($a_ref_id, false);
278  return $rbacreview->getNumberOfAssignedUsers($lroles);
279  }
280 
288  public static function lookupNumberOfMembers($a_ref_id)
289  {
290  global $rbacreview, $ilObjDataCache;
291 
292  $has_policies = $rbacreview->getLocalPolicies($a_ref_id);
293 
294  if (!$has_policies) {
295  return 0;
296  }
297  $lroles = $rbacreview->getRolesOfRoleFolder($a_ref_id, false);
298 
299  $memberRoles = array();
300  foreach ($lroles as $role_id) {
301  $title = $ilObjDataCache->lookupTitle($role_id);
302  switch (substr($title, 0, 8)) {
303  case 'il_crs_a':
304  case 'il_crs_t':
305  case 'il_grp_a':
306  break;
307 
308  default:
309  $memberRoles[] = $role_id;
310  break;
311  }
312  }
313  return $rbacreview->getNumberOfAssignedUsers($memberRoles);
314  }
315 
316 
326  public static function _isBlocked($a_obj_id, $a_usr_id)
327  {
328  global $ilDB;
329 
330  $query = "SELECT * FROM obj_members " .
331  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
332  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
333  "AND blocked = " . $ilDB->quote(1, 'integer');
334  $res = $ilDB->query($query);
335  return $res->numRows() ? true : false;
336  }
337 
347  public static function _hasPassed($a_obj_id, $a_usr_id)
348  {
349  global $ilDB;
350 
351  $query = "SELECT * FROM obj_members " .
352  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
353  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
354  "AND passed = '1'";
355  $res = $ilDB->query($query);
356  return $res->numRows() ? true : false;
357  }
358 
368  public static function _deleteAllEntries($a_obj_id)
369  {
370  global $ilDB;
371 
372  $query = "DELETE FROM obj_members " .
373  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
374  $res = $ilDB->manipulate($query);
375 
376  $query = "DELETE FROM il_subscribers " .
377  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . "";
378  $res = $ilDB->manipulate($query);
379 
380  $query = 'DELETE FROM crs_waiting_list ' .
381  'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
382  $ilDB->manipulate($query);
383 
384  return true;
385  }
386 
395  public static function _deleteUser($a_usr_id)
396  {
397  global $ilDB;
398 
399  $query = "DELETE FROM obj_members WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . "";
400  $res = $ilDB->manipulate($query);
401 
402  $query = "DELETE FROM il_subscribers WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . "";
403  $res = $ilDB->manipulate($query);
404 
405  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
407  }
408 
409  public static function getDefaultMemberRole($a_ref_id)
410  {
411  global $ilCtrl;
412 
413  $obj_id = ilObject::_lookupObjId($a_ref_id);
415 
416  if (!in_array($type, array('crs','grp'))) {
417  return 0;
418  }
419 
420  global $rbacreview;
421 
422 
423  $roles = $rbacreview->getRolesOfRoleFolder($a_ref_id, false);
424 
425  foreach ($roles as $role) {
427  if (substr($title, 0, 13) == ('il_' . $type . '_member')) {
428  return $role;
429  }
430  }
431  return 0;
432  }
433 
438  public function getObjId()
439  {
440  return $this->obj_id;
441  }
442 
447  public function getType()
448  {
449  return $this->type;
450  }
451 
458  public function getNotificationRecipients()
459  {
460  global $ilDB;
461 
462  $query = "SELECT * FROM obj_members " .
463  "WHERE notification = 1 " .
464  "AND obj_id = " . $ilDB->quote($this->obj_id) . " ";
465  $res = $ilDB->query($query);
466  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
467  if ($this->isAdmin($row->usr_id) or $this->isTutor($row->usr_id)) {
468  $recp[] = $row->usr_id;
469  }
470  }
471  return $recp ? $recp : array();
472  }
473 
480  public function getCountMembers()
481  {
482  return count($this->members);
483  }
484 
491  public function getCountParticipants()
492  {
493  return count($this->participants);
494  }
495 
496 
497 
498 
505  public function getParticipants()
506  {
507  return $this->participants ? $this->participants : array();
508  }
509 
517  public function getMembers()
518  {
519  return $this->members ? $this->members : array();
520  }
527  public function getAdmins()
528  {
529  return $this->admins ? $this->admins : array();
530  }
531 
536  public function getCountAdmins()
537  {
538  return count($this->getAdmins());
539  }
540 
541 
548  public function getTutors()
549  {
550  return $this->tutors ? $this->tutors : array();
551  }
552 
560  public function isAdmin($a_usr_id)
561  {
562  return in_array($a_usr_id, $this->admins) ? true : false;
563  }
564 
572  public function isTutor($a_usr_id)
573  {
574  return in_array($a_usr_id, $this->tutors) ? true : false;
575  }
576 
584  public function isMember($a_usr_id)
585  {
586  return in_array($a_usr_id, $this->members) ? true : false;
587  }
588 
589 
590 
591 
599  public function isAssigned($a_usr_id)
600  {
601  return in_array($a_usr_id, $this->participants);
602  }
603 
609  public function isLastAdmin($a_usr_id)
610  {
611  return in_array($a_usr_id, $this->getAdmins()) and count($this->getAdmins()) == 1;
612  }
613 
614 
622  public function getRoles()
623  {
624  return $this->roles ? $this->roles : array();
625  }
626 
634  public function getAssignedRoles($a_usr_id)
635  {
636  global $rbacreview;
637 
638  foreach ($this->roles as $role) {
639  if ($rbacreview->isAssigned($a_usr_id, $role)) {
640  $assigned[] = $role;
641  }
642  }
643  return $assigned ? $assigned : array();
644  }
645 
654  public function updateRoleAssignments($a_usr_id, $a_roles)
655  {
656  global $rbacreview,$rbacadmin;
657 
658  $roles = $a_roles ? $a_roles : array();
659 
660  foreach ($this->getRoles() as $role_id) {
661  if ($rbacreview->isAssigned($a_usr_id, $role_id)) {
662  if (!in_array($role_id, $roles)) {
663  $rbacadmin->deassignUser($role_id, $a_usr_id);
664  }
665  } else {
666  if (in_array($role_id, $roles)) {
667  $rbacadmin->assignUser($role_id, $a_usr_id);
668  }
669  }
670  }
671  $rbacreview->clearCaches();
672  $this->readParticipants();
673  $this->readParticipantsStatus();
674  }
675 
683  public function checkLastAdmin($a_usr_ids)
684  {
685  foreach ($this->getAdmins() as $admin_id) {
686  if (!in_array($admin_id, $a_usr_ids)) {
687  return true;
688  }
689  }
690  return false;
691  }
692 
700  public function isBlocked($a_usr_id)
701  {
702  if (isset($this->participants_status[$a_usr_id])) {
703  return $this->participants_status[$a_usr_id]['blocked'] ? true : false;
704  }
705  return false;
706  }
707 
715  public function hasPassed($a_usr_id)
716  {
717  if (isset($this->participants_status[$a_usr_id])) {
718  return $this->participants_status[$a_usr_id]['passed'] ? true : false;
719  }
720  return false;
721  }
722 
730  public function delete($a_usr_id)
731  {
732  global $rbacadmin,$ilDB;
733 
734  $this->dropDesktopItem($a_usr_id);
735  foreach ($this->roles as $role_id) {
736  $rbacadmin->deassignUser($role_id, $a_usr_id);
737  }
738 
739  $query = "DELETE FROM obj_members " .
740  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
741  "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer');
742  $res = $ilDB->manipulate($query);
743 
744  $this->readParticipants();
745  $this->readParticipantsStatus();
746 
747  $GLOBALS['ilAppEventHandler']->raise(
748  $this->getComponent(),
749  "deleteParticipant",
750  array(
751  'obj_id' => $this->obj_id,
752  'usr_id' => $a_usr_id)
753  );
754 
755  return true;
756  }
757 
766  public function updateBlocked($a_usr_id, $a_blocked)
767  {
768  global $ilDB;
769 
770  $this->participants_status[$a_usr_id]['blocked'] = (int) $a_blocked;
771 
772  $query = "SELECT * FROM obj_members " .
773  "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
774  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
775  $res = $ilDB->query($query);
776  if ($res->numRows()) {
777  $query = "UPDATE obj_members SET " .
778  "blocked = " . $ilDB->quote((int) $a_blocked, 'integer') . " " .
779  "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
780  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
781  } else {
782  $query = "INSERT INTO obj_members (blocked,obj_id,usr_id,notification,passed) " .
783  "VALUES ( " .
784  $ilDB->quote((int) $a_blocked, 'integer') . ", " .
785  $ilDB->quote($this->obj_id, 'integer') . ", " .
786  $ilDB->quote($a_usr_id, 'integer') . ", " .
787  $ilDB->quote(0, 'integer') . ", " .
788  $ilDB->quote(0, 'integer') .
789  ")";
790  }
791  $res = $ilDB->manipulate($query);
792  return true;
793  }
794 
795  // cognos-blu-patch: begin
803  public function updateContact($a_usr_id, $a_contact)
804  {
805  global $ilDB;
806 
807  $ilDB->manipulate(
808  'UPDATE obj_members SET ' .
809  'contact = ' . $ilDB->quote($a_contact, 'integer') . ' ' .
810  'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer') . ' ' .
811  'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer')
812  );
813 
814  $this->participants_status[$a_usr_id]['contact'] = $a_contact;
815  return true;
816  }
817 
822  public function getContacts()
823  {
824  $contacts = array();
825  foreach ((array) $this->participants_status as $usr_id => $status) {
826  if ($status['contact']) {
827  $contacts[] = $usr_id;
828  }
829  }
830  return $contacts;
831  }
832 
833 
834  // cognos-blu-patch: end
835 
844  public function updateNotification($a_usr_id, $a_notification)
845  {
846  global $ilDB;
847 
848  $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
849 
850  $query = "SELECT * FROM obj_members " .
851  "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
852  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
853  $res = $ilDB->query($query);
854  if ($res->numRows()) {
855  $query = "UPDATE obj_members SET " .
856  "notification = " . $ilDB->quote((int) $a_notification, 'integer') . " " .
857  "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
858  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
859  } else {
860  $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) " .
861  "VALUES ( " .
862  $ilDB->quote((int) $a_notification, 'integer') . ", " .
863  $ilDB->quote($this->obj_id, 'integer') . ", " .
864  $ilDB->quote($a_usr_id, 'integer') . ", " .
865  $ilDB->quote(0, 'integer') . ", " .
866  $ilDB->quote(0, 'integer') .
867  ")";
868  }
869  $res = $ilDB->manipulate($query);
870  return true;
871  }
872 
873 
874 
875 
884  public function add($a_usr_id, $a_role)
885  {
886  global $rbacadmin,$ilLog,$ilAppEventHandler;
887 
888  if ($this->isAssigned($a_usr_id)) {
889  return false;
890  }
891 
892  switch ($a_role) {
893  case IL_CRS_ADMIN:
894  $this->admins[] = $a_usr_id;
895  break;
896 
897  case IL_CRS_TUTOR:
898  $this->tutors[] = $a_usr_id;
899  break;
900 
901  case IL_CRS_MEMBER:
902  $this->members[] = $a_usr_id;
903  break;
904 
905  case IL_GRP_ADMIN:
906  $this->admins[] = $a_usr_id;
907  break;
908 
909  case IL_GRP_MEMBER:
910  $this->members[] = $a_usr_id;
911  break;
912 
913  case IL_SESS_MEMBER:
914  $this->members[] = $a_usr_id;
915  break;
916  }
917 
918  $this->participants[] = $a_usr_id;
919  $rbacadmin->assignUser($this->role_data[$a_role], $a_usr_id);
920 
921  // Delete subscription request
922  $this->deleteSubscriber($a_usr_id);
923 
924  include_once './Services/Membership/classes/class.ilWaitingList.php';
925  ilWaitingList::deleteUserEntry($a_usr_id, $this->obj_id);
926 
927  $ilLog->write(__METHOD__ . ': Raise new event: ' . $this->getComponent() . ' addParticipant');
928  $ilAppEventHandler->raise(
929  $this->getComponent(),
930  "addParticipant",
931  array(
932  'obj_id' => $this->obj_id,
933  'usr_id' => $a_usr_id,
934  'role_id' => $a_role)
935  );
936  return true;
937  }
938 
939 
947  public function deleteParticipants($a_user_ids)
948  {
949  foreach ($a_user_ids as $user_id) {
950  $this->delete($user_id);
951  }
952  return true;
953  }
954 
962  public function addDesktopItem($a_usr_id)
963  {
964  if (!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id, $this->type)) {
965  ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id, $this->type);
966  }
967  return true;
968  }
969 
977  public function dropDesktopItem($a_usr_id)
978  {
979  if (ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id, $this->type)) {
980  ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id, $this->type);
981  }
982 
983  return true;
984  }
985 
986 
987 
995  public function isNotificationEnabled($a_usr_id)
996  {
997  if (isset($this->participants_status[$a_usr_id])) {
998  return $this->participants_status[$a_usr_id]['notification'] ? true : false;
999  }
1000  return false;
1001  }
1002 
1003  // cognos-blu-patch: begin
1008  public function isContact($a_usr_id)
1009  {
1010  if (isset($this->participants_status[$a_usr_id])) {
1011  return (bool) $this->participants_status[$a_usr_id]['contact'];
1012  }
1013  return false;
1014  }
1015  // cognos-blu-patch: end
1016 
1017 
1022  public function getAutoGeneratedRoleId($a_role_type)
1023  {
1024  if (array_key_exists($a_role_type, $this->role_data)) {
1025  return $this->role_data[$a_role_type];
1026  }
1027 
1028  return 0;
1029  }
1030 
1031 
1039  protected function readParticipants()
1040  {
1041  global $rbacreview,$ilObjDataCache,$ilLog;
1042 
1043  $GLOBALS['rbacreview']->clearCaches();
1044  $this->roles = $rbacreview->getRolesOfRoleFolder($this->ref_id, false);
1045 
1046  $users = array();
1047  $this->participants = array();
1048  $this->members = $this->admins = $this->tutors = array();
1049 
1050  $additional_roles = [];
1051  $auto_generated_roles = [];
1052  foreach ($this->roles as $role_id) {
1053  $title = $ilObjDataCache->lookupTitle($role_id);
1054  switch (substr($title, 0, 8)) {
1055  case 'il_crs_m':
1056  $auto_generated_roles[$role_id] = IL_ROLE_POSITION_MEMBER;
1057  $this->role_data[IL_CRS_MEMBER] = $role_id;
1058  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id), $this->participants));
1059  $this->members = array_unique(array_merge($assigned, $this->members));
1060  $this->role_assignments[$role_id] = $assigned;
1061  break;
1062 
1063  case 'il_crs_a':
1064  $auto_generated_roles[$role_id] = IL_ROLE_POSITION_ADMIN;
1065  $this->role_data[IL_CRS_ADMIN] = $role_id;
1066  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id), $this->participants));
1067  $this->admins = $rbacreview->assignedUsers($role_id);
1068  $this->role_assignments[$role_id] = $assigned;
1069  break;
1070 
1071  case 'il_crs_t':
1072  $auto_generated_roles[$role_id] = IL_ROLE_POSITION_TUTOR;
1073  $this->role_data[IL_CRS_TUTOR] = $role_id;
1074  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id), $this->participants));
1075  $this->tutors = $rbacreview->assignedUsers($role_id);
1076  $this->role_assignments[$role_id] = $assigned;
1077  break;
1078 
1079  case 'il_grp_a':
1080  $auto_generated_roles[$role_id] = IL_ROLE_POSITION_ADMIN;
1081  $this->role_data[IL_GRP_ADMIN] = $role_id;
1082  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id), $this->participants));
1083  $this->admins = $rbacreview->assignedUsers($role_id);
1084  $this->role_assignments[$role_id] = $assigned;
1085  break;
1086 
1087  case 'il_grp_m':
1088  $auto_generated_roles[$role_id] = IL_ROLE_POSITION_MEMBER;
1089  $this->role_data[IL_GRP_MEMBER] = $role_id;
1090  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id), $this->participants));
1091  $this->members = $rbacreview->assignedUsers($role_id);
1092  $this->role_assignments[$role_id] = $assigned;
1093  break;
1094 
1095  case 'il_sess_':
1096  $this->role_data[IL_SESS_MEMBER] = $role_id;
1097  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id), $this->participants));
1098  $this->members = $rbacreview->assignedUsers($role_id);
1099  break;
1100 
1101 
1102  default:
1103  $additional_roles[$role_id] = $title;
1104  $this->participants = array_unique(array_merge($assigned = $rbacreview->assignedUsers($role_id), $this->participants));
1105  $this->members = array_unique(array_merge($assigned, $this->members));
1106  $this->role_assignments[$role_id] = $assigned;
1107  break;
1108  }
1109  }
1110  asort($auto_generated_roles);
1111  asort($additional_roles);
1112  $this->roles_sorted = $auto_generated_roles + $additional_roles;
1113  }
1114 
1122  protected function readParticipantsStatus()
1123  {
1124  global $ilDB;
1125 
1126  $query = "SELECT * FROM obj_members " .
1127  "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " ";
1128  $res = $ilDB->query($query);
1129  $this->participants_status = array();
1130  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1131  $this->participants_status[$row->usr_id]['blocked'] = $row->blocked;
1132  $this->participants_status[$row->usr_id]['notification'] = $row->notification;
1133  $this->participants_status[$row->usr_id]['passed'] = $row->passed;
1134  // cognos-blu-patch: begin
1135  $this->participants_status[$row->usr_id]['contact'] = $row->contact;
1136  // cognos-blu-patch: end
1137  }
1138  }
1139 
1147  public function isGroupingMember($a_usr_id, $a_field = '')
1148  {
1149  global $rbacreview,$ilObjDataCache,$ilDB;
1150 
1151  // Used for membership limitations -> check membership by given field
1152  if ($a_field) {
1153  include_once './Services/User/classes/class.ilObjUser.php';
1154 
1155  $tmp_user =&ilObjectFactory::getInstanceByObjId($a_usr_id);
1156  switch ($a_field) {
1157  case 'login':
1158  $and = "AND login = " . $ilDB->quote($tmp_user->getLogin(), 'text') . " ";
1159  break;
1160  case 'email':
1161  $and = "AND email = " . $ilDB->quote($tmp_user->getEmail(), 'text') . " ";
1162  break;
1163  case 'matriculation':
1164  $and = "AND matriculation = " . $ilDB->quote($tmp_user->getMatriculation(), 'text') . " ";
1165  break;
1166 
1167  default:
1168  $and = "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
1169  break;
1170  }
1171 
1172  if (!$this->getParticipants()) {
1173  return false;
1174  }
1175 
1176  $query = "SELECT * FROM usr_data ud " .
1177  "WHERE " . $ilDB->in('usr_id', $this->getParticipants(), false, 'integer') . " " .
1178  $and;
1179 
1180  $res = $ilDB->query($query);
1181  return $res->numRows() ? true : false;
1182  }
1183  }
1184 
1185  public static function lookupSubscribers($a_obj_id)
1186  {
1187  global $ilDB;
1188 
1189  $subscribers = array();
1190  $query = "SELECT usr_id FROM il_subscribers " .
1191  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
1192  "ORDER BY sub_time ";
1193 
1194  $res = $ilDB->query($query);
1195  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1196  $subscribers[] = $row->usr_id;
1197  }
1198  return $subscribers;
1199  }
1200 
1206  public function getSubscribers()
1207  {
1208  $this->readSubscribers();
1209 
1210  return $this->subscribers;
1211  }
1212 
1213 
1219  public function getCountSubscribers()
1220  {
1221  return count($this->getSubscribers());
1222  }
1223 
1229  public function getSubscriberData($a_usr_id)
1230  {
1231  return $this->readSubscriberData($a_usr_id);
1232  }
1233 
1234 
1235 
1241  public function assignSubscribers($a_usr_ids)
1242  {
1243  if (!is_array($a_usr_ids) or !count($a_usr_ids)) {
1244  return false;
1245  }
1246  foreach ($a_usr_ids as $id) {
1247  if (!$this->assignSubscriber($id)) {
1248  return false;
1249  }
1250  }
1251  return true;
1252  }
1253 
1259  public function assignSubscriber($a_usr_id)
1260  {
1261  global $ilErr;
1262 
1263  $ilErr->setMessage("");
1264  if (!$this->isSubscriber($a_usr_id)) {
1265  $ilErr->appendMessage($this->lng->txt("crs_user_notsubscribed"));
1266 
1267  return false;
1268  }
1269  if ($this->isAssigned($a_usr_id)) {
1270  $tmp_obj = ilObjectFactory::getInstanceByObjId($a_usr_id);
1271  $ilErr->appendMessage($tmp_obj->getLogin() . ": " . $this->lng->txt("crs_user_already_assigned"));
1272 
1273  return false;
1274  }
1275 
1276  if (!$tmp_obj =&ilObjectFactory::getInstanceByObjId($a_usr_id)) {
1277  $ilErr->appendMessage($this->lng->txt("crs_user_not_exists"));
1278 
1279  return false;
1280  }
1281 
1282  // TODO: must be group or course member role
1283  if ($this instanceof ilCourseParticipants) {
1284  $this->add($tmp_obj->getId(), IL_CRS_MEMBER);
1285  }
1286  if ($this instanceof ilGroupParticipants) {
1287  $this->add($tmp_obj->getId(), IL_GRP_MEMBER);
1288  }
1289  if ($this instanceof ilSessionParticipants) {
1290  $this->register($tmp_obj->getId());
1291  }
1292  $this->deleteSubscriber($a_usr_id);
1293  return true;
1294  }
1295 
1301  public function autoFillSubscribers()
1302  {
1303  $this->readSubscribers();
1304 
1305  $counter = 0;
1306  foreach ($this->subscribers as $subscriber) {
1307  if (!$this->assignSubscriber($subscriber)) {
1308  continue;
1309  } else {
1310  // TODO: notification
1311  #$this->sendNotification($this->NOTIFY_ACCEPT_SUBSCRIBER,$subscriber);
1312  }
1313  ++$counter;
1314  }
1315 
1316  return $counter;
1317  }
1318 
1324  public function addSubscriber($a_usr_id)
1325  {
1326  global $ilDB;
1327 
1328  $query = "INSERT INTO il_subscribers (usr_id,obj_id,subject,sub_time) " .
1329  " VALUES (" .
1330  $ilDB->quote($a_usr_id, 'integer') . "," .
1331  $ilDB->quote($this->obj_id, 'integer') . ", " .
1332  $ilDB->quote('', 'text') . ", " .
1333  $ilDB->quote(time(), 'integer') .
1334  ")";
1335  $res = $ilDB->manipulate($query);
1336 
1337  return true;
1338  }
1339 
1340 
1346  public function updateSubscriptionTime($a_usr_id, $a_subtime)
1347  {
1348  global $ilDB;
1349 
1350  $query = "UPDATE il_subscribers " .
1351  "SET sub_time = " . $ilDB->quote($a_subtime, 'integer') . " " .
1352  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
1353  "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " ";
1354  $res = $ilDB->manipulate($query);
1355 
1356  return true;
1357  }
1358 
1366  public function updateSubject($a_usr_id, $a_subject)
1367  {
1368  global $ilDB;
1369 
1370  $query = "UPDATE il_subscribers " .
1371  "SET subject = " . $ilDB->quote($a_subject, 'text') . " " .
1372  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
1373  "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " ";
1374  $res = $ilDB->manipulate($query);
1375  return true;
1376  }
1377 
1378 
1384  public function deleteSubscriber($a_usr_id)
1385  {
1386  global $ilDB;
1387 
1388  $query = "DELETE FROM il_subscribers " .
1389  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
1390  "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " ";
1391  $res = $ilDB->manipulate($query);
1392 
1393  return true;
1394  }
1395 
1396 
1402  public function deleteSubscribers($a_usr_ids)
1403  {
1404  global $ilErr,$ilDB;
1405 
1406  if (!is_array($a_usr_ids) or !count($a_usr_ids)) {
1407  $ilErr->setMessage('');
1408  $ilErr->appendMessage($this->lng->txt("no_usr_ids_given"));
1409 
1410  return false;
1411  }
1412  $query = "DELETE FROM il_subscribers " .
1413  "WHERE " . $ilDB->in('usr_id', (array) $a_usr_ids, false, 'integer') . " " .
1414  "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer');
1415  $res = $ilDB->query($query);
1416  return true;
1417  }
1418 
1419 
1425  public function isSubscriber($a_usr_id)
1426  {
1427  global $ilDB;
1428 
1429  $query = "SELECT * FROM il_subscribers " .
1430  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
1431  "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer') . "";
1432 
1433  $res = $ilDB->query($query);
1434  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1435  return true;
1436  }
1437  return false;
1438  }
1439 
1446  public static function _isSubscriber($a_obj_id, $a_usr_id)
1447  {
1448  global $ilDB;
1449 
1450  $query = "SELECT * FROM il_subscribers " .
1451  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
1452  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . "";
1453 
1454  $res = $ilDB->query($query);
1455  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1456  return true;
1457  }
1458  return false;
1459  }
1460 
1466  protected function readSubscribers()
1467  {
1468  global $ilDB;
1469 
1470  $this->subscribers = array();
1471 
1472  $query = "SELECT usr_id FROM il_subscribers " .
1473  "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
1474  "ORDER BY sub_time ";
1475 
1476  $res = $this->ilDB->query($query);
1477  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1478  // DELETE SUBSCRIPTION IF USER HAS BEEN DELETED
1479  if (!ilObjectFactory::getInstanceByObjId($row->usr_id, false)) {
1480  $this->deleteSubscriber($row->usr_id);
1481  }
1482  $this->subscribers[] = $row->usr_id;
1483  }
1484  return true;
1485  }
1486 
1492  protected function readSubscriberData($a_usr_id)
1493  {
1494  global $ilDB;
1495 
1496  $query = "SELECT * FROM il_subscribers " .
1497  "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
1498  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . "";
1499 
1500  $res = $this->ilDB->query($query);
1501  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1502  $data["time"] = $row->sub_time;
1503  $data["usr_id"] = $row->usr_id;
1504  $data['subject'] = $row->subject;
1505  }
1506  return $data ? $data : array();
1507  }
1508 
1509  public static function lookupSubscribersData($a_obj_id)
1510  {
1511  global $ilDB;
1512 
1513  $query = 'SELECT * FROM il_subscribers ' .
1514  'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
1515  $res = $ilDB->query($query);
1516 
1517  $data = array();
1518  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1519  $data[$row->usr_id]['time'] = $row->sub_time;
1520  $data[$row->usr_id]['usr_id'] = $row->usr_id;
1521  $data[$row->usr_id]['subject'] = $row->subject;
1522  }
1523  return $data;
1524  }
1525 
1533  public static function _getAllSupportContactsOfUser($a_usr_id, $a_type)
1534  {
1535  global $ilDB;
1536 
1537  // todo: join the two queries or alternatively reuse _getMembershipByType
1538  // for the first part
1539 
1540  // this will also dismiss local roles!
1541  $j2 = "JOIN object_data obd2 ON (ua.rol_id = obd2.obj_id) ";
1542  $a2 = "AND obd2.title LIKE 'il_" . $a_type . "_mem%' ";
1543 
1544  // #14290 - no role folder anymore
1545  $query = "SELECT DISTINCT obd.obj_id,obr.ref_id FROM rbac_ua ua " .
1546  "JOIN rbac_fa fa ON ua.rol_id = fa.rol_id " .
1547  "JOIN object_reference obr ON fa.parent = obr.ref_id " .
1548  "JOIN object_data obd ON obr.obj_id = obd.obj_id " .
1549  $j2 .
1550  "WHERE obd.type = " . $ilDB->quote($a_type, 'text') . " " .
1551  "AND fa.assign = 'y' " .
1552  "AND ua.usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
1553  $a2;
1554 
1555  $res = $ilDB->query($query);
1556  $obj_ids = array();
1557  while ($row = $ilDB->fetchObject($res)) {
1558  $obj_ids[] = $row->obj_id;
1559  }
1560 
1561  $set = $ilDB->query("SELECT obj_id, usr_id FROM obj_members " .
1562  " WHERE " . $ilDB->in("obj_id", $obj_ids, false, "integer") .
1563  " AND contact = " . $ilDB->quote(1, "integer"));
1564  $res = array();
1565  while ($rec = $ilDB->fetchAssoc($set)) {
1566  $res[] = $rec;
1567  }
1568 
1569  return $res;
1570  }
1571 
1577  public function setRoleOrderPosition($a_user_id)
1578  {
1579  $counter = 0;
1580  $sortable_assignments = '9999999999';
1581  foreach ($this->roles_sorted as $role_id => $trash) {
1582  if (in_array($a_user_id, (array) $this->role_assignments[$role_id])) {
1583  $sortable_assignments = substr_replace($sortable_assignments, '1', $counter, 1);
1584  }
1585  ++$counter;
1586  }
1587  return $sortable_assignments;
1588  }
1589 }
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.
__construct($a_component_name, $a_ref_id)
Singleton Constructor.
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.
Session participation handling.
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)
global $DIC
Definition: saml.php:7
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.
if(!array_key_exists('StateId', $_REQUEST)) $id
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 instance.
add($a_usr_id, $a_role)
Add user to object.
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.
static getInstance($a_ref_id)
Get instance by ref_id.
$counter
$a_type
Definition: workflow.php:92
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...
static lookupShowMembersEnabled(int $a_obj_id)
foreach($_POST as $key=> $value) $res
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.
$query
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.
$users
Definition: authpage.php:44
getRoles()
Get course roles.
static getInstance($a_ref_id)
Get instance.
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.
const IL_SESS_MEMBER
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.