ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjectBadgeTableGUI.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
5
12{
16 protected $ctrl;
17
21 protected $access;
22
23 protected $has_write; // [bool]
24
25 public function __construct($a_parent_obj, $a_parent_cmd = "", $a_has_write = false)
26 {
27 global $DIC;
28
29 $this->ctrl = $DIC->ctrl();
30 $this->lng = $DIC->language();
31 $this->access = $DIC->access();
32 $ilCtrl = $DIC->ctrl();
33 $lng = $DIC->language();
34
35 $this->setId("bdgobdg");
36 $this->has_write = (bool) $a_has_write;
37
38 parent::__construct($a_parent_obj, $a_parent_cmd);
39
40 $this->setLimit(9999);
41
42 $this->setTitle($lng->txt("badge_object_badges"));
43
44 if ($this->has_write) {
45 $this->addColumn("", "", 1);
46 }
47
48 $this->addColumn($lng->txt("title"), "title");
49 $this->addColumn($lng->txt("type"), "type");
50 $this->addColumn($lng->txt("object"), "container");
51 $this->addColumn($lng->txt("active"), "active");
52 $this->addColumn($lng->txt("action"), "");
53
54 if ($this->has_write) {
55 $this->addMultiCommand("activateObjectBadges", $lng->txt("activate"));
56 $this->addMultiCommand("deactivateObjectBadges", $lng->txt("deactivate"));
57 $this->addMultiCommand("confirmDeleteObjectBadges", $lng->txt("delete"));
58 $this->setSelectAllCheckbox("id");
59 }
60
61 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
62 $this->setRowTemplate("tpl.object_badge_row.html", "Services/Badge");
63 $this->setDefaultOrderField("title");
64
65 $this->setFilterCommand("applyObjectFilter");
66 $this->setResetCommand("resetObjectFilter");
67
68 $this->initFilter();
69
70 $this->getItems();
71 }
72
73 public function initFilter()
74 {
76
77 $title = $this->addFilterItemByMetaType("title", self::FILTER_TEXT, false, $lng->txt("title"));
78 $this->filter["title"] = $title->getValue();
79
80 $object = $this->addFilterItemByMetaType("object", self::FILTER_TEXT, false, $lng->txt("object"));
81 $this->filter["object"] = $object->getValue();
82
83 $lng->loadLanguageModule("search");
84
85 $options = array(
86 "" => $lng->txt("search_any"),
87 );
88 foreach (ilBadgeHandler::getInstance()->getAvailableTypes() as $id => $type) {
89 // no activity badges
90 if (!in_array("bdga", $type->getValidObjectTypes())) {
92 }
93 }
94 asort($options);
95
96 $type = $this->addFilterItemByMetaType("type", self::FILTER_SELECT, false, $lng->txt("type"));
97 $type->setOptions($options);
98 $this->filter["type"] = $type->getValue();
99 }
100
101 public function getItems()
102 {
104 $ilAccess = $this->access;
105
106 $data = $filter_types = array();
107
108 $types = ilBadgeHandler::getInstance()->getAvailableTypes();
109
110 foreach (ilBadge::getObjectInstances($this->filter) as $badge_item) {
111 // :TODO: container presentation
112 $container_url = null;
113 $container = '<img class="ilIcon" src="' .
114 ilObject::_getIcon($badge_item["parent_id"], "big", $badge_item["parent_type"]) .
115 '" alt="' . $lng->txt("obj_" . $badge_item["parent_type"]) .
116 '" title="' . $lng->txt("obj_" . $badge_item["parent_type"]) . '" /> ' .
117 $badge_item["parent_title"];
118
119 if ((bool) $badge_item["deleted"]) {
120 $container .= ' <span class="il_ItemAlertProperty">' . $lng->txt("deleted") . '</span>';
121 } else {
122 $ref_id = array_shift(ilObject::_getAllReferences($badge_item["parent_id"]));
123 if ($ilAccess->checkAccess("read", "", $ref_id)) {
124 $container_url = ilLink::_getLink($ref_id);
125 }
126 }
127
128 $type_caption = ilBadge::getExtendedTypeCaption($types[$badge_item["type_id"]]);
129
130 $data[] = array(
131 "id" => $badge_item["id"],
132 "active" => $badge_item["active"],
133 "type" => $type_caption,
134 "title" => $badge_item["title"],
135 "container_meta" => $container,
136 "container_url" => $container_url,
137 "container_id" => $badge_item["parent_id"],
138 "renderer" => new ilBadgeRenderer(null, new ilBadge($badge_item["id"]))
139 );
140
141 $filter_types[$badge_item["type_id"]] = $type_caption;
142 }
143
144 $this->setData($data);
145 }
146
147 protected function fillRow($a_set)
148 {
150 $ilCtrl = $this->ctrl;
151
152 if ($a_set["container_url"]) {
153 $this->tpl->setCurrentBlock("container_link_bl");
154 $this->tpl->setVariable("TXT_CONTAINER", $a_set["container_meta"]);
155 $this->tpl->setVariable("URL_CONTAINER", $a_set["container_url"]);
156 $this->tpl->parseCurrentBlock();
157 } else {
158 $this->tpl->setCurrentBlock("container_nolink_bl");
159 $this->tpl->setVariable("TXT_CONTAINER_STATIC", $a_set["container_meta"]);
160 $this->tpl->parseCurrentBlock();
161 }
162
163 if ($this->has_write) {
164 $this->tpl->setVariable("VAL_ID", $a_set["id"]);
165 }
166
167 $this->tpl->setVariable("PREVIEW", $a_set["renderer"]->getHTML());
168 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
169 $this->tpl->setVariable("TXT_TYPE", $a_set["type"]);
170 $this->tpl->setVariable("TXT_ACTIVE", $a_set["active"]
171 ? $lng->txt("yes")
172 : $lng->txt("no"));
173
174 if ($this->has_write) {
175 $ilCtrl->setParameter($this->getParentObject(), "pid", $a_set["container_id"]);
176 $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
177 $url = $ilCtrl->getLinkTarget($this->getParentObject(), "listObjectBadgeUsers");
178 $ilCtrl->setParameter($this->getParentObject(), "bid", "");
179 $ilCtrl->setParameter($this->getParentObject(), "pid", "");
180
181 $this->tpl->setVariable("TXT_LIST", $lng->txt("users"));
182 $this->tpl->setVariable("URL_LIST", $url);
183 }
184 }
185}
An exception for terminatinating execution or to throw for unit testing.
static getInstance()
Constructor.
Class ilBadgeRenderer.
Class ilBadge.
static getExtendedTypeCaption(ilBadgeType $a_type)
static getObjectInstances(array $a_filter=null)
TableGUI class for badge listing.
__construct($a_parent_obj, $a_parent_cmd="", $a_has_write=false)
ilTable2GUI constructor.
fillRow($a_set)
Standard Version of Fill Row.
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _getAllReferences($a_id)
get all reference ids of object
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
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setLimit($a_limit=0, $a_default_limit=0)
set max.
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.
setFilterCommand($a_val, $a_caption=null)
Set filter command.
filter()
Definition: filter.php:2
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type
$url
$container
Definition: wac.php:13