ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRepositoryUserResultTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
16  protected static $all_selectable_cols = NULL;
17  protected $admin_mode;
18 
22  function __construct($a_parent_obj, $a_parent_cmd, $a_admin_mode = false)
23  {
24  global $ilCtrl, $lng, $ilAccess, $lng, $ilUser;
25 
26  $this->admin_mode = (bool)$a_admin_mode;
27 
28  $this->setId("rep_search_".$ilUser->getId());
29  parent::__construct($a_parent_obj, $a_parent_cmd);
30 
31  $this->addColumn("", "", "1", true);
32 
33  $all_cols = $this->getSelectableColumns();
34  foreach($this->getSelectedColumns() as $col)
35  {
36  $this->addColumn($all_cols[$col]['txt'], $col);
37  }
38 
39  $this->setFormAction($ilCtrl->getFormAction($this->parent_obj));
40  $this->setRowTemplate("tpl.rep_search_usr_result_row.html", "Services/Search");
41  $this->setTitle($this->lng->txt('search_results'));
42  $this->setEnableTitle(true);
43  $this->setDefaultOrderField("login");
44  $this->setDefaultOrderDirection("asc");
45  $this->enable('select_all');
46  $this->setSelectAllCheckbox("user[]");
47  }
48 
56  public function getSelectableColumns()
57  {
58  global $rbacreview, $ilUser;
59 
60  if(!self::$all_selectable_cols)
61  {
62  include_once './Services/Search/classes/class.ilUserSearchOptions.php';
63  $columns = ilUserSearchOptions::getSelectableColumnInfo($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID));
64 
65  if($this->admin_mode)
66  {
67  // #11293
68  $columns['access_until'] = array('txt' => $this->lng->txt('access_until'));
69  $columns['last_login'] = array('txt' => $this->lng->txt('last_login'));
70  }
71 
72  self::$all_selectable_cols = $columns;
73  }
75  }
76 
81  public function initMultiCommands($a_commands)
82  {
83  if(!count($a_commands))
84  {
85  $this->addMultiCommand('addUser', $this->lng->txt('btn_add'));
86  return true;
87  }
88  $this->addMultiItemSelectionButton('member_type', $a_commands, 'addUser', $this->lng->txt('btn_add'));
89  return true;
90  }
91 
95  protected function fillRow($a_set)
96  {
97  global $ilCtrl, $lng;
98 
99  $this->tpl->setVariable("VAL_ID", $a_set["usr_id"]);
100  foreach($this->getSelectedColumns() as $field)
101  {
102  switch($field)
103  {
104  case 'gender':
105  $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
106  $this->tpl->setCurrentBlock('custom_fields');
107  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
108  $this->tpl->parseCurrentBlock();
109  break;
110 
111  case 'birthday':
112  $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'], IL_CAL_DATE)) : $this->lng->txt('no_date');
113  $this->tpl->setCurrentBlock('custom_fields');
114  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
115  $this->tpl->parseCurrentBlock();
116  break;
117 
118  case 'access_until':
119  $this->tpl->setCurrentBlock('custom_fields');
120  $this->tpl->setVariable('CUST_CLASS', ' '.$a_set['access_class']);
121  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
122  $this->tpl->parseCurrentBlock();
123  break;
124 
125  case 'last_login':
126  $a_set['last_login'] = $a_set['last_login'] ? ilDatePresentation::formatDate(new ilDateTime($a_set['last_login'], IL_CAL_DATETIME)) : $this->lng->txt('no_date');
127  $this->tpl->setCurrentBlock('custom_fields');
128  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
129  $this->tpl->parseCurrentBlock();
130  break;
131 
132  case 'login':
133  if($this->admin_mode)
134  {
135  $ilCtrl->setParameterByClass("ilobjusergui", "ref_id", "7");
136  $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", $a_set["usr_id"]);
137  $ilCtrl->setParameterByClass("ilobjusergui", "search", "1");
138  $link = $ilCtrl->getLinkTargetByClass(array("iladministrationgui", "ilobjusergui"), "view");
139  $a_set[$field] = "<a href=\"".$link."\">".$a_set[$field]."</a>";
140  }
141  // fallthrough
142 
143  default:
144  $this->tpl->setCurrentBlock('custom_fields');
145  $this->tpl->setVariable('VAL_CUST', (string) ($a_set[$field] ? $a_set[$field] : ''));
146  $this->tpl->parseCurrentBlock();
147  break;
148  }
149  }
150 
151  }
152 
158  public function parseUserIds($a_user_ids)
159  {
160  if(!$a_user_ids)
161  {
162  $this->setData(array());
163  return true;
164  }
165 
166  $additional_fields = $this->getSelectedColumns();
167 
168  $parse_access = false;
169  if(isset($additional_fields['access_until']))
170  {
171  $parse_access = true;
172  unset($additional_fields['access_until']);
173  }
174 
175  $udf_ids = $usr_data_fields = $odf_ids = array();
176  foreach($additional_fields as $field)
177  {
178  if(substr($field, 0, 3) == 'udf')
179  {
180  $udf_ids[] = substr($field,4);
181  continue;
182  }
183  $usr_data_fields[] = $field;
184  }
185  include_once './Services/User/classes/class.ilUserQuery.php';
186  $usr_data = ilUserQuery::getUserListData(
187  'login',
188  'ASC',
189  0,
190  999999,
191  '',
192  '',
193  null,
194  false,
195  false,
196  0,
197  0,
198  null,
199  $usr_data_fields,
200  $a_user_ids
201  );
202 
203  if($this->admin_mode && $parse_access)
204  {
205  // see ilUserTableGUI
206  $current_time = time();
207  foreach($usr_data['set'] as $k => $user)
208  {
209  if ($user['active'])
210  {
211  if ($user["time_limit_unlimited"])
212  {
213  $txt_access = $this->lng->txt("access_unlimited");
214  $usr_data["set"][$k]["access_class"] = "smallgreen";
215  }
216  elseif ($user["time_limit_until"] < $current_time)
217  {
218  $txt_access = $this->lng->txt("access_expired");
219  $usr_data["set"][$k]["access_class"] = "smallred";
220  }
221  else
222  {
223  $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"],IL_CAL_UNIX));
224  $usr_data["set"][$k]["access_class"] = "small";
225  }
226  }
227  else
228  {
229  $txt_access = $this->lng->txt("inactive");
230  $usr_data["set"][$k]["access_class"] = "smallred";
231  }
232  $usr_data["set"][$k]["access_until"] = $txt_access;
233  }
234  }
235 
236  // Custom user data fields
237  if($udf_ids)
238  {
239  include_once './Services/User/classes/class.ilUserDefinedData.php';
240  $data = ilUserDefinedData::lookupData($a_user_ids, $udf_ids);
241 
242  $users = array();
243  $counter = 0;
244  foreach($usr_data['set'] as $set)
245  {
246  $users[$counter] = $set;
247  foreach($udf_ids as $udf_field)
248  {
249  $users[$counter]['udf_'.$udf_field] = $data[$set['usr_id']][$udf_field];
250  }
251  ++$counter;
252  }
253  }
254  else
255  {
256  $users = $usr_data['set'];
257  }
258  $this->setData($users);
259  }
260 
261 }
262 ?>