ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4include_once("./Services/Table/classes/class.ilTable2GUI.php");
5
16{
17
21 public function __construct($a_parent_obj, $a_parent_cmd)
22 {
23 global $DIC;
24
25 $ilCtrl = $DIC->ctrl();
26 $lng = $DIC->language();
27 $access = $DIC->access();
28
29 $this->setId("registration_code");
30
31 parent::__construct($a_parent_obj, $a_parent_cmd);
32
33 $this->addColumn("", "", "1", true);
34 foreach ($this->getSelectedColumns() as $c => $caption) {
35 if ($c == "role_local" || $c == "alimit") {
36 $c = "";
37 }
38 $this->addColumn($this->lng->txt($caption), $c);
39 }
40
41 $this->setExternalSorting(true);
42 $this->setExternalSegmentation(true);
43 $this->setEnableHeader(true);
44 $this->setFormAction($ilCtrl->getFormAction($this->parent_obj, "listCodes"));
45 $this->setRowTemplate("tpl.code_list_row.html", "Services/Registration");
46 $this->setEnableTitle(true);
47 $this->initFilter();
48 $this->setFilterCommand("applyCodesFilter");
49 $this->setResetCommand("resetCodesFilter");
50 $this->setDefaultOrderField("generated"); // #11341
51 $this->setDefaultOrderDirection("desc");
52
53 $this->setSelectAllCheckbox("id[]");
54 $this->setTopCommands(true);
55
56 if($access->checkAccess("write", '', $a_parent_obj->ref_id)) {
57 $this->addMultiCommand("deleteConfirmation", $lng->txt("delete"));
58 }
59
60 $this->addCommandButton("exportCodes", $lng->txt("registration_codes_export"));
61
62 $this->getItems();
63 }
64
68 public function getItems()
69 {
70 global $DIC;
71
72 $rbacreview = $DIC['rbacreview'];
73 $ilObjDataCache = $DIC['ilObjDataCache'];
74
76
77 include_once("./Services/Registration/classes/class.ilRegistrationCode.php");
78
79 // #12737
80 if (!in_array($this->getOrderField(), array_keys($this->getSelectedColumns()))) {
81 $this->setOrderField($this->getDefaultOrderField());
82 }
83
89 $this->filter["code"],
90 $this->filter["role"],
91 $this->filter["generated"],
92 $this->filter["alimit"]
93 );
94
95 if (count($codes_data["set"]) == 0 && $this->getOffset() > 0) {
96 $this->resetOffset();
102 $this->filter["code"],
103 $this->filter["role"],
104 $this->filter["generated"],
105 $this->filter["alimit"]
106 );
107 }
108
109 include_once './Services/AccessControl/classes/class.ilObjRole.php';
110 $options = array();
111 foreach ($rbacreview->getGlobalRoles() as $role_id) {
112 if (!in_array($role_id, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID))) {
113 $role_map[$role_id] = $ilObjDataCache->lookupTitle($role_id);
114 }
115 }
116
117 $result = array();
118 foreach ($codes_data["set"] as $k => $code) {
119 $result[$k]["code"] = $code["code"];
120 $result[$k]["code_id"] = $code["code_id"];
121
122 $result[$k]["generated"] = ilDatePresentation::formatDate(new ilDateTime($code["generated"], IL_CAL_UNIX));
123
124 if ($code["used"]) {
125 $result[$k]["used"] = ilDatePresentation::formatDate(new ilDateTime($code["used"], IL_CAL_UNIX));
126 }
127
128 if ($code["role"]) {
129 $result[$k]["role"] = $this->role_map[$code["role"]];
130 }
131
132 if ($code["role_local"]) {
133 $local = array();
134 foreach (explode(";", $code["role_local"]) as $role_id) {
135 $role = ilObject::_lookupTitle($role_id);
136 if ($role) {
137 $local[] = $role;
138 }
139 }
140 if (sizeof($local)) {
141 sort($local);
142 $result[$k]["role_local"] = implode("<br />", $local);
143 }
144 }
145
146 if ($code["alimit"]) {
147 switch ($code["alimit"]) {
148 case "unlimited":
149 $result[$k]["alimit"] = $this->lng->txt("reg_access_limitation_none");
150 break;
151
152 case "absolute":
153 $result[$k]["alimit"] = $this->lng->txt("reg_access_limitation_mode_absolute_target") .
154 ": " . ilDatePresentation::formatDate(new ilDate($code["alimitdt"], IL_CAL_DATE));
155 break;
156
157 case "relative":
158 $limit_caption = array();
159 $limit = unserialize($code["alimitdt"]);
160 if ((int) $limit["d"]) {
161 $limit_caption[] = (int) $limit["d"] . " " . $this->lng->txt("days");
162 }
163 if ((int) $limit["m"]) {
164 $limit_caption[] = (int) $limit["m"] . " " . $this->lng->txt("months");
165 }
166 if ((int) $limit["y"]) {
167 $limit_caption[] = (int) $limit["y"] . " " . $this->lng->txt("years");
168 }
169 if (sizeof($limit_caption)) {
170 $result[$k]["alimit"] = $this->lng->txt("reg_access_limitation_mode_relative_target") .
171 ": " . implode(", ", $limit_caption);
172 }
173 break;
174 }
175 }
176 }
177
178 $this->setMaxCount($codes_data["cnt"]);
179 $this->setData($result);
180 }
181
182
186 public function initFilter()
187 {
188 global $DIC;
189
190 $lng = $DIC['lng'];
191 $rbacreview = $DIC['rbacreview'];
192 $ilUser = $DIC['ilUser'];
193 $ilObjDataCache = $DIC['ilObjDataCache'];
194
195 include_once("./Services/Registration/classes/class.ilRegistrationCode.php");
196
197 // code
198 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
199 $ti = new ilTextInputGUI($lng->txt("registration_code"), "query");
200 $ti->setMaxLength(ilRegistrationCode::CODE_LENGTH);
201 $ti->setSize(20);
202 $ti->setSubmitFormOnEnter(true);
203 $this->addFilterItem($ti);
204 $ti->readFromSession();
205 $this->filter["code"] = $ti->getValue();
206
207 // role
208
209 $this->role_map = array();
210 foreach ($rbacreview->getGlobalRoles() as $role_id) {
211 if (!in_array($role_id, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID))) {
212 $this->role_map[$role_id] = $ilObjDataCache->lookupTitle($role_id);
213 }
214 }
215
216 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
217 include_once './Services/AccessControl/classes/class.ilObjRole.php';
218 $options = array("" => $this->lng->txt("registration_roles_all")) +
219 $this->role_map;
220 $si = new ilSelectInputGUI($this->lng->txt("role"), "role");
221 $si->setOptions($options);
222 $this->addFilterItem($si);
223 $si->readFromSession();
224 $this->filter["role"] = $si->getValue();
225
226 // access limitation
227 $options = array("" => $this->lng->txt("registration_codes_access_limitation_all"),
228 "unlimited" => $this->lng->txt("reg_access_limitation_none"),
229 "absolute" => $this->lng->txt("reg_access_limitation_mode_absolute"),
230 "relative" => $this->lng->txt("reg_access_limitation_mode_relative"));
231 $si = new ilSelectInputGUI($this->lng->txt("reg_access_limitations"), "alimit");
232 $si->setOptions($options);
233 $this->addFilterItem($si);
234 $si->readFromSession();
235 $this->filter["alimit"] = $si->getValue();
236
237 // generated
238 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
239 $options = array("" => $this->lng->txt("registration_generated_all"));
240 foreach ((array) ilRegistrationCode::getGenerationDates() as $date) {
241 $options[$date] = ilDatePresentation::formatDate(new ilDateTime($date, IL_CAL_UNIX));
242 }
243 $si = new ilSelectInputGUI($this->lng->txt("registration_generated"), "generated");
244 $si->setOptions($options);
245 $this->addFilterItem($si);
246 $si->readFromSession();
247 $this->filter["generated"] = $si->getValue();
248 }
249
250 public function getSelectedColumns()
251 {
252 return array("code" => "registration_code",
253 "role" => "registration_codes_roles",
254 "role_local" => "registration_codes_roles_local",
255 "alimit" => "reg_access_limitations",
256 "generated" => "registration_generated",
257 "used" => "registration_used");
258 }
259
260 protected function fillRow($code)
261 {
262 $this->tpl->setVariable("ID", $code["code_id"]);
263 foreach (array_keys($this->getSelectedColumns()) as $c) {
264 $this->tpl->setVariable("VAL_" . strtoupper($c), $code[$c]);
265 }
266 }
267}
$result
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
Class for single dates.
static _lookupTitle($a_id)
lookup object title
static getCodesData($order_field, $order_direction, $offset, $limit, $filter_code, $filter_role, $filter_generated, $filter_access_limitation)
TableGUI class for registration codes.
__construct($a_parent_obj, $a_parent_cmd)
Constructor.
fillRow($code)
Standard Version of Fill Row.
This class represents a selection list property in a property form.
Class ilTable2GUI.
setTopCommands($a_val)
Set top commands (display command buttons on top of table, too)
setEnableHeader($a_enableheader)
Set Enable Header.
setExternalSorting($a_val)
Set external sorting.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
setData($a_data)
set table data @access public
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
setEnableTitle($a_enabletitle)
Set Enable Title.
getLimit()
Get limit.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
resetOffset($a_in_determination=false)
Reset offset.
addMultiCommand($a_cmd, $a_text)
Add Command button.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
getOffset()
Get offset.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setOrderField($a_order_field)
set order column
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setFilterCommand($a_val, $a_caption=null)
Set filter command.
getDefaultOrderField()
Get Default order field.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
getOrderDirection()
Get order direction.
setMaxCount($a_max_count)
set max.
This class represents a text property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$c
Definition: cli.php:37
const SYSTEM_ROLE_ID
Definition: constants.php:27
const ANONYMOUS_ROLE_ID
Definition: constants.php:26
filter()
Definition: filter.php:2
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc