ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAccountCodesTableGUI.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 {
20  function __construct($a_parent_obj, $a_parent_cmd)
21  {
22  global $ilCtrl, $lng;
23 
24  $this->setId("user_account_code");
25 
26  parent::__construct($a_parent_obj, $a_parent_cmd);
27 
28  $this->addColumn("", "", "1", true);
29  $this->addColumn($lng->txt("user_account_code"), "code");
30  $this->addColumn($lng->txt("user_account_code_valid_until"), "valid_until");
31  $this->addColumn($lng->txt("user_account_code_generated"), "generated");
32  $this->addColumn($lng->txt("user_account_code_used"), "used");
33 
34  $this->setExternalSorting(true);
35  $this->setExternalSegmentation(true);
36  $this->setEnableHeader(true);
37  $this->setFormAction($ilCtrl->getFormAction($this->parent_obj, "listCodes"));
38  $this->setRowTemplate("tpl.code_list_row.html", "Services/User");
39  $this->setEnableTitle(true);
40  $this->initFilter();
41  $this->setFilterCommand("applyCodesFilter");
42  $this->setResetCommand("resetCodesFilter");
43  $this->setDefaultOrderField("generated");
44  $this->setDefaultOrderDirection("desc");
45 
46  $this->setSelectAllCheckbox("id[]");
47  $this->setTopCommands(true);
48  $this->addMultiCommand("deleteConfirmation", $lng->txt("delete"));
49 
50  $this->addCommandButton("exportCodes", $lng->txt("user_account_codes_export"));
51 
52  $this->getItems();
53  }
54 
58  function getItems()
59  {
60  global $lng, $rbacreview, $ilObjDataCache;
61 
62  $this->determineOffsetAndOrder();
63 
64  include_once("./Services/User/classes/class.ilAccountCode.php");
65 
66  $codes_data = ilAccountCode::getCodesData(
71  $this->filter["code"],
72  $this->filter["valid_until"],
73  $this->filter["generated"]
74  );
75 
76  if (count($codes_data["set"]) == 0 && $this->getOffset() > 0)
77  {
78  $this->resetOffset();
79  $codes_data = ilAccountCode::getCodesData(
84  $this->filter["code"],
85  $this->filter["valid_until"],
86  $this->filter["generated"]
87  );
88  }
89 
90  $result = array();
91  foreach ($codes_data["set"] as $k => $code)
92  {
93  $result[$k]["generated"] = ilDatePresentation::formatDate(new ilDateTime($code["generated"],IL_CAL_UNIX));
94 
95  if($code["used"])
96  {
97  $result[$k]["used"] = ilDatePresentation::formatDate(new ilDateTime($code["used"],IL_CAL_UNIX));
98  }
99  else
100  {
101  $result[$k]["used"] = "";
102  }
103 
104  if($code["valid_until"] === "0")
105  {
106  $valid = $lng->txt("user_account_code_valid_until_unlimited");
107  }
108  else if(is_numeric($code["valid_until"]))
109  {
110  $valid = $code["valid_until"]." ".($code["valid_until"] == 1 ? $lng->txt("day") : $lng->txt("days"));
111  }
112  else
113  {
114  $valid = ilDatePresentation::formatDate(new ilDate($code["valid_until"], IL_CAL_DATE));
115  }
116  $result[$k]["valid_until"] = $valid;
117 
118  $result[$k]["code"] = $code["code"];
119  $result[$k]["code_id"] = $code["code_id"];
120  }
121 
122  $this->setMaxCount($codes_data["cnt"]);
123  $this->setData($result);
124  }
125 
126 
130  function initFilter()
131  {
132  global $lng, $rbacreview, $ilUser;
133 
134  include_once("./Services/User/classes/class.ilAccountCode.php");
135 
136  // code
137  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
138  $ti = new ilTextInputGUI($lng->txt("user_account_code"), "query");
140  $ti->setSize(20);
141  $ti->setSubmitFormOnEnter(true);
142  $this->addFilterItem($ti);
143  $ti->readFromSession();
144  $this->filter["code"] = $ti->getValue();
145 
146  // generated
147  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
148  $options = array("" => $lng->txt("user_account_code_generated_all"));
149  foreach((array)ilAccountCode::getGenerationDates() as $date)
150  {
151  $options[$date] = ilDatePresentation::formatDate(new ilDateTime($date,IL_CAL_UNIX));
152  }
153  $si = new ilSelectInputGUI($lng->txt("user_account_code_generated"), "generated");
154  $si->setOptions($options);
155  $this->addFilterItem($si);
156  $si->readFromSession();
157  $this->filter["generated"] = $si->getValue();
158  }
159 
163  protected function fillRow($code)
164  {
165  $this->tpl->setVariable("ID", $code["code_id"]);
166  $this->tpl->setVariable("VAL_CODE", $code["code"]);
167  $this->tpl->setVariable("VAL_VALID_UNTIL", $code["valid_until"]);
168  $this->tpl->setVariable("VAL_GENERATED", $code["generated"]);
169  $this->tpl->setVariable("VAL_USED", $code["used"]);
170  }
171 }
172 
173 ?>