ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
17  protected $has_write; // [bool]
18  protected $parent_type; // [string]
19 
20  function __construct($a_parent_obj, $a_parent_cmd = "", $a_parent_obj_id, $a_has_write = false)
21  {
22  global $ilCtrl, $lng;
23 
24  $this->setId("bdgbdg");
25  $this->has_write = (bool)$a_has_write;
26  $this->parent_type = ilObject::_lookupType($a_parent_obj_id);
27 
28  parent::__construct($a_parent_obj, $a_parent_cmd);
29 
30  $this->setLimit(9999);
31 
32  $this->setTitle($lng->txt("obj_bdga"));
33 
34  if($this->has_write)
35  {
36  $this->addColumn("", "", 1);
37  }
38 
39  $this->addColumn($lng->txt("title"), "title");
40  $this->addColumn($lng->txt("type"), "type");
41  $this->addColumn($lng->txt("active"), "active");
42 
43  if($this->has_write)
44  {
45  $this->addColumn($lng->txt("action"), "");
46 
47  $lng->loadLanguageModule("content");
48  $this->addMultiCommand("copyBadges", $lng->txt("cont_copy_to_clipboard"));
49  $this->addMultiCommand("activateBadges", $lng->txt("activate"));
50  $this->addMultiCommand("deactivateBadges", $lng->txt("deactivate"));
51  $this->addMultiCommand("confirmDeleteBadges", $lng->txt("delete"));
52  $this->setSelectAllCheckbox("id");
53  }
54 
55  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
56  $this->setRowTemplate("tpl.badge_row.html", "Services/Badge");
57  $this->setDefaultOrderField("title");
58 
59  $this->setFilterCommand("applyBadgeFilter");
60  $this->setResetCommand("resetBadgeFilter");
61 
62  $this->initFilter();
63 
64  $this->getItems($a_parent_obj_id);
65  }
66 
67  public function initFilter()
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  $handler = ilBadgeHandler::getInstance();
75  $valid_types = $handler->getAvailableTypesForObjType($this->parent_type);
76  if($valid_types &&
77  sizeof($valid_types) > 1)
78  {
79  $lng->loadLanguageModule("search");
80 
81  $options = array("" => $lng->txt("search_any"));
82  foreach($valid_types as $id => $type)
83  {
85  }
86  asort($options);
87 
88  $type = $this->addFilterItemByMetaType("type", self::FILTER_SELECT, false, $lng->txt("type"));
89  $type->setOptions($options);
90  $this->filter["type"] = $type->getValue();
91  }
92  }
93 
94  function getItems($a_parent_obj_id)
95  {
96  $data = array();
97 
98  include_once "Services/Badge/classes/class.ilBadgeRenderer.php";
99 
100  foreach(ilBadge::getInstancesByParentId($a_parent_obj_id, $this->filter) as $badge)
101  {
102  $data[] = array(
103  "id" => $badge->getId(),
104  "title" => $badge->getTitle(),
105  "active" => $badge->isActive(),
106  "type" => ($this->parent_type != "bdga")
107  ? ilBadge::getExtendedTypeCaption($badge->getTypeInstance())
108  : $badge->getTypeInstance()->getCaption(),
109  "manual" => (!$badge->getTypeInstance() instanceof ilBadgeAuto),
110  "renderer" => new ilBadgeRenderer(null, $badge)
111  );
112  }
113 
114  $this->setData($data);
115  }
116 
117  protected function fillRow($a_set)
118  {
119  global $lng, $ilCtrl;
120 
121  if($this->has_write)
122  {
123  $this->tpl->setVariable("VAL_ID", $a_set["id"]);
124  }
125 
126  $this->tpl->setVariable("PREVIEW", $a_set["renderer"]->getHTML());
127  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
128  $this->tpl->setVariable("TXT_TYPE", $a_set["type"]);
129  $this->tpl->setVariable("TXT_ACTIVE", $a_set["active"]
130  ? $lng->txt("yes")
131  : $lng->txt("no"));
132 
133  if($this->has_write)
134  {
135  include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
136  $actions = new ilAdvancedSelectionListGUI();
137  $actions->setListTitle($lng->txt("actions"));
138 
139  if($a_set["manual"] &&
140  $a_set["active"])
141  {
142  $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
143  $ilCtrl->setParameter($this->getParentObject(), "tgt", "bdgl");
144  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "awardBadgeUserSelection");
145  $ilCtrl->setParameter($this->getParentObject(), "bid", "");
146  $ilCtrl->setParameter($this->getParentObject(), "tgt", "");
147  $actions->addItem($lng->txt("badge_award_badge"), "", $url);
148  }
149 
150  $ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
151  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "editBadge");
152  $ilCtrl->setParameter($this->getParentObject(), "bid", "");
153  $actions->addItem($lng->txt("edit"), "", $url);
154 
155  $this->tpl->setVariable("ACTIONS", $actions->getHTML());
156  }
157  }
158 }
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=NULL)
Add filter by standard type.
$url
Definition: shib_logout.php:72
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.
if(!is_array($argv)) $options
static getExtendedTypeCaption(ilBadgeType $a_type)
addMultiCommand($a_cmd, $a_text)
Add Command button.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
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.
global $lng
Definition: privfeed.php:17
__construct($a_parent_obj, $a_parent_cmd="", $a_parent_obj_id, $a_has_write=false)
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
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.
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.