ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
185 public function getOptionArray()
186 {
187 $options = array();
188
189 foreach($this->byActiveId as $activeId => $usrData)
190 {
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'), $usrData['firstname'], $usrData['lastname']
203 );
204 }
205
206 public function getAnonymousActiveIds()
207 {
208 $anonymousActiveIds = array();
209
210 foreach($this->byActiveId as $activeId => $active)
211 {
212 if($active['user_id'] == ANONYMOUS_USER_ID)
213 {
214 $anonymousActiveIds[] = $activeId;
215 }
216 }
217
218 return $anonymousActiveIds;
219 }
220
221 public function getUserDataByActiveId($activeId)
222 {
223 if( isset($this->byActiveId[$activeId]) )
224 {
225 return $this->byActiveId[$activeId];
226 }
227
228 return null;
229 }
230}
Database Wrapper.
Definition: class.ilDB.php:29
language handling
__construct(ilDB $db, ilLanguage $lng)
if(!is_array($argv)) $options