ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjectBadgeTableGUI.php
Go to the documentation of this file.
1 <?php
2 
22 
29 {
31  protected array $filter = [];
32  private readonly Tile $tile;
33  private readonly Renderer $ui_renderer;
34  private readonly Factory $ui_factory;
35 
36  public function __construct(
37  object $a_parent_obj,
38  string $a_parent_cmd = "",
39  protected bool $has_write = false
40  ) {
41  global $DIC;
42 
43  $this->ctrl = $DIC->ctrl();
44  $this->lng = $DIC->language();
45  $this->access = $DIC->access();
46  $this->tile = new Tile($DIC);
47  $this->ui_factory = $DIC->ui()->factory();
48  $this->ui_renderer = $DIC->ui()->renderer();
49  $ilCtrl = $DIC->ctrl();
50  $lng = $DIC->language();
51 
52  $this->setId("bdgobdg");
53 
54  parent::__construct($a_parent_obj, $a_parent_cmd);
55 
56  $this->setLimit(9999);
57 
58  $this->setTitle($lng->txt("badge_object_badges"));
59 
60  if ($this->has_write) {
61  $this->addColumn("", "", 1);
62  }
63 
64  $this->addColumn($lng->txt("title"), "title");
65  $this->addColumn($lng->txt("type"), "type");
66  $this->addColumn($lng->txt("object"), "container");
67  $this->addColumn($lng->txt("active"), "active");
68  $this->addColumn($lng->txt("action"), "");
69 
70  if ($this->has_write) {
71  $this->addMultiCommand("activateObjectBadges", $lng->txt("activate"));
72  $this->addMultiCommand("deactivateObjectBadges", $lng->txt("deactivate"));
73  $this->addMultiCommand("confirmDeleteObjectBadges", $lng->txt("delete"));
74  $this->setSelectAllCheckbox("id");
75  }
76 
77  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
78  $this->setRowTemplate("tpl.object_badge_row.html", "Services/Badge");
79  $this->setDefaultOrderField("title");
80 
81  $this->setFilterCommand("applyObjectFilter");
82  $this->setResetCommand("resetObjectFilter");
83 
84  $this->initFilter();
85 
86  $this->getItems();
87  }
88 
89  public function initFilter(): void
90  {
91  $lng = $this->lng;
92 
93  $title = $this->addFilterItemByMetaType("title", self::FILTER_TEXT, false, $lng->txt("title"));
94  $this->filter["title"] = $title->getValue();
95 
96  $object = $this->addFilterItemByMetaType("object", self::FILTER_TEXT, false, $lng->txt("object"));
97  $this->filter["object"] = $object->getValue();
98 
99  $lng->loadLanguageModule("search");
100 
101  $options = array(
102  "" => $lng->txt("search_any"),
103  );
104  foreach (ilBadgeHandler::getInstance()->getAvailableTypes() as $id => $type) {
105  // no activity badges
106  if (!in_array("bdga", $type->getValidObjectTypes(), true)) {
107  $options[$id] = ilBadge::getExtendedTypeCaption($type);
108  }
109  }
110  asort($options);
111 
112  $type = $this->addFilterItemByMetaType("type", self::FILTER_SELECT, false, $lng->txt("type"));
113  $type->setOptions($options);
114  $this->filter["type"] = $type->getValue();
115  }
116 
117  public function getItems(): void
118  {
119  $data = [];
120 
121  $types = ilBadgeHandler::getInstance()->getAvailableTypes(false);
122 
123  foreach (ilBadge::getObjectInstances($this->filter) as $badge_item) {
124  $type_caption = ilBadge::getExtendedTypeCaption($types[$badge_item['type_id']]);
125 
126  $data[] = [
127  'id' => (int) $badge_item['id'],
128  'active' => $badge_item['active'],
129  'type' => $type_caption,
130  'title' => $badge_item['title'],
131  'container' => $badge_item['parent_title'],
132  'container_deleted' => (bool) ($badge_item['deleted'] ?? false),
133  'container_id' => (int) $badge_item['parent_id'],
134  'container_type' => $badge_item['parent_type'],
135  'renderer' => fn() => $this->tile->asTitle(
136  $this->tile->modalContent(new ilBadge((int) $badge_item['id']))
137  )
138  ];
139  }
140 
141  $this->setData($data);
142  }
143 
144  protected function fillRow(array $a_set): void
145  {
146  $lng = $this->lng;
147  $ilCtrl = $this->ctrl;
148  $ilAccess = $this->access;
149 
150  $container_parts = [
151  $this->ui_renderer->render($this->ui_factory->symbol()->icon()->custom(
152  ilObject::_getIcon($a_set['container_id'], 'big', $a_set['container_type']),
153  $lng->txt('obj_' . $a_set['container_type'])
154  )),
155  $a_set['container'],
156  ];
157 
158  $container_url = '';
159  if ($a_set['container_deleted'] ?? false) {
160  $container_parts[] = ' <span class="il_ItemAlertProperty">' . $lng->txt('deleted') . '</span>';
161  } else {
162  $ref_ids = ilObject::_getAllReferences($a_set['container_id']);
163  $ref_id = array_shift($ref_ids);
164  if ($ilAccess->checkAccess('read', '', $ref_id)) {
165  $container_url = ilLink::_getLink($ref_id);
166  }
167  }
168 
169  $containter_info = implode(' ', $container_parts);
170  if ($container_url !== '') {
171  $this->tpl->setCurrentBlock('container_link_bl');
172  $this->tpl->setVariable('TXT_CONTAINER', $containter_info);
173  $this->tpl->setVariable('URL_CONTAINER', $container_url);
174  } else {
175  $this->tpl->setCurrentBlock('container_nolink_bl');
176  $this->tpl->setVariable('TXT_CONTAINER_STATIC', $containter_info);
177  }
178  $this->tpl->parseCurrentBlock();
179 
180  if ($this->has_write) {
181  $this->tpl->setVariable('VAL_ID', $a_set['id']);
182  }
183 
184  $this->tpl->setVariable('PREVIEW', $this->ui_renderer->render($a_set['renderer']()));
185  $this->tpl->setVariable('TXT_TYPE', $a_set['type']);
186  $this->tpl->setVariable(
187  'TXT_ACTIVE',
188  $a_set['active'] ? $lng->txt('yes') : $lng->txt('no')
189  );
190 
191  if ($this->has_write) {
192  $ilCtrl->setParameter($this->getParentObject(), 'pid', $a_set['container_id']);
193  $ilCtrl->setParameter($this->getParentObject(), 'bid', $a_set['id']);
194  $url = $ilCtrl->getLinkTarget($this->getParentObject(), 'listObjectBadgeUsers');
195  $ilCtrl->setParameter($this->getParentObject(), 'bid', '');
196  $ilCtrl->setParameter($this->getParentObject(), 'pid', '');
197 
198  $this->tpl->setVariable('TXT_LIST', $lng->txt('users'));
199  $this->tpl->setVariable('URL_LIST', $url);
200  }
201  }
202 }
setData(array $a_data)
An entity that renders components to a string output.
Definition: Renderer.php:30
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setFormAction(string $a_form_action, bool $a_multipart=false)
setResetCommand(string $a_val, string $a_caption="")
__construct(object $a_parent_obj, string $a_parent_cmd="", protected bool $has_write=false)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static getObjectInstances(array $a_filter=null)
loadLanguageModule(string $a_module)
Load language module.
ilLanguage $lng
setId(string $a_val)
global $DIC
Definition: feed.php:28
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
$ref_id
Definition: ltiauth.php:67
__construct(VocabulariesInterface $vocabularies)
static getExtendedTypeCaption(ilBadgeType $a_type)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setFilterCommand(string $a_val, string $a_caption="")
$url
Definition: ltiregstart.php:35
TableGUI class for badge listing.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setLimit(int $a_limit=0, int $a_default_limit=0)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
addMultiCommand(string $a_cmd, string $a_text)