ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $type = 'crs';
14 
16  protected $data = array();
17 
19  protected $objParticipants = null;
20 
22  protected $lng;
23 
25  protected $dataCache;
26 
30  protected $roleSortWeightMap = [
31  'il_crs_a' => 10,
32  'il_grp_a' => 10,
33  'il_crs_t' => 9,
34  'il_crs_m' => 8,
35  'il_grp_m' => 8,
36  ];
37 
41  public function __construct($objParticipants)
42  {
43  global $DIC;
44 
45  $this->dataCache = $DIC['ilObjDataCache'];
46  $this->objParticipants = $objParticipants;
47  $this->type = $this->objParticipants->getType();
48  $this->lng = $DIC['lng'];
49 
50  $this->collectTableData();
51  }
52 
56  private function collectTableData()
57  {
58  $participants = $this->objParticipants->getParticipants();
59  foreach ($participants as $user_id) {
60  $name = ilObjUser::_lookupName($user_id);
61  $login = ilObjUser::_lookupLogin($user_id);
62 
63  $publicName = '';
64  if (in_array(ilObjUser::_lookupPref($user_id, 'public_profile'), array('g', 'y'))) {
65  $publicName = $name['lastname'] . ', ' . $name['firstname'];
66  }
67 
68  $this->data[$user_id]['user_id'] = $user_id;
69  $this->data[$user_id]['login'] = $login;
70  $this->data[$user_id]['name'] = $publicName;
71 
72  $assignedRoles = $this->objParticipants->getAssignedRoles($user_id);
73  $this->dataCache->preloadObjectCache($assignedRoles);
74  $roleTitles = [];
75  foreach ($assignedRoles as $roleId) {
76  $title = $this->dataCache->lookupTitle($roleId);
77  $roleTitles[] = $title;
78  }
79 
80  $roleTitles = $this->sortRoles($roleTitles);
81 
82  $that = $this;
83  $roleTitles = array_map(function ($roleTitle) use ($that) {
84  return $that->buildRoleTitle($roleTitle);
85  }, $roleTitles);
86 
87  $this->data[$user_id]['role'] = implode(', ', $roleTitles);
88  }
89  }
90 
95  private function sortRoles(array $roleTitles)
96  {
97  $that = $this;
98  usort($roleTitles, function ($a, $b) use ($that) {
99  $leftPrefixTitle = substr($a, 0, 8);
100  $rightPrefixTitle = substr($b, 0, 8);
101 
102  $leftRating = 0;
103  if (isset($that->roleSortWeightMap[$leftPrefixTitle])) {
104  $leftRating = $that->roleSortWeightMap[$leftPrefixTitle];
105  }
106 
107  $rightRating = 0;
108  if (isset($that->roleSortWeightMap[$rightPrefixTitle])) {
109  $rightRating = $that->roleSortWeightMap[$rightPrefixTitle];
110  }
111 
112  if ($leftRating > 0 || $rightRating > 0) {
113  if ($leftRating !== $rightRating) {
114  return $rightRating - $leftRating > 0 ? 1 : -1;
115  } else {
116  return 0;
117  }
118  }
119 
120  return strcmp($a, $b);
121  });
122 
123  return $roleTitles;
124  }
125 
130  private function buildRoleTitle($role)
131  {
132  require_once 'Services/AccessControl/classes/class.ilObjRole.php';
133  return \ilObjRole::_getTranslation($role);
134  }
135 
139  public function getData()
140  {
141  return $this->data;
142  }
143 }
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
Add some data
global $DIC
Definition: saml.php:7
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.
static _lookupPref($a_usr_id, $a_keyword)
Class ilMailMemberSearchDataProvider.