ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
53  public function __construct(ilDB $db, ilLanguage $lng)
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  $query = "
70  SELECT ta.active_id,
71  ta.user_fi user_id,
72  ta.anonymous_id,
73  ud.firstname,
74  ud.lastname
75  FROM tst_active ta
76  LEFT JOIN usr_data ud
77  ON ud.usr_id = ta.user_fi
78  WHERE test_fi = %s
79  AND {$this->getConditionalExpression()}
80  ";
81 
82  $res = $this->db->queryF($query, array('integer'), array($testId));
83 
84  while( $row = $this->db->fetchAssoc($res) )
85  {
86  $this->byActiveId[ $row['active_id'] ] = $row;
87 
88  if( $row['user_id'] == ANONYMOUS_USER_ID )
89  {
90  $this->byAnonymousId[ $row['anonymous_id'] ] = $row;
91  }
92  else
93  {
94  $this->byUserId[ $row['user_id'] ] = $row;
95  }
96  }
97 
98  $this->setActiveIds(array_keys($this->byActiveId));
99  $this->setUserIds(array_keys($this->byUserId));
100  $this->setAnonymousIds(array_keys($this->byAnonymousId));
101  }
102 
103  public function getConditionalExpression()
104  {
105  $conditions = array();
106 
107  if( count($this->getActiveIds()) )
108  {
109  $conditions[] = $this->db->in('active_id', $this->getActiveIds(), false, 'integer');
110  }
111 
112  if( count($this->getUserIds()) )
113  {
114  $conditions[] = $this->db->in('user_fi', $this->getUserIds(), false, 'integer');
115  }
116 
117  if( count($this->getAnonymousIds()) )
118  {
119  $conditions[] = $this->db->in('anonymous_id', $this->getAnonymousIds(), false, 'integer');
120  }
121 
122  if( count($conditions) )
123  {
124  return '('.implode(' OR ', $conditions).')';
125  }
126 
127  return '1 = 1';
128  }
129 
130  public function setActiveIds($activeIds)
131  {
132  $this->activeIds = $activeIds;
133  }
134 
135  public function getActiveIds()
136  {
137  return $this->activeIds;
138  }
139 
140  public function setUserIds($userIds)
141  {
142  $this->userIds = $userIds;
143  }
144 
145  public function getUserIds()
146  {
147  return $this->userIds;
148  }
149 
151  {
152  $this->anonymousIds = $anonymousIds;
153  }
154 
155  public function getAnonymousIds()
156  {
157  return $this->anonymousIds;
158  }
159 
160  public function getUserIdByActiveId($activeId)
161  {
162  return $this->byActiveId[$activeId]['user_id'];
163  }
164 
165  public function getConcatedFullnameByActiveId($activeId)
166  {
167  return "{$this->byActiveId[$activeId]['firstname']} {$this->byActiveId[$activeId]['lastname']}";
168  }
169 
170  public function getFormatedFullnameByActiveId($activeId)
171  {
172  return $this->buildFormatedFullname($this->byActiveId[$activeId]);
173  }
174 
175  public function getOptionArray()
176  {
177  $options = array();
178 
179  foreach($this->byActiveId as $activeId => $usrData)
180  {
181  $options[$activeId] = $this->buildFormatedFullname($usrData);
182  }
183 
184  asort($options);
185 
186  return $options;
187  }
188 
189  private function buildFormatedFullname($usrData)
190  {
191  return sprintf(
192  $this->lng->txt('tst_participant_fullname_pattern'), $usrData['firstname'], $usrData['lastname']
193  );
194  }
195 }