ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
37
41 private $byActiveId;
42
46 private $byUserId;
47
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 {
91 $this->byActiveId[ $row['active_id'] ] = $row;
92
93 if( $row['user_id'] == ANONYMOUS_USER_ID )
94 {
95 $this->byAnonymousId[ $row['anonymous_id'] ] = $row;
96 }
97 else
98 {
99 $this->byUserId[ $row['user_id'] ] = $row;
100 }
101 }
102
103 $this->setActiveIds(array_keys($this->byActiveId));
104 $this->setUserIds(array_keys($this->byUserId));
105 $this->setAnonymousIds(array_keys($this->byAnonymousId));
106 }
107
108 public function getConditionalExpression()
109 {
110 $conditions = array();
111
112 if( count($this->getActiveIds()) )
113 {
114 $conditions[] = $this->db->in('active_id', $this->getActiveIds(), false, 'integer');
115 }
116
117 if( count($this->getUserIds()) )
118 {
119 $conditions[] = $this->db->in('user_fi', $this->getUserIds(), false, 'integer');
120 }
121
122 if( count($this->getAnonymousIds()) )
123 {
124 $conditions[] = $this->db->in('anonymous_id', $this->getAnonymousIds(), false, 'integer');
125 }
126
127 if( count($conditions) )
128 {
129 return '('.implode(' OR ', $conditions).')';
130 }
131
132 return '1 = 1';
133 }
134
135 public function setActiveIds($activeIds)
136 {
137 $this->activeIds = $activeIds;
138 }
139
140 public function getActiveIds()
141 {
142 return $this->activeIds;
143 }
144
145 public function setUserIds($userIds)
146 {
147 $this->userIds = $userIds;
148 }
149
150 public function getUserIds()
151 {
152 return $this->userIds;
153 }
154
156 {
157 $this->anonymousIds = $anonymousIds;
158 }
159
160 public function getAnonymousIds()
161 {
162 return $this->anonymousIds;
163 }
164
165 public function getUserIdByActiveId($activeId)
166 {
167 return $this->byActiveId[$activeId]['user_id'];
168 }
169
170 public function getActiveIdByUserId($userId)
171 {
172 return $this->byUserId[$userId]['active_id'];
173 }
174
175 public function getConcatedFullnameByActiveId($activeId)
176 {
177 return "{$this->byActiveId[$activeId]['firstname']} {$this->byActiveId[$activeId]['lastname']}";
178 }
179
180 public function getFormatedFullnameByActiveId($activeId)
181 {
182 return $this->buildFormatedFullname($this->byActiveId[$activeId]);
183 }
184
186 {
187 $fullname = str_replace(' ', '', $this->byActiveId[$activeId]['lastname']);
188 $fullname .= '_'.str_replace(' ', '', $this->byActiveId[$activeId]['firstname']);
189 $fullname .= '_'.$this->byActiveId[$activeId]['login'];
190
191 return ilUtil::getASCIIFilename($fullname);
192 }
193
194 public function getOptionArray()
195 {
196 $options = array();
197
198 foreach($this->byActiveId as $activeId => $usrData)
199 {
200 $options[$activeId] = $this->buildFormatedFullname($usrData);
201 }
202
203 asort($options);
204
205 return $options;
206 }
207
208 private function buildFormatedFullname($usrData)
209 {
210 return sprintf(
211 $this->lng->txt('tst_participant_fullname_pattern'), $usrData['firstname'], $usrData['lastname']
212 );
213 }
214
215 public function getAnonymousActiveIds()
216 {
217 $anonymousActiveIds = array();
218
219 foreach($this->byActiveId as $activeId => $active)
220 {
221 if($active['user_id'] == ANONYMOUS_USER_ID)
222 {
223 $anonymousActiveIds[] = $activeId;
224 }
225 }
226
227 return $anonymousActiveIds;
228 }
229
230 public function getUserDataByActiveId($activeId)
231 {
232 if( isset($this->byActiveId[$activeId]) )
233 {
234 return $this->byActiveId[$activeId];
235 }
236
237 return null;
238 }
239}
Database Wrapper.
Definition: class.ilDB.php:29
language handling
__construct(ilDB $db, ilLanguage $lng)
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
if(!is_array($argv)) $options