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