ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 include_once("Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
19  protected $user;
20 
24  protected $ctrl;
25 
29  protected $tpl;
30 
31  public function __construct($a_parent_obj, $a_parent_cmd, $a_user_id = null)
32  {
33  global $DIC;
34 
35  $this->lng = $DIC->language();
36  $this->user = $DIC->user();
37  $this->ctrl = $DIC->ctrl();
38  $this->tpl = $DIC["tpl"];
39  $lng = $DIC->language();
40  $ilUser = $DIC->user();
41  $ilCtrl = $DIC->ctrl();
42  $tpl = $DIC["tpl"];
43 
44  if (!$a_user_id) {
45  $a_user_id = $ilUser->getId();
46  }
47 
48  $this->setId("bdgprs");
49 
50  parent::__construct($a_parent_obj, $a_parent_cmd);
51 
52  $this->setTitle($lng->txt("badge_personal_badges"));
53 
54  $this->addColumn("", "", 1);
55  $this->addColumn($lng->txt("title"), "title");
56  $this->addColumn($lng->txt("object"), "parent_title");
57  $this->addColumn($lng->txt("badge_issued_on"), "issued_on");
58  $this->addColumn($lng->txt("badge_in_profile"), "active");
59  $this->addColumn($lng->txt("actions"), "");
60 
61  if (ilBadgeHandler::getInstance()->isObiActive()) {
62 
63 
64  // :TODO: use local copy instead?
65  $tpl->addJavascript("https://backpack.openbadges.org/issuer.js", false);
66 
67  $tpl->addJavascript("Services/Badge/js/ilBadge.js");
68  $tpl->addOnLoadCode('il.Badge.setUrl("' .
69  $ilCtrl->getLinkTarget($this->getParentObject(), "addtoBackpack", "", true, false) .
70  '")');
71  }
72 
73  $this->setDefaultOrderField("title");
74 
75  $this->setFormAction($ilCtrl->getFormAction($this->getParentObject()));
76  $this->setRowTemplate("tpl.personal_row.html", "Services/Badge");
77 
78  $this->addMultiCommand("activate", $lng->txt("badge_add_to_profile"));
79  $this->addMultiCommand("deactivate", $lng->txt("badge_remove_from_profile"));
80  if (ilBadgeHandler::getInstance()->isObiActive()) {
81  $this->addMultiCommand("addToBackpackMulti", $lng->txt("badge_add_to_backpack"));
82  }
83  $this->setSelectAllCheckbox("badge_id");
84 
85  $this->getItems($a_user_id);
86  }
87 
88  public function initFilters(array $a_parents)
89  {
90  $lng = $this->lng;
91 
92  $title = $this->addFilterItemByMetaType("title", self::FILTER_TEXT, false, $lng->txt("title"));
93  $this->filter["title"] = $title->getValue();
94 
95  $lng->loadLanguageModule("search");
96 
97  $options = array(
98  "" => $lng->txt("search_any"),
99  "-1" => $lng->txt("none")
100  );
101  asort($a_parents);
102 
103  $obj = $this->addFilterItemByMetaType("obj", self::FILTER_SELECT, false, $lng->txt("object"));
104  $obj->setOptions($options + $a_parents);
105  $this->filter["obj"] = $obj->getValue();
106  }
107 
108  public function getItems($a_user_id)
109  {
110  $lng = $this->lng;
111 
112  $data = $filter_parent = array();
113 
114  include_once "Services/Badge/classes/class.ilBadge.php";
115  include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
116  include_once "Services/Badge/classes/class.ilBadgeRenderer.php";
117  foreach (ilBadgeAssignment::getInstancesByUserId($a_user_id) as $ass) {
118  $badge = new ilBadge($ass->getBadgeId());
119 
120  $parent = null;
121  if ($badge->getParentId()) {
122  $parent = $badge->getParentMeta();
123  if ($parent["type"] == "bdga") {
124  $parent = null;
125  } else {
126  $filter_parent[$parent["id"]] =
127  "(" . $lng->txt($parent["type"]) . ") " . $parent["title"];
128  }
129  }
130 
131  $data[] = array(
132  "id" => $badge->getId(),
133  "title" => $badge->getTitle(),
134  "image" => $badge->getImagePath(),
135  "issued_on" => $ass->getTimestamp(),
136  "parent_title" => $parent ? $parent["title"] : null,
137  "parent" => $parent,
138  "active" => (bool) $ass->getPosition(),
139  "renderer" => new ilBadgeRenderer($ass)
140  );
141  }
142 
143  $this->initFilters($filter_parent);
144 
145  if ($this->filter["title"]) {
146  foreach ($data as $idx => $row) {
147  if (!stristr($row["title"], $this->filter["title"])) {
148  unset($data[$idx]);
149  }
150  }
151  }
152 
153  if ($this->filter["obj"]) {
154  foreach ($data as $idx => $row) {
155  if ($this->filter["obj"] > 0) {
156  if (!$row["parent"] || $row["parent"]["id"] != $this->filter["obj"]) {
157  unset($data[$idx]);
158  }
159  } else {
160  if ($row["parent"]) {
161  unset($data[$idx]);
162  }
163  }
164  }
165  }
166 
167  $this->setData($data);
168  }
169 
170  public function fillRow($a_set)
171  {
172  $lng = $this->lng;
174 
175  $this->tpl->setVariable("VAL_ID", $a_set["id"]);
176  $this->tpl->setVariable("PREVIEW", $a_set["renderer"]->getHTML());
177  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
178  $this->tpl->setVariable("TXT_ISSUED_ON", ilDatePresentation::formatDate(new ilDateTime($a_set["issued_on"], IL_CAL_UNIX)));
179  $this->tpl->setVariable("TXT_ACTIVE", $a_set["active"]
180  ? $lng->txt("yes")
181  : $lng->txt("no"));
182 
183  if ($a_set["parent"]) {
184  $this->tpl->setVariable("TXT_PARENT", $a_set["parent_title"]);
185  $this->tpl->setVariable(
186  "SRC_PARENT",
187  ilObject::_getIcon($a_set["parent"]["id"], "big", $a_set["parent"]["type"])
188  );
189  }
190 
191  include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
192  $actions = new ilAdvancedSelectionListGUI();
193  $actions->setListTitle("");
194 
195  $ilCtrl->setParameter($this->getParentObject(), "badge_id", $a_set["id"]);
196  $url = $ilCtrl->getLinkTarget($this->getParentObject(), $a_set["active"]
197  ? "deactivate"
198  : "activate");
199  $ilCtrl->setParameter($this->getParentObject(), "badge_id", "");
200  $actions->addItem($lng->txt(!$a_set["active"]
201  ? "badge_add_to_profile"
202  : "badge_remove_from_profile"), "", $url);
203 
204  if (ilBadgeHandler::getInstance()->isObiActive()) {
205  $actions->addItem(
206  $lng->txt("badge_add_to_backpack"),
207  "",
208  "",
209  "",
210  "",
211  "",
212  "",
213  false,
214  "il.Badge.publish(" . $a_set["id"] . ");"
215  );
216  }
217 
218  $this->tpl->setVariable("ACTIONS", $actions->getHTML());
219  }
220 }
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
global $DIC
Definition: saml.php:7
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=null)
Add filter by standard type.
const IL_CAL_UNIX
getParentObject()
Get parent object.
setId($a_val)
Set id.
user()
Definition: user.php:4
global $ilCtrl
Definition: ilias.php:18
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
getHTML()
Get HTML.
__construct($a_parent_obj, $a_parent_cmd, $a_user_id=null)
Class ilTable2GUI.
addMultiCommand($a_cmd, $a_text)
Add Command button.
Date and time handling
$ilUser
Definition: imgupload.php:18
setRowTemplate($a_template, $a_template_dir="")
Set row template.
TableGUI class for user badge listing.
Create styles array
The data for the language used.
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
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.
$url
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
static getInstancesByUserId($a_user_id)
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
static getInstance()
Constructor.