ILIAS  release_8 Revision v8.24
class.ilBadgePersonalTableGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected ilObjUser $user;
27 protected array $filter = [];
28
29 public function __construct(
30 object $a_parent_obj,
31 string $a_parent_cmd,
32 int $a_user_id = null
33 ) {
34 global $DIC;
35
36 $this->lng = $DIC->language();
37 $this->user = $DIC->user();
38 $this->ctrl = $DIC->ctrl();
39 $this->tpl = $DIC["tpl"];
40 $lng = $DIC->language();
41 $ilUser = $DIC->user();
42 $ilCtrl = $DIC->ctrl();
43 $tpl = $DIC["tpl"];
44
45 if (!$a_user_id) {
46 $a_user_id = $ilUser->getId();
47 }
48
49 $this->setId("bdgprs");
50
51 parent::__construct($a_parent_obj, $a_parent_cmd);
52
53 $this->setTitle($lng->txt("badge_personal_badges"));
54
55 $this->addColumn("", "", 1);
56 $this->addColumn($lng->txt("title"), "title");
57 $this->addColumn($lng->txt("object"), "parent_title");
58 $this->addColumn($lng->txt("badge_issued_on"), "issued_on");
59 $this->addColumn($lng->txt("badge_in_profile"), "active");
60 $this->addColumn($lng->txt("actions"), "");
61
62 $this->setDefaultOrderField("title");
63
64 $this->setFormAction($ilCtrl->getFormAction($this->getParentObject()));
65 $this->setRowTemplate("tpl.personal_row.html", "Services/Badge");
66
67 $this->addMultiCommand("activate", $lng->txt("badge_add_to_profile"));
68 $this->addMultiCommand("deactivate", $lng->txt("badge_remove_from_profile"));
69 $this->setSelectAllCheckbox("badge_id");
70
71 $this->getItems($a_user_id);
72 }
73
74 public function initFilters(array $a_parents): void
75 {
77
78 $title = $this->addFilterItemByMetaType("title", self::FILTER_TEXT, false, $lng->txt("title"));
79 $this->filter["title"] = $title->getValue();
80
81 $lng->loadLanguageModule("search");
82
83 $options = array(
84 "" => $lng->txt("search_any"),
85 "-1" => $lng->txt("none")
86 );
87 asort($a_parents);
88
89 $obj = $this->addFilterItemByMetaType("obj", self::FILTER_SELECT, false, $lng->txt("object"));
90 $obj->setOptions($options + $a_parents);
91 $this->filter["obj"] = $obj->getValue();
92 }
93
94 public function getItems(int $a_user_id): void
95 {
97
98 $data = $filter_parent = array();
99
100 foreach (ilBadgeAssignment::getInstancesByUserId($a_user_id) as $ass) {
101 $badge = new ilBadge($ass->getBadgeId());
102
103 $parent = null;
104 if ($badge->getParentId()) {
105 $parent = $badge->getParentMeta();
106 if ($parent["type"] === "bdga") {
107 $parent = null;
108 } else {
109 $filter_parent[$parent["id"]] =
110 "(" . $lng->txt($parent["type"]) . ") " . $parent["title"];
111 }
112 }
113
114 $data[] = array(
115 "id" => $badge->getId(),
116 "title" => $badge->getTitle(),
117 "image" => $badge->getImagePath(),
118 "issued_on" => $ass->getTimestamp(),
119 "parent_title" => $parent ? $parent["title"] : null,
120 "parent" => $parent,
121 "active" => (bool) $ass->getPosition(),
122 "renderer" => new ilBadgeRenderer($ass)
123 );
124 }
125
126 $this->initFilters($filter_parent);
127
128 if ($this->filter["title"]) {
129 foreach ($data as $idx => $row) {
130 if (stripos($row["title"], $this->filter["title"]) === false) {
131 unset($data[$idx]);
132 }
133 }
134 }
135
136 if ($this->filter["obj"]) {
137 foreach ($data as $idx => $row) {
138 if ($this->filter["obj"] > 0) {
139 if (!$row["parent"] || $row["parent"]["id"] != $this->filter["obj"]) {
140 unset($data[$idx]);
141 }
142 } elseif ($row["parent"]) {
143 unset($data[$idx]);
144 }
145 }
146 }
147
148 $this->setData($data);
149 }
150
151 protected function fillRow(array $a_set): void
152 {
154 $ilCtrl = $this->ctrl;
155
156 $this->tpl->setVariable("VAL_ID", $a_set["id"]);
157 $this->tpl->setVariable("PREVIEW", $a_set["renderer"]->getHTML());
158 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
159 $this->tpl->setVariable("TXT_ISSUED_ON", ilDatePresentation::formatDate(new ilDateTime($a_set["issued_on"], IL_CAL_UNIX)));
160 $this->tpl->setVariable("TXT_ACTIVE", $a_set["active"]
161 ? $lng->txt("yes")
162 : $lng->txt("no"));
163
164 if ($a_set["parent"]) {
165 $this->tpl->setVariable("TXT_PARENT", $a_set["parent_title"]);
166 $this->tpl->setVariable(
167 "SRC_PARENT",
168 ilObject::_getIcon((int) $a_set["parent"]["id"], "big", $a_set["parent"]["type"])
169 );
170 }
171
172 $actions = new ilAdvancedSelectionListGUI();
173 $actions->setListTitle("");
174
175 $ilCtrl->setParameter($this->getParentObject(), "badge_id", $a_set["id"]);
176 $url = $ilCtrl->getLinkTarget($this->getParentObject(), $a_set["active"]
177 ? "deactivate"
178 : "activate");
179 $ilCtrl->setParameter($this->getParentObject(), "badge_id", "");
180 $actions->addItem($lng->txt(!$a_set["active"]
181 ? "badge_add_to_profile"
182 : "badge_remove_from_profile"), "", $url);
183
184
185 $this->tpl->setVariable("ACTIONS", $actions->getHTML());
186 }
187}
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstancesByUserId(int $a_user_id)
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, int $a_user_id=null)
fillRow(array $a_set)
Standard Version of Fill Row.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
loadLanguageModule(string $a_module)
Load language module.
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...
User class.
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getHTML()
Get HTML.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addMultiCommand(string $a_cmd, string $a_text)
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
setFormAction(string $a_form_action, bool $a_multipart=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)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
ilLanguage $lng
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$url