ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBadgeTableGUI.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 include_once("./Services/Badge/classes/class.ilBadge.php");
6 
16 {
20  protected $ctrl;
21 
22  protected $has_write; // [bool]
23  protected $parent_type; // [string]
24 
25  public function __construct($a_parent_obj, $a_parent_cmd = "", $a_parent_obj_id, $a_has_write = false)
26  {
27  global $DIC;
28 
29  $this->ctrl = $DIC->ctrl();
30  $this->lng = $DIC->language();
31  $ilCtrl = $DIC->ctrl();
32  $lng = $DIC->language();
33 
34  $this->setId("bdgbdg");
35  $this->has_write = (bool) $a_has_write;
36  $this->parent_type = ilObject::_lookupType($a_parent_obj_id);
37 
38  parent::__construct($a_parent_obj, $a_parent_cmd);
39 
40  $this->setLimit(9999);
41 
42  $this->setTitle($lng->txt("obj_bdga"));
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("active"), "active");
51 
52  if ($this->has_write) {
53  $this->addColumn($lng->txt("action"), "");
54 
55  $lng->loadLanguageModule("content");
56  $this->addMultiCommand("copyBadges", $lng->txt("cont_copy_to_clipboard"));
57  $this->addMultiCommand("activateBadges", $lng->txt("activate"));
58  $this->addMultiCommand("deactivateBadges", $lng->txt("deactivate"));
59  $this->addMultiCommand("confirmDeleteBadges", $lng->txt("delete"));
60  $this->setSelectAllCheckbox("id");
61  }
62 
63  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
64  $this->setRowTemplate("tpl.badge_row.html", "Services/Badge");
65  $this->setDefaultOrderField("title");
66 
67  $this->setFilterCommand("applyBadgeFilter");
68  $this->setResetCommand("resetBadgeFilter");
69 
70  $this->initFilter();
71 
72  $this->getItems($a_parent_obj_id);
73  }
74 
75  public function initFilter()
76  {
77  $lng = $this->lng;
78 
79  $title = $this->addFilterItemByMetaType("title", self::FILTER_TEXT, false, $lng->txt("title"));
80  $this->filter["title"] = $title->getValue();
81 
83  $valid_types = $handler->getAvailableTypesForObjType($this->parent_type);
84  if ($valid_types &&
85  sizeof($valid_types) > 1) {
86  $lng->loadLanguageModule("search");
87 
88  $options = array("" => $lng->txt("search_any"));
89  foreach ($valid_types as $id => $type) {
91  }
92  asort($options);
93 
94  $type = $this->addFilterItemByMetaType("type", self::FILTER_SELECT, false, $lng->txt("type"));
95  $type->setOptions($options);
96  $this->filter["type"] = $type->getValue();
97  }
98  }
99 
100  public function getItems($a_parent_obj_id)
101  {
102  $data = array();
103 
104  include_once "Services/Badge/classes/class.ilBadgeRenderer.php";
105 
106  foreach (ilBadge::getInstancesByParentId($a_parent_obj_id, $this->filter) as $badge) {
107  $data[] = array(
108  "id" => $badge->getId(),
109  "title" => $badge->getTitle(),
110  "active" => $badge->isActive(),
111  "type" => ($this->parent_type != "bdga")
112  ? ilBadge::getExtendedTypeCaption($badge->getTypeInstance())
113  : $badge->getTypeInstance()->getCaption(),
114  "manual" => (!$badge->getTypeInstance() instanceof ilBadgeAuto),
115  "renderer" => new ilBadgeRenderer(null, $badge)
116  );
117  }
118 
119  $this->setData($data);
120  }
121 
122  protected function fillRow($a_set)
123  {
124  $lng = $this->lng;
126 
127  if ($this->has_write) {
128  $this->tpl->setVariable("VAL_ID", $a_set["id"]);
129  }
130 
131  $this->tpl->setVariable("PREVIEW", $a_set["renderer"]->getHTML());
132  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
133  $this->tpl->setVariable("TXT_TYPE", $a_set["type"]);
134  $this->tpl->setVariable("TXT_ACTIVE", $a_set["active"]
135  ? $lng->txt("yes")
136  : $lng->txt("no"));
137 
138  if ($this->has_write) {
139  include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
140  $actions = new ilAdvancedSelectionListGUI();
141  $actions->setListTitle($lng->txt("actions"));
142 
143  if ($a_set["manual"] &&
144  $a_set["active"]) {
145  $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
146  $ilCtrl->setParameter($this->getParentObject(), "tgt", "bdgl");
147  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "awardBadgeUserSelection");
148  $ilCtrl->setParameter($this->getParentObject(), "bid", "");
149  $ilCtrl->setParameter($this->getParentObject(), "tgt", "");
150  $actions->addItem($lng->txt("badge_award_badge"), "", $url);
151  }
152 
153  $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
154  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "editBadge");
155  $ilCtrl->setParameter($this->getParentObject(), "bid", "");
156  $actions->addItem($lng->txt("edit"), "", $url);
157 
158  $this->tpl->setVariable("ACTIONS", $actions->getHTML());
159  }
160  }
161 }
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
$type
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=null)
Add filter by standard type.
getParentObject()
Get parent object.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
Manual Badge Auto.
getHTML()
Get HTML.
Class ilTable2GUI.
static getInstancesByParentId($a_parent_id, array $a_filter=null)
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
static getExtendedTypeCaption(ilBadgeType $a_type)
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.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
static _lookupType($a_id, $a_reference=false)
lookup object type
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
TableGUI class for badge listing.
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.
__construct($a_parent_obj, $a_parent_cmd="", $a_parent_obj_id, $a_has_write=false)
$url
$handler
setLimit($a_limit=0, $a_default_limit=0)
getItems($a_parent_obj_id)
static getInstance()
Constructor.
setFilterCommand($a_val, $a_caption=null)
Set filter command.