ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilTestParticipantData.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
12 {
16  protected $db;
17 
21  protected $lng;
22 
26  private $activeIds;
27 
31  private $userIds;
32 
36  private $anonymousIds;
37 
41  private $byActiveId;
42 
46  private $byUserId;
47 
51  private $byAnonymousId;
52 
54  {
55  $this->db = $db;
56  $this->lng = $lng;
57 
58  $this->activeIds = array();
59  $this->userIds = array();
60  $this->anonymousIds = array();
61 
62  $this->byActiveId = array();
63  $this->byUserId = array();
64  $this->byAnonymousId = array();
65  }
66 
67  public function load($testId)
68  {
69  $this->byActiveId = array();
70  $this->byUserId = array();
71 
72  $query = "
73  SELECT ta.active_id,
74  ta.user_fi user_id,
75  ta.anonymous_id,
76  ud.firstname,
77  ud.lastname,
78  ud.login,
79  ud.matriculation
80  FROM tst_active ta
81  LEFT JOIN usr_data ud
82  ON ud.usr_id = ta.user_fi
83  WHERE test_fi = %s
84  AND {$this->getConditionalExpression()}
85  ";
86 
87  $res = $this->db->queryF($query, array('integer'), array($testId));
88 
89  while ($row = $this->db->fetchAssoc($res)) {
90  $this->byActiveId[ $row['active_id'] ] = $row;
91 
92  if ($row['user_id'] == ANONYMOUS_USER_ID) {
93  $this->byAnonymousId[ $row['anonymous_id'] ] = $row;
94  } else {
95  $this->byUserId[ $row['user_id'] ] = $row;
96  }
97  }
98 
99  $this->setActiveIds(array_keys($this->byActiveId));
100  $this->setUserIds(array_keys($this->byUserId));
101  $this->setAnonymousIds(array_keys($this->byAnonymousId));
102  }
103 
104  public function getConditionalExpression()
105  {
106  $conditions = array();
107 
108  if (count($this->getActiveIds())) {
109  $conditions[] = $this->db->in('active_id', $this->getActiveIds(), false, 'integer');
110  }
111 
112  if (count($this->getUserIds())) {
113  $conditions[] = $this->db->in('user_fi', $this->getUserIds(), false, 'integer');
114  }
115 
116  if (count($this->getAnonymousIds())) {
117  $conditions[] = $this->db->in('anonymous_id', $this->getAnonymousIds(), false, 'integer');
118  }
119 
120  if (count($conditions)) {
121  return '(' . implode(' OR ', $conditions) . ')';
122  }
123 
124  return '1 = 1';
125  }
126 
127  public function setActiveIds($activeIds)
128  {
129  $this->activeIds = $activeIds;
130  }
131 
132  public function getActiveIds()
133  {
134  return $this->activeIds;
135  }
136 
137  public function setUserIds($userIds)
138  {
139  $this->userIds = $userIds;
140  }
141 
142  public function getUserIds()
143  {
144  return $this->userIds;
145  }
146 
148  {
149  $this->anonymousIds = $anonymousIds;
150  }
151 
152  public function getAnonymousIds()
153  {
154  return $this->anonymousIds;
155  }
156 
157  public function getUserIdByActiveId($activeId)
158  {
159  return $this->byActiveId[$activeId]['user_id'];
160  }
161 
162  public function getActiveIdByUserId($userId)
163  {
164  return $this->byUserId[$userId]['active_id'];
165  }
166 
167  public function getConcatedFullnameByActiveId($activeId)
168  {
169  return "{$this->byActiveId[$activeId]['firstname']} {$this->byActiveId[$activeId]['lastname']}";
170  }
171 
172  public function getFormatedFullnameByActiveId($activeId)
173  {
174  return $this->buildFormatedFullname($this->byActiveId[$activeId]);
175  }
176 
177  public function getFileSystemCompliantFullnameByActiveId($activeId)
178  {
179  $fullname = str_replace(' ', '', $this->byActiveId[$activeId]['lastname']);
180  $fullname .= '_' . str_replace(' ', '', $this->byActiveId[$activeId]['firstname']);
181  $fullname .= '_' . $this->byActiveId[$activeId]['login'];
182 
183  return ilUtil::getASCIIFilename($fullname);
184  }
185 
186  public function getOptionArray()
187  {
188  $options = array();
189 
190  foreach ($this->byActiveId as $activeId => $usrData) {
191  $options[$activeId] = $this->buildFormatedFullname($usrData);
192  }
193 
194  asort($options);
195 
196  return $options;
197  }
198 
199  private function buildFormatedFullname($usrData)
200  {
201  return sprintf(
202  $this->lng->txt('tst_participant_fullname_pattern'),
203  $usrData['firstname'],
204  $usrData['lastname']
205  );
206  }
207 
208  public function getAnonymousActiveIds()
209  {
210  $anonymousActiveIds = array();
211 
212  foreach ($this->byActiveId as $activeId => $active) {
213  if ($active['user_id'] == ANONYMOUS_USER_ID) {
214  $anonymousActiveIds[] = $activeId;
215  }
216  }
217 
218  return $anonymousActiveIds;
219  }
220 
221  public function getUserDataByActiveId($activeId)
222  {
223  if (isset($this->byActiveId[$activeId])) {
224  return $this->byActiveId[$activeId];
225  }
226 
227  return null;
228  }
229 }
__construct(ilDBInterface $db, ilLanguage $lng)
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
Interface ilDBInterface.
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
language handling
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20