ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMailMemberSearchDataProvider.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
13  protected $access;
14 
16  protected $ref_id;
17 
19  protected $type = 'crs';
20 
22  protected $data = [];
23 
25  protected $objParticipants = null;
26 
28  protected $dataCache;
29 
31  protected $roleSortWeightMap = [
32  'il_crs_a' => 10,
33  'il_grp_a' => 10,
34  'il_crs_t' => 9,
35  'il_crs_m' => 8,
36  'il_grp_m' => 8,
37  ];
38 
40  protected $lng;
41 
46  public function __construct($objParticipants, $a_ref_id)
47  {
48  global $DIC;
49 
50  $this->dataCache = $DIC['ilObjDataCache'];
51  $this->access = $DIC->access();
52  $this->objParticipants = $objParticipants;
53  $this->type = $this->objParticipants->getType();
54  $this->lng = $DIC['lng'];
55 
56  $this->ref_id = $a_ref_id;
57 
58  $this->collectTableData();
59  }
60 
61  private function collectTableData()
62  {
63  $participants = $this->objParticipants->getParticipants();
64  if ($this->type === 'crs' || $this->type === 'grp') {
65  $participants = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
66  'read',
67  'manage_members',
68  $this->ref_id,
69  $participants
70  );
71  }
72 
73  $preloadedRoleIds = [];
74  foreach ($participants as $user_id) {
75  $user = ilObjectFactory::getInstanceByObjId($user_id, false);
76  if (!$user || !($user instanceof ilObjUser)) {
77  continue;
78  }
79 
80  if (!$user->getActive()) {
81  continue;
82  }
83 
84  $login = $user->getLogin();
85 
86  $publicName = '';
87  if (in_array($user->getPref('public_profile'), ['g', 'y'])) {
88  $publicName = $user->getLastname() . ', ' . $user->getFirstname();
89  }
90 
91  $this->data[$user_id]['user_id'] = $user_id;
92  $this->data[$user_id]['login'] = $login;
93  $this->data[$user_id]['name'] = $publicName;
94 
95  $assignedRoles = $this->objParticipants->getAssignedRoles($user_id);
96  $rolesToPreload = array_diff($assignedRoles, $preloadedRoleIds);
97  $this->dataCache->preloadObjectCache($rolesToPreload);
98 
99  $roleTitles = [];
100  foreach ($assignedRoles as $roleId) {
101  $preloadedRoleIds[$roleId] = $roleId;
102  $title = $this->dataCache->lookupTitle($roleId);
103  $roleTitles[] = $title;
104  }
105 
106  $roleTitles = $this->sortRoles($roleTitles);
107 
108  $roleTitles = array_map(function (string $roleTitle) : string {
109  return $this->buildRoleTitle($roleTitle);
110  }, $roleTitles);
111 
112  $this->data[$user_id]['role'] = implode(', ', $roleTitles);
113  }
114  }
115 
120  private function sortRoles(array $roleTitles) : array
121  {
122  usort($roleTitles, function (string $a, string $b) : int {
123  $leftPrefixTitle = substr($a, 0, 8);
124  $rightPrefixTitle = substr($b, 0, 8);
125 
126  $leftRating = $this->roleSortWeightMap[$leftPrefixTitle] ?? 0;
127  $rightRating = $this->roleSortWeightMap[$rightPrefixTitle] ?? 0;
128 
129  if ($leftRating > 0 || $rightRating > 0) {
130  if ($leftRating !== $rightRating) {
131  return $rightRating - $leftRating > 0 ? 1 : -1;
132  }
133 
134  return 0;
135  }
136 
137  return strcmp($a, $b);
138  });
139 
140  return $roleTitles;
141  }
142 
143  private function buildRoleTitle(string $role) : string
144  {
145  return ilObjRole::_getTranslation($role);
146  }
147 
148  public function getData() : array
149  {
150  return $this->data;
151  }
152 }
global $DIC
Definition: saml.php:7
$user
Definition: migrateto20.php:57
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _getTranslation($a_role_title)
$this data['403_header']
$login
Definition: cron.php:13
Class ilMailMemberSearchDataProvider.