ILIAS  Release_4_2_x_branch Revision 61807
 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  $result = array();
99  foreach ($codes_data["set"] as $k => $code)
100  {
101  $result[$k]["registration_generated"] = ilDatePresentation::formatDate(new ilDateTime($code["generated"],IL_CAL_UNIX));
102 
103  if($code["used"])
104  {
105  $result[$k]["registration_used"] = ilDatePresentation::formatDate(new ilDateTime($code["used"],IL_CAL_UNIX));
106  }
107  else
108  {
109  $result[$k]["registration_used"] = "";
110  }
111 
112  if($code["role"])
113  {
114  $result[$k]["role"] = $this->role_map[$code["role"]];
115  }
116  $result[$k]["registration_code"] = $code["code"];
117  $result[$k]["code_id"] = $code["code_id"];
118  }
119 
120  $this->setMaxCount($codes_data["cnt"]);
121  $this->setData($result);
122  }
123 
124 
128  function initFilter()
129  {
130  global $lng, $rbacreview, $ilUser, $ilObjDataCache;
131 
132  include_once("./Services/Registration/classes/class.ilRegistrationCode.php");
133 
134  // code
135  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
136  $ti = new ilTextInputGUI($lng->txt("registration_code"), "query");
138  $ti->setSize(20);
139  $ti->setSubmitFormOnEnter(true);
140  $this->addFilterItem($ti);
141  $ti->readFromSession();
142  $this->filter["code"] = $ti->getValue();
143 
144  // role
145 
146  $this->role_map = array();
147  foreach($rbacreview->getGlobalRoles() as $role_id)
148  {
149  if(!in_array($role_id, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID)))
150  {
151  $this->role_map[$role_id] = $ilObjDataCache->lookupTitle($role_id);
152  }
153  }
154 
155  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
156  include_once './Services/AccessControl/classes/class.ilObjRole.php';
157  $options = array("" => $this->lng->txt("registration_roles_all"))+
158  $this->role_map;
159  $si = new ilSelectInputGUI($this->lng->txt("role"), "role");
160  $si->setOptions($options);
161  $this->addFilterItem($si);
162  $si->readFromSession();
163  $this->filter["role"] = $si->getValue();
164 
165  // generated
166  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
167  $options = array("" => $this->lng->txt("registration_generated_all"));
168  foreach((array)ilRegistrationCode::getGenerationDates() as $date)
169  {
170  $options[$date] = ilDatePresentation::formatDate(new ilDateTime($date,IL_CAL_UNIX));
171  }
172  $si = new ilSelectInputGUI($this->lng->txt("registration_generated"), "generated");
173  $si->setOptions($options);
174  $this->addFilterItem($si);
175  $si->readFromSession();
176  $this->filter["generated"] = $si->getValue();
177  }
178 
179  public function getSelectedColumns()
180  {
181  return array("registration_code", "role", "registration_generated", "registration_used");
182  }
183 
187  protected function fillRow($code)
188  {
189  $this->tpl->setVariable("ID", $code["code_id"]);
190  foreach ($this->getSelectedColumns() as $c)
191  {
192  $this->tpl->setVariable("VAL_".strtoupper($c), $code[$c]);
193  }
194  }
195 
196 }
197 ?>