ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilBadgePersonalTableGUI.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
15{
16 function __construct($a_parent_obj, $a_parent_cmd, $a_user_id = null)
17 {
18 global $lng, $ilUser, $ilCtrl, $tpl;
19
20 if(!$a_user_id)
21 {
22 $a_user_id = $ilUser->getId();
23 }
24
25 $this->setId("bdgprs");
26
27 parent::__construct($a_parent_obj, $a_parent_cmd);
28
29 $this->setTitle($lng->txt("badge_personal_badges"));
30
31 $this->addColumn("", "", 1);
32 $this->addColumn($lng->txt("title"), "title");
33 $this->addColumn($lng->txt("object"), "parent_title");
34 $this->addColumn($lng->txt("badge_issued_on"), "issued_on");
35 $this->addColumn($lng->txt("badge_in_profile"), "active");
36 $this->addColumn($lng->txt("actions"), "");
37
38 if(ilBadgeHandler::getInstance()->isObiActive())
39 {
40
41
42 // :TODO: use local copy instead?
43 $tpl->addJavascript("https://backpack.openbadges.org/issuer.js", false);
44
45 $tpl->addJavascript("Services/Badge/js/ilBadge.js");
46 $tpl->addOnLoadCode('il.Badge.setUrl("'.
47 $ilCtrl->getLinkTarget($this->getParentObject(), "addtoBackpack", "", true, false).
48 '")');
49 }
50
51 $this->setDefaultOrderField("title");
52
53 $this->setFormAction($ilCtrl->getFormAction($this->getParentObject()));
54 $this->setRowTemplate("tpl.personal_row.html", "Services/Badge");
55
56 $this->addMultiCommand("activate", $lng->txt("badge_add_to_profile"));
57 $this->addMultiCommand("deactivate", $lng->txt("badge_remove_from_profile"));
58 if(ilBadgeHandler::getInstance()->isObiActive())
59 {
60 $this->addMultiCommand("addToBackpackMulti", $lng->txt("badge_add_to_backpack"));
61 }
62 $this->setSelectAllCheckbox("badge_id");
63
64 $this->getItems($a_user_id);
65 }
66
67 public function initFilters(array $a_parents)
68 {
69 global $lng;
70
71 $title = $this->addFilterItemByMetaType("title", self::FILTER_TEXT, false, $lng->txt("title"));
72 $this->filter["title"] = $title->getValue();
73
74 $lng->loadLanguageModule("search");
75
76 $options = array(
77 "" => $lng->txt("search_any"),
78 "-1" => $lng->txt("none")
79 );
80 asort($a_parents);
81
82 $obj = $this->addFilterItemByMetaType("obj", self::FILTER_SELECT, false, $lng->txt("object"));
83 $obj->setOptions($options + $a_parents);
84 $this->filter["obj"] = $obj->getValue();
85 }
86
87 function getItems($a_user_id)
88 {
89 global $lng;
90
91 $data = $filter_parent = array();
92
93 include_once "Services/Badge/classes/class.ilBadge.php";
94 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
95 include_once "Services/Badge/classes/class.ilBadgeRenderer.php";
96 foreach(ilBadgeAssignment::getInstancesByUserId($a_user_id) as $ass)
97 {
98 $badge = new ilBadge($ass->getBadgeId());
99
100 $parent = null;
101 if($badge->getParentId())
102 {
103 $parent = $badge->getParentMeta();
104 if($parent["type"] == "bdga")
105 {
106 $parent = null;
107 }
108 else
109 {
110 $filter_parent[$parent["id"]] =
111 "(".$lng->txt($parent["type"]).") ".$parent["title"];
112 }
113 }
114
115 $data[] = array(
116 "id" => $badge->getId(),
117 "title" => $badge->getTitle(),
118 "image" => $badge->getImagePath(),
119 "issued_on" => $ass->getTimestamp(),
120 "parent_title" => $parent ? $parent["title"] : null,
121 "parent" => $parent,
122 "active" => (bool)$ass->getPosition(),
123 "renderer" => new ilBadgeRenderer($ass)
124 );
125 }
126
127 $this->initFilters($filter_parent);
128
129 if($this->filter["title"])
130 {
131 foreach($data as $idx => $row)
132 {
133 if(!stristr($row["title"], $this->filter["title"]))
134 {
135 unset($data[$idx]);
136 }
137 }
138 }
139
140 if($this->filter["obj"])
141 {
142 foreach($data as $idx => $row)
143 {
144 if($this->filter["obj"] > 0)
145 {
146 if(!$row["parent"] || $row["parent"]["id"] != $this->filter["obj"])
147 {
148 unset($data[$idx]);
149 }
150 }
151 else
152 {
153 if($row["parent"])
154 {
155 unset($data[$idx]);
156 }
157 }
158 }
159 }
160
161 $this->setData($data);
162 }
163
164 function fillRow($a_set)
165 {
166 global $lng, $ilCtrl;
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 {
178 $this->tpl->setVariable("TXT_PARENT", $a_set["parent_title"]);
179 $this->tpl->setVariable("SRC_PARENT",
180 ilObject::_getIcon($a_set["parent"]["id"], "big", $a_set["parent"]["type"]));
181 }
182
183 include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
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")
195 , "", $url);
196
197 if(ilBadgeHandler::getInstance()->isObiActive())
198 {
199 $actions->addItem($lng->txt("badge_add_to_backpack"), "", "", "", "", "", "",
200 false, "il.Badge.publish(".$a_set["id"].");");
201 }
202
203 $this->tpl->setVariable("ACTIONS", $actions->getHTML());
204 }
205}
206
global $tpl
Definition: ilias.php:8
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)
Constructor.
fillRow($a_set)
Standard Version of Fill Row.
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
Class ilTable2GUI.
getHTML()
Get HTML.
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.
getParentObject()
Get parent object.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
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.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=NULL)
Add filter by standard type.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$url
Definition: shib_logout.php:72
if(!is_array($argv)) $options
$ilUser
Definition: imgupload.php:18