ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRegistrationCodesTableGUI.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 
16 {
17 
21  function __construct($a_parent_obj, $a_parent_cmd)
22  {
23  global $ilCtrl, $lng;
24 
25  $this->setId("registration_code");
26 
27  parent::__construct($a_parent_obj, $a_parent_cmd);
28 
29  $this->addColumn("", "", "1", true);
30  foreach ($this->getSelectedColumns() as $c => $caption)
31  {
32  if($c == "role_local" || $c == "alimit")
33  {
34  $c = "";
35  }
36  $this->addColumn($this->lng->txt($caption), $c);
37  }
38 
39  $this->setExternalSorting(true);
40  $this->setExternalSegmentation(true);
41  $this->setEnableHeader(true);
42  $this->setFormAction($ilCtrl->getFormAction($this->parent_obj, "listCodes"));
43  $this->setRowTemplate("tpl.code_list_row.html", "Services/Registration");
44  $this->setEnableTitle(true);
45  $this->initFilter();
46  $this->setFilterCommand("applyCodesFilter");
47  $this->setResetCommand("resetCodesFilter");
48  $this->setDefaultOrderField("generated"); // #11341
49  $this->setDefaultOrderDirection("desc");
50 
51  $this->setSelectAllCheckbox("id[]");
52  $this->setTopCommands(true);
53  $this->addMultiCommand("deleteConfirmation", $lng->txt("delete"));
54 
55  $this->addCommandButton("exportCodes", $lng->txt("registration_codes_export"));
56 
57  $this->getItems();
58  }
59 
63  function getItems()
64  {
65  global $rbacreview, $ilObjDataCache;
66 
67  $this->determineOffsetAndOrder();
68 
69  include_once("./Services/Registration/classes/class.ilRegistrationCode.php");
70 
71  // #12737
72  if(!in_array($this->getOrderField(), array_keys($this->getSelectedColumns())))
73  {
74  $this->setOrderField($this->getDefaultOrderField());
75  }
76 
82  $this->filter["code"],
83  $this->filter["role"],
84  $this->filter["generated"],
85  $this->filter["alimit"]
86  );
87 
88  if (count($codes_data["set"]) == 0 && $this->getOffset() > 0)
89  {
90  $this->resetOffset();
96  $this->filter["code"],
97  $this->filter["role"],
98  $this->filter["generated"],
99  $this->filter["alimit"]
100  );
101  }
102 
103  include_once './Services/AccessControl/classes/class.ilObjRole.php';
104  $options = array();
105  foreach($rbacreview->getGlobalRoles() as $role_id)
106  {
107  if(!in_array($role_id, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID)))
108  {
109  $role_map[$role_id] = $ilObjDataCache->lookupTitle($role_id);
110  }
111  }
112 
113  $result = array();
114  foreach ($codes_data["set"] as $k => $code)
115  {
116  $result[$k]["code"] = $code["code"];
117  $result[$k]["code_id"] = $code["code_id"];
118 
119  $result[$k]["generated"] = ilDatePresentation::formatDate(new ilDateTime($code["generated"],IL_CAL_UNIX));
120 
121  if($code["used"])
122  {
123  $result[$k]["used"] = ilDatePresentation::formatDate(new ilDateTime($code["used"],IL_CAL_UNIX));
124  }
125 
126  if($code["role"])
127  {
128  $result[$k]["role"] = $this->role_map[$code["role"]];
129  }
130 
131  if($code["role_local"])
132  {
133  $local = array();
134  foreach(explode(";", $code["role_local"]) as $role_id)
135  {
136  $role = ilObject::_lookupTitle($role_id);
137  if($role)
138  {
139  $local[] = $role;
140  }
141  }
142  if(sizeof($local))
143  {
144  sort($local);
145  $result[$k]["role_local"] = implode("<br />", $local);
146  }
147  }
148 
149  if($code["alimit"])
150  {
151  switch($code["alimit"])
152  {
153  case "unlimited":
154  $result[$k]["alimit"] = $this->lng->txt("reg_access_limitation_none");
155  break;
156 
157  case "absolute":
158  $result[$k]["alimit"] = $this->lng->txt("reg_access_limitation_mode_absolute_target").
159  ": ".ilDatePresentation::formatDate(new ilDate($code["alimitdt"], IL_CAL_DATE));
160  break;
161 
162  case "relative":
163  $limit_caption = array();
164  $limit = unserialize($code["alimitdt"]);
165  if((int)$limit["d"])
166  {
167  $limit_caption[] = (int)$limit["d"]." ".$this->lng->txt("days");
168  }
169  if((int)$limit["m"])
170  {
171  $limit_caption[] = (int)$limit["m"]." ".$this->lng->txt("months");
172  }
173  if((int)$limit["y"])
174  {
175  $limit_caption[] = (int)$limit["y"]." ".$this->lng->txt("years");
176  }
177  if(sizeof($limit_caption))
178  {
179  $result[$k]["alimit"] = $this->lng->txt("reg_access_limitation_mode_relative_target").
180  ": ".implode(", ", $limit_caption);
181  }
182  break;
183  }
184  }
185  }
186 
187  $this->setMaxCount($codes_data["cnt"]);
188  $this->setData($result);
189  }
190 
191 
195  function initFilter()
196  {
197  global $lng, $rbacreview, $ilUser, $ilObjDataCache;
198 
199  include_once("./Services/Registration/classes/class.ilRegistrationCode.php");
200 
201  // code
202  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
203  $ti = new ilTextInputGUI($lng->txt("registration_code"), "query");
205  $ti->setSize(20);
206  $ti->setSubmitFormOnEnter(true);
207  $this->addFilterItem($ti);
208  $ti->readFromSession();
209  $this->filter["code"] = $ti->getValue();
210 
211  // role
212 
213  $this->role_map = array();
214  foreach($rbacreview->getGlobalRoles() as $role_id)
215  {
216  if(!in_array($role_id, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID)))
217  {
218  $this->role_map[$role_id] = $ilObjDataCache->lookupTitle($role_id);
219  }
220  }
221 
222  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
223  include_once './Services/AccessControl/classes/class.ilObjRole.php';
224  $options = array("" => $this->lng->txt("registration_roles_all"))+
225  $this->role_map;
226  $si = new ilSelectInputGUI($this->lng->txt("role"), "role");
227  $si->setOptions($options);
228  $this->addFilterItem($si);
229  $si->readFromSession();
230  $this->filter["role"] = $si->getValue();
231 
232  // access limitation
233  $options = array("" => $this->lng->txt("registration_codes_access_limitation_all"),
234  "unlimited" => $this->lng->txt("reg_access_limitation_none"),
235  "absolute" => $this->lng->txt("reg_access_limitation_mode_absolute"),
236  "relative" => $this->lng->txt("reg_access_limitation_mode_relative"));
237  $si = new ilSelectInputGUI($this->lng->txt("reg_access_limitations"), "alimit");
238  $si->setOptions($options);
239  $this->addFilterItem($si);
240  $si->readFromSession();
241  $this->filter["alimit"] = $si->getValue();
242 
243  // generated
244  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
245  $options = array("" => $this->lng->txt("registration_generated_all"));
246  foreach((array)ilRegistrationCode::getGenerationDates() as $date)
247  {
249  }
250  $si = new ilSelectInputGUI($this->lng->txt("registration_generated"), "generated");
251  $si->setOptions($options);
252  $this->addFilterItem($si);
253  $si->readFromSession();
254  $this->filter["generated"] = $si->getValue();
255  }
256 
257  public function getSelectedColumns()
258  {
259  return array("code" => "registration_code",
260  "role" => "registration_codes_roles",
261  "role_local" => "registration_codes_roles_local",
262  "alimit" => "reg_access_limitations",
263  "generated" => "registration_generated",
264  "used" => "registration_used");
265  }
266 
267  protected function fillRow($code)
268  {
269  $this->tpl->setVariable("ID", $code["code_id"]);
270  foreach (array_keys($this->getSelectedColumns()) as $c)
271  {
272  $this->tpl->setVariable("VAL_".strtoupper($c), $code[$c]);
273  }
274  }
275 
276 }
277 ?>