ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilBadgePersonalTableGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
15 protected $user;
16
20 protected $ctrl;
21
25 protected $tpl;
26
27 public function __construct($a_parent_obj, $a_parent_cmd, $a_user_id = null)
28 {
29 global $DIC;
30
31 $this->lng = $DIC->language();
32 $this->user = $DIC->user();
33 $this->ctrl = $DIC->ctrl();
34 $this->tpl = $DIC["tpl"];
35 $lng = $DIC->language();
36 $ilUser = $DIC->user();
37 $ilCtrl = $DIC->ctrl();
38 $tpl = $DIC["tpl"];
39
40 if (!$a_user_id) {
41 $a_user_id = $ilUser->getId();
42 }
43
44 $this->setId("bdgprs");
45
46 parent::__construct($a_parent_obj, $a_parent_cmd);
47
48 $this->setTitle($lng->txt("badge_personal_badges"));
49
50 $this->addColumn("", "", 1);
51 $this->addColumn($lng->txt("title"), "title");
52 $this->addColumn($lng->txt("object"), "parent_title");
53 $this->addColumn($lng->txt("badge_issued_on"), "issued_on");
54 $this->addColumn($lng->txt("badge_in_profile"), "active");
55 $this->addColumn($lng->txt("actions"), "");
56
57 if (ilBadgeHandler::getInstance()->isObiActive()) {
58
59
60 // :TODO: use local copy instead?
61 $tpl->addJavascript("https://backpack.openbadges.org/issuer.js", false);
62
63 $tpl->addJavascript("Services/Badge/js/ilBadge.js");
64 $tpl->addOnLoadCode('il.Badge.setUrl("' .
65 $ilCtrl->getLinkTarget($this->getParentObject(), "addtoBackpack", "", true, false) .
66 '")');
67 }
68
69 $this->setDefaultOrderField("title");
70
71 $this->setFormAction($ilCtrl->getFormAction($this->getParentObject()));
72 $this->setRowTemplate("tpl.personal_row.html", "Services/Badge");
73
74 $this->addMultiCommand("activate", $lng->txt("badge_add_to_profile"));
75 $this->addMultiCommand("deactivate", $lng->txt("badge_remove_from_profile"));
76 if (ilBadgeHandler::getInstance()->isObiActive()) {
77 $this->addMultiCommand("addToBackpackMulti", $lng->txt("badge_add_to_backpack"));
78 }
79 $this->setSelectAllCheckbox("badge_id");
80
81 $this->getItems($a_user_id);
82 }
83
84 public function initFilters(array $a_parents)
85 {
87
88 $title = $this->addFilterItemByMetaType("title", self::FILTER_TEXT, false, $lng->txt("title"));
89 $this->filter["title"] = $title->getValue();
90
91 $lng->loadLanguageModule("search");
92
93 $options = array(
94 "" => $lng->txt("search_any"),
95 "-1" => $lng->txt("none")
96 );
97 asort($a_parents);
98
99 $obj = $this->addFilterItemByMetaType("obj", self::FILTER_SELECT, false, $lng->txt("object"));
100 $obj->setOptions($options + $a_parents);
101 $this->filter["obj"] = $obj->getValue();
102 }
103
104 public function getItems($a_user_id)
105 {
107
108 $data = $filter_parent = array();
109
110 foreach (ilBadgeAssignment::getInstancesByUserId($a_user_id) as $ass) {
111 $badge = new ilBadge($ass->getBadgeId());
112
113 $parent = null;
114 if ($badge->getParentId()) {
115 $parent = $badge->getParentMeta();
116 if ($parent["type"] == "bdga") {
117 $parent = null;
118 } else {
119 $filter_parent[$parent["id"]] =
120 "(" . $lng->txt($parent["type"]) . ") " . $parent["title"];
121 }
122 }
123
124 $data[] = array(
125 "id" => $badge->getId(),
126 "title" => $badge->getTitle(),
127 "image" => $badge->getImagePath(),
128 "issued_on" => $ass->getTimestamp(),
129 "parent_title" => $parent ? $parent["title"] : null,
130 "parent" => $parent,
131 "active" => (bool) $ass->getPosition(),
132 "renderer" => new ilBadgeRenderer($ass)
133 );
134 }
135
136 $this->initFilters($filter_parent);
137
138 if ($this->filter["title"]) {
139 foreach ($data as $idx => $row) {
140 if (!stristr($row["title"], $this->filter["title"])) {
141 unset($data[$idx]);
142 }
143 }
144 }
145
146 if ($this->filter["obj"]) {
147 foreach ($data as $idx => $row) {
148 if ($this->filter["obj"] > 0) {
149 if (!$row["parent"] || $row["parent"]["id"] != $this->filter["obj"]) {
150 unset($data[$idx]);
151 }
152 } else {
153 if ($row["parent"]) {
154 unset($data[$idx]);
155 }
156 }
157 }
158 }
159
160 $this->setData($data);
161 }
162
163 public function fillRow($a_set)
164 {
167
168 $this->tpl->setVariable("VAL_ID", $a_set["id"]);
169 $this->tpl->setVariable("PREVIEW", $a_set["renderer"]->getHTML());
170 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
171 $this->tpl->setVariable("TXT_ISSUED_ON", ilDatePresentation::formatDate(new ilDateTime($a_set["issued_on"], IL_CAL_UNIX)));
172 $this->tpl->setVariable("TXT_ACTIVE", $a_set["active"]
173 ? $lng->txt("yes")
174 : $lng->txt("no"));
175
176 if ($a_set["parent"]) {
177 $this->tpl->setVariable("TXT_PARENT", $a_set["parent_title"]);
178 $this->tpl->setVariable(
179 "SRC_PARENT",
180 ilObject::_getIcon($a_set["parent"]["id"], "big", $a_set["parent"]["type"])
181 );
182 }
183
184 $actions = new ilAdvancedSelectionListGUI();
185 $actions->setListTitle("");
186
187 $ilCtrl->setParameter($this->getParentObject(), "badge_id", $a_set["id"]);
188 $url = $ilCtrl->getLinkTarget($this->getParentObject(), $a_set["active"]
189 ? "deactivate"
190 : "activate");
191 $ilCtrl->setParameter($this->getParentObject(), "badge_id", "");
192 $actions->addItem($lng->txt(!$a_set["active"]
193 ? "badge_add_to_profile"
194 : "badge_remove_from_profile"), "", $url);
195
196 if (ilBadgeHandler::getInstance()->isObiActive()) {
197 $actions->addItem(
198 $lng->txt("badge_add_to_backpack"),
199 "",
200 "",
201 "",
202 "",
203 "",
204 "",
205 false,
206 "il.Badge.publish(" . $a_set["id"] . ");"
207 );
208 }
209
210 $this->tpl->setVariable("ACTIONS", $actions->getHTML());
211 }
212}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
User interface class for advanced drop-down selection lists.
static getInstancesByUserId($a_user_id)
static getInstance()
Constructor.
TableGUI class for user badge listing.
__construct($a_parent_obj, $a_parent_cmd, $a_user_id=null)
ilTable2GUI constructor.
fillRow($a_set)
Standard Version of Fill Row.
Class ilBadgeRenderer.
Class ilBadge.
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 ilTable2GUI.
getHTML()
Get HTML.
getParentObject()
Get parent object.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
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
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
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.
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=null)
Add filter by standard type.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
global $ilCtrl
Definition: ilias.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$url
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46