ILIAS  release_8 Revision v8.24
class.ilAccountCodesTableGUI.php
Go to the documentation of this file.
1<?php
2
24{
28 public array $filter;
29
30 public function __construct(
31 object $a_parent_obj,
32 string $a_parent_cmd
33 ) {
34 global $DIC;
35
36 $ilCtrl = $DIC['ilCtrl'];
37 $lng = $DIC['lng'];
38
39 $this->setId("user_account_code");
40
41 parent::__construct($a_parent_obj, $a_parent_cmd);
42
43 $this->addColumn("", "", "1", true);
44 $this->addColumn($lng->txt("user_account_code"), "code");
45 $this->addColumn($lng->txt("user_account_code_valid_until"), "valid_until");
46 $this->addColumn($lng->txt("user_account_code_generated"), "generated");
47 $this->addColumn($lng->txt("user_account_code_used"), "used");
48
49 $this->setExternalSorting(true);
50 $this->setExternalSegmentation(true);
51 $this->setEnableHeader(true);
52 $this->setFormAction($ilCtrl->getFormAction($this->parent_obj, "listCodes"));
53 $this->setRowTemplate("tpl.code_list_row.html", "Services/User");
54 $this->setEnableTitle(true);
55 $this->initFilter();
56 $this->setFilterCommand("applyCodesFilter");
57 $this->setResetCommand("resetCodesFilter");
58 $this->setDefaultOrderField("generated");
59 $this->setDefaultOrderDirection("desc");
60
61 $this->setSelectAllCheckbox("id[]");
62 $this->setTopCommands(true);
63 $this->addMultiCommand("deleteConfirmation", $lng->txt("delete"));
64
66 $button->setCaption("user_account_codes_export");
67 $button->setCommand("exportCodes");
68 $button->setOmitPreventDoubleSubmission(true);
69 $this->addCommandButtonInstance($button);
70
71 $this->getItems();
72 }
73
74 public function getItems(): void
75 {
76 global $DIC;
77
78 $lng = $DIC['lng'];
79
81
82 $codes_data = ilAccountCode::getCodesData(
87 $this->filter["code"],
88 $this->filter["valid_until"],
89 $this->filter["generated"]
90 );
91
92 if (count($codes_data["set"]) == 0 && $this->getOffset() > 0) {
93 $this->resetOffset();
94 $codes_data = ilAccountCode::getCodesData(
99 $this->filter["code"],
100 $this->filter["valid_until"],
101 $this->filter["generated"]
102 );
103 }
104
105 $result = array();
106 foreach ($codes_data["set"] as $k => $code) {
107 $result[$k]["generated"] = ilDatePresentation::formatDate(new ilDateTime($code["generated"], IL_CAL_UNIX));
108
109 if ($code["used"]) {
110 $result[$k]["used"] = ilDatePresentation::formatDate(new ilDateTime($code["used"], IL_CAL_UNIX));
111 } else {
112 $result[$k]["used"] = "";
113 }
114
115 if ($code["valid_until"] === "0") {
116 $valid = $lng->txt("user_account_code_valid_until_unlimited");
117 } elseif (is_numeric($code["valid_until"])) {
118 $valid = $code["valid_until"] . " " . ($code["valid_until"] == 1 ? $lng->txt("day") : $lng->txt("days"));
119 } else {
120 $valid = ilDatePresentation::formatDate(new ilDate($code["valid_until"], IL_CAL_DATE));
121 }
122 $result[$k]["valid_until"] = $valid;
123
124 $result[$k]["code"] = $code["code"];
125 $result[$k]["code_id"] = $code["code_id"];
126 }
127
128 $this->setMaxCount($codes_data["cnt"]);
129 $this->setData($result);
130 }
131
132 public function initFilter(): void
133 {
134 global $DIC;
135
136 $lng = $DIC['lng'];
137
138 // code
139 $ti = new ilTextInputGUI($lng->txt("user_account_code"), "query");
140 $ti->setMaxLength(ilAccountCode::CODE_LENGTH);
141 $ti->setSize(20);
142 $ti->setSubmitFormOnEnter(true);
143 $this->addFilterItem($ti);
144 $ti->readFromSession();
145 $this->filter["code"] = $ti->getValue();
146
147 // generated
148 $options = array("" => $lng->txt("user_account_code_generated_all"));
149 foreach (ilAccountCode::getGenerationDates() as $date) {
150 $options[$date] = ilDatePresentation::formatDate(new ilDateTime($date, IL_CAL_UNIX));
151 }
152 $si = new ilSelectInputGUI($lng->txt("user_account_code_generated"), "generated");
153 $si->setOptions($options);
154 $this->addFilterItem($si);
155 $si->readFromSession();
156 $this->filter["generated"] = $si->getValue();
157 }
158
162 protected function fillRow(array $a_set): void
163 {
164 $this->tpl->setVariable("ID", $a_set["code_id"]);
165 $this->tpl->setVariable("VAL_CODE", $a_set["code"]);
166 $this->tpl->setVariable("VAL_VALID_UNTIL", $a_set["valid_until"]);
167 $this->tpl->setVariable("VAL_GENERATED", $a_set["generated"]);
168 $this->tpl->setVariable("VAL_USED", $a_set["used"]);
169 }
170}
const IL_CAL_DATE
const IL_CAL_UNIX
static getCodesData(string $order_field, string $order_direction, int $offset, int $limit, string $filter_code, string $filter_valid_until, string $filter_generated)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(object $a_parent_obj, string $a_parent_cmd)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
Class for single dates.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFilterCommand(string $a_val, string $a_caption="")
determineOffsetAndOrder(bool $a_omit_offset=false)
setExternalSegmentation(bool $a_val)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setEnableTitle(bool $a_enabletitle)
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
resetOffset(bool $a_in_determination=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
addCommandButtonInstance(ilButtonBase $a_button)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setTopCommands(bool $a_val)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setResetCommand(string $a_val, string $a_caption="")
setData(array $a_data)
Set table data.
ilLanguage $lng
setMaxCount(int $a_max_count)
set max.
This class represents a text property in a property form.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$valid
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc