ILIAS  release_4-3 Revision
 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)
31  {
32  $this->addColumn($this->lng->txt($c), $c);
33  }
34 
35  $this->setExternalSorting(true);
36  $this->setExternalSegmentation(true);
37  $this->setEnableHeader(true);
38  $this->setFormAction($ilCtrl->getFormAction($this->parent_obj, "listCodes"));
39  $this->setRowTemplate("tpl.code_list_row.html", "Services/Registration");
40  $this->setEnableTitle(true);
41  $this->initFilter();
42  $this->setFilterCommand("applyCodesFilter");
43  $this->setResetCommand("resetCodesFilter");
44  $this->setDefaultOrderField("registration_generated");
45  $this->setDefaultOrderDirection("desc");
46 
47  $this->setSelectAllCheckbox("id[]");
48  $this->setTopCommands(true);
49  $this->addMultiCommand("deleteConfirmation", $lng->txt("delete"));
50 
51  $this->addCommandButton("exportCodes", $lng->txt("registration_codes_export"));
52 
53  $this->getItems();
54  }
55 
59  function getItems()
60  {
61  global $lng, $rbacreview, $ilObjDataCache;
62 
63  $this->determineOffsetAndOrder();
64 
65  include_once("./Services/Registration/classes/class.ilRegistrationCode.php");
66 
67  $order_map = array(
68  "registration_code" => "code",
69  "role" => "role",
70  "registration_generated" => "generated",
71  "registration_used" => "used"
72  );
73 
75  ilUtil::stripSlashes($order_map[$this->getOrderField()]),
79  $this->filter["code"],
80  $this->filter["role"],
81  $this->filter["generated"]
82  );
83 
84  if (count($codes_data["set"]) == 0 && $this->getOffset() > 0)
85  {
86  $this->resetOffset();
92  $this->filter["code"],
93  $this->filter["role"],
94  $this->filter["generated"]
95  );
96  }
97 
98  include_once './Services/AccessControl/classes/class.ilObjRole.php';
99  $options = array();
100  foreach($rbacreview->getGlobalRoles() as $role_id)
101  {
102  if(!in_array($role_id, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID)))
103  {
104  $role_map[$role_id] = $ilObjDataCache->lookupTitle($role_id);
105  }
106  }
107 
108  $result = array();
109  foreach ($codes_data["set"] as $k => $code)
110  {
111  $result[$k]["registration_generated"] = ilDatePresentation::formatDate(new ilDateTime($code["generated"],IL_CAL_UNIX));
112 
113  if($code["used"])
114  {
115  $result[$k]["registration_used"] = ilDatePresentation::formatDate(new ilDateTime($code["used"],IL_CAL_UNIX));
116  }
117  else
118  {
119  $result[$k]["registration_used"] = "";
120  }
121 
122  if($code["role"])
123  {
124  $result[$k]["role"] = $this->role_map[$code["role"]];
125  }
126  $result[$k]["registration_code"] = $code["code"];
127  $result[$k]["code_id"] = $code["code_id"];
128  }
129 
130  $this->setMaxCount($codes_data["cnt"]);
131  $this->setData($result);
132  }
133 
134 
138  function initFilter()
139  {
140  global $lng, $rbacreview, $ilUser, $ilObjDataCache;
141 
142  include_once("./Services/Registration/classes/class.ilRegistrationCode.php");
143 
144  // code
145  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
146  $ti = new ilTextInputGUI($lng->txt("registration_code"), "query");
148  $ti->setSize(20);
149  $ti->setSubmitFormOnEnter(true);
150  $this->addFilterItem($ti);
151  $ti->readFromSession();
152  $this->filter["code"] = $ti->getValue();
153 
154  // role
155 
156  $this->role_map = array();
157  foreach($rbacreview->getGlobalRoles() as $role_id)
158  {
159  if(!in_array($role_id, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID)))
160  {
161  $this->role_map[$role_id] = $ilObjDataCache->lookupTitle($role_id);
162  }
163  }
164 
165  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
166  include_once './Services/AccessControl/classes/class.ilObjRole.php';
167  $options = array("" => $this->lng->txt("registration_roles_all"))+
168  $this->role_map;
169  $si = new ilSelectInputGUI($this->lng->txt("role"), "role");
170  $si->setOptions($options);
171  $this->addFilterItem($si);
172  $si->readFromSession();
173  $this->filter["role"] = $si->getValue();
174 
175  // generated
176  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
177  $options = array("" => $this->lng->txt("registration_generated_all"));
178  foreach((array)ilRegistrationCode::getGenerationDates() as $date)
179  {
180  $options[$date] = ilDatePresentation::formatDate(new ilDateTime($date,IL_CAL_UNIX));
181  }
182  $si = new ilSelectInputGUI($this->lng->txt("registration_generated"), "generated");
183  $si->setOptions($options);
184  $this->addFilterItem($si);
185  $si->readFromSession();
186  $this->filter["generated"] = $si->getValue();
187  }
188 
189  public function getSelectedColumns()
190  {
191  return array("registration_code", "role", "registration_generated", "registration_used");
192  }
193 
197  protected function fillRow($code)
198  {
199  $this->tpl->setVariable("ID", $code["code_id"]);
200  foreach ($this->getSelectedColumns() as $c)
201  {
202  $this->tpl->setVariable("VAL_".strtoupper($c), $code[$c]);
203  }
204  }
205 
206 }
207 ?>