ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilBadgeTableGUI.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 $ctrl;
16
17 protected $has_write; // [bool]
18 protected $parent_type; // [string]
19
20 public function __construct($a_parent_obj, $a_parent_cmd = "", $a_parent_obj_id, $a_has_write = false)
21 {
22 global $DIC;
23
24 $this->ctrl = $DIC->ctrl();
25 $this->lng = $DIC->language();
26 $ilCtrl = $DIC->ctrl();
27 $lng = $DIC->language();
28
29 $this->setId("bdgbdg");
30 $this->has_write = (bool) $a_has_write;
31 $this->parent_type = ilObject::_lookupType($a_parent_obj_id);
32
33 parent::__construct($a_parent_obj, $a_parent_cmd);
34
35 $this->setLimit(9999);
36
37 $this->setTitle($lng->txt("obj_bdga"));
38
39 if ($this->has_write) {
40 $this->addColumn("", "", 1);
41 }
42
43 $this->addColumn($lng->txt("title"), "title");
44 $this->addColumn($lng->txt("type"), "type");
45 $this->addColumn($lng->txt("active"), "active");
46
47 if ($this->has_write) {
48 $this->addColumn($lng->txt("action"), "");
49
50 $lng->loadLanguageModule("content");
51 $this->addMultiCommand("copyBadges", $lng->txt("cont_copy_to_clipboard"));
52 $this->addMultiCommand("activateBadges", $lng->txt("activate"));
53 $this->addMultiCommand("deactivateBadges", $lng->txt("deactivate"));
54 $this->addMultiCommand("confirmDeleteBadges", $lng->txt("delete"));
55 $this->setSelectAllCheckbox("id");
56 }
57
58 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
59 $this->setRowTemplate("tpl.badge_row.html", "Services/Badge");
60 $this->setDefaultOrderField("title");
61
62 $this->setFilterCommand("applyBadgeFilter");
63 $this->setResetCommand("resetBadgeFilter");
64
65 $this->initFilter();
66
67 $this->getItems($a_parent_obj_id);
68 }
69
70 public function initFilter()
71 {
73
74 $title = $this->addFilterItemByMetaType("title", self::FILTER_TEXT, false, $lng->txt("title"));
75 $this->filter["title"] = $title->getValue();
76
77 $handler = ilBadgeHandler::getInstance();
78 $valid_types = $handler->getAvailableTypesForObjType($this->parent_type);
79 if ($valid_types &&
80 sizeof($valid_types) > 1) {
81 $lng->loadLanguageModule("search");
82
83 $options = array("" => $lng->txt("search_any"));
84 foreach ($valid_types as $id => $type) {
86 }
87 asort($options);
88
89 $type = $this->addFilterItemByMetaType("type", self::FILTER_SELECT, false, $lng->txt("type"));
90 $type->setOptions($options);
91 $this->filter["type"] = $type->getValue();
92 }
93 }
94
95 public function getItems($a_parent_obj_id)
96 {
97 $data = array();
98
99 foreach (ilBadge::getInstancesByParentId($a_parent_obj_id, $this->filter) as $badge) {
100 $data[] = array(
101 "id" => $badge->getId(),
102 "title" => $badge->getTitle(),
103 "active" => $badge->isActive(),
104 "type" => ($this->parent_type != "bdga")
105 ? ilBadge::getExtendedTypeCaption($badge->getTypeInstance())
106 : $badge->getTypeInstance()->getCaption(),
107 "manual" => (!$badge->getTypeInstance() instanceof ilBadgeAuto),
108 "renderer" => new ilBadgeRenderer(null, $badge)
109 );
110 }
111
112 $this->setData($data);
113 }
114
115 protected function fillRow($a_set)
116 {
118 $ilCtrl = $this->ctrl;
119
120 if ($this->has_write) {
121 $this->tpl->setVariable("VAL_ID", $a_set["id"]);
122 }
123
124 $this->tpl->setVariable("PREVIEW", $a_set["renderer"]->getHTML());
125 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
126 $this->tpl->setVariable("TXT_TYPE", $a_set["type"]);
127 $this->tpl->setVariable("TXT_ACTIVE", $a_set["active"]
128 ? $lng->txt("yes")
129 : $lng->txt("no"));
130
131 if ($this->has_write) {
132 $actions = new ilAdvancedSelectionListGUI();
133 $actions->setListTitle($lng->txt("actions"));
134
135 if ($a_set["manual"] &&
136 $a_set["active"]) {
137 $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
138 $ilCtrl->setParameter($this->getParentObject(), "tgt", "bdgl");
139 $url = $ilCtrl->getLinkTarget($this->getParentObject(), "awardBadgeUserSelection");
140 $ilCtrl->setParameter($this->getParentObject(), "bid", "");
141 $ilCtrl->setParameter($this->getParentObject(), "tgt", "");
142 $actions->addItem($lng->txt("badge_award_badge"), "", $url);
143 }
144
145 $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
146 $url = $ilCtrl->getLinkTarget($this->getParentObject(), "editBadge");
147 $ilCtrl->setParameter($this->getParentObject(), "bid", "");
148 $actions->addItem($lng->txt("edit"), "", $url);
149
150 $this->tpl->setVariable("ACTIONS", $actions->getHTML());
151 }
152 }
153}
An exception for terminatinating execution or to throw for unit testing.
User interface class for advanced drop-down selection lists.
static getInstance()
Constructor.
Class ilBadgeRenderer.
TableGUI class for badge listing.
__construct($a_parent_obj, $a_parent_cmd="", $a_parent_obj_id, $a_has_write=false)
fillRow($a_set)
Standard Version of Fill Row.
initFilter()
Init filter.
getItems($a_parent_obj_id)
static getInstancesByParentId($a_parent_id, array $a_filter=null)
static getExtendedTypeCaption(ilBadgeType $a_type)
static _lookupType($a_id, $a_reference=false)
lookup object type
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
Manual Badge Auto.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type
$url