ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilBadgeUserTableGUI.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
20 protected $tree;
21
22 protected $award_badge; // [ilBadge]
23 protected $do_parent; // [bool]
24
25 public function __construct($a_parent_obj, $a_parent_cmd = "", $a_parent_ref_id, ilBadge $a_award_bagde = null, $a_parent_obj_id = null, $a_restrict_badge_id = null)
26 {
27 global $DIC;
28
29 $this->ctrl = $DIC->ctrl();
30 $this->lng = $DIC->language();
31 $this->tree = $DIC->repositoryTree();
32 $ilCtrl = $DIC->ctrl();
33 $lng = $DIC->language();
34
35 $this->setId("bdgusr");
36 $this->award_badge = $a_award_bagde;
37 $this->do_parent = false;
38
39 $parent_type = ilObject::_lookupType($a_parent_ref_id, true);
40 if (in_array($parent_type, array("grp", "crs"))) {
41 $this->do_parent = (!$a_parent_obj_id && !$this->award_badge);
42 }
43
44 parent::__construct($a_parent_obj, $a_parent_cmd);
45
46 $this->setLimit(9999);
47
48 if ($this->award_badge) {
49 $this->setTitle($lng->txt("badge_award_badge") . ": " . $a_award_bagde->getTitle());
50 $this->setDescription($a_award_bagde->getDescription());
51
52 $this->addColumn("", "", 1);
53
54 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
55 $this->addMultiCommand("assignBadge", $lng->txt("badge_award_badge"));
56 $this->addMultiCommand("confirmDeassignBadge", $lng->txt("badge_remove_badge"));
57 } else {
58 $parent = "";
59 if ($a_parent_obj_id) {
60 $title = ilObject::_lookupTitle($a_parent_obj_id);
61 if (!$title) {
62 $title = ilObjectDataDeletionLog::get($a_parent_obj_id);
63 if ($title) {
64 $title = $title["title"];
65 }
66 }
67 if ($a_restrict_badge_id) {
68 $badge = new ilBadge($a_restrict_badge_id);
69 $title .= " - " . $badge->getTitle();
70 }
71 $parent = $title . ": ";
72 }
73 $this->setTitle($parent . $lng->txt("users"));
74 }
75
76 $this->addColumn($lng->txt("name"), "name");
77 $this->addColumn($lng->txt("login"), "login");
78 $this->addColumn($lng->txt("type"), "type");
79 $this->addColumn($lng->txt("title"), "title");
80 $this->addColumn($lng->txt("badge_issued_on"), "issued");
81
82 if ($this->do_parent) {
83 $this->addColumn($lng->txt("object"), "parent_id");
84 }
85
86 $this->setDefaultOrderField("name");
87
88 $this->setRowTemplate("tpl.user_row.html", "Services/Badge");
89
90 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
91 $this->setFilterCommand("apply" . ucfirst($this->getParentCmd()));
92 $this->setResetCommand("reset" . ucfirst($this->getParentCmd()));
93
94 $this->initFilter();
95
96 $this->getItems($a_parent_ref_id, $this->award_badge, $a_parent_obj_id, $a_restrict_badge_id);
97 }
98
99 public function initFilter()
100 {
102
103 $name = $this->addFilterItemByMetaType("name", self::FILTER_TEXT, false, $lng->txt("name"));
104 $this->filter["name"] = $name->getValue();
105 }
106
107 public function getItems($a_parent_ref_id, ilBadge $a_award_bagde = null, $a_parent_obj_id = null, $a_restrict_badge_id = null)
108 {
110
111 $data = array();
112
113 if (!$a_parent_obj_id) {
114 $a_parent_obj_id = ilObject::_lookupObjId($a_parent_ref_id);
115 }
116
117 // repository context: walk tree for available users
118 if ($a_parent_ref_id) {
119 $user_ids = ilBadgeHandler::getInstance()->getUserIds($a_parent_ref_id, $a_parent_obj_id);
120 }
121
122 $obj_ids = array($a_parent_obj_id);
123
124 // add sub-items
125 if ($this->do_parent) {
126 foreach ($tree->getSubTree($tree->getNodeData($a_parent_ref_id)) as $node) {
127 $obj_ids[] = $node["obj_id"];
128 }
129 }
130
131 $badges = $assignments = array();
132 foreach ($obj_ids as $obj_id) {
133 foreach (ilBadge::getInstancesByParentId($obj_id) as $badge) {
134 $badges[$badge->getId()] = $badge;
135 }
136
137 foreach (ilBadgeAssignment::getInstancesByParentId($obj_id) as $ass) {
138 if ($a_restrict_badge_id &&
139 $a_restrict_badge_id != $ass->getBadgeId()) {
140 continue;
141 }
142
143 // when awarding we only want to see the current badge
144 if ($this->award_badge &&
145 $ass->getBadgeId() != $this->award_badge->getId()) {
146 continue;
147 }
148
149 $assignments[$ass->getUserId()][] = $ass;
150 }
151 }
152
153 // administration context: show only existing assignments
154 if (!$user_ids) {
155 $user_ids = array_keys($assignments);
156 }
157
158 $tmp["set"] = array();
159 if (count($user_ids) > 0) {
160 $uquery = new ilUserQuery();
161 $uquery->setLimit(9999);
162 $uquery->setUserFilter($user_ids);
163
164 if ($this->filter["name"]) {
165 $uquery->setTextFilter($this->filter["name"]);
166 }
167
168 $tmp = $uquery->query();
169 }
170 foreach ($tmp["set"] as $user) {
171 // add 1 entry for each badge
172 if (array_key_exists($user["usr_id"], $assignments)) {
173 foreach ($assignments[$user["usr_id"]] as $user_ass) {
174 $idx = $user_ass->getBadgeId() . "-" . $user["usr_id"];
175
176 $badge = $badges[$user_ass->getBadgeId()];
177
178 if ($this->do_parent) {
179 $parent = $badge->getParentMeta();
180 }
181
182 $data[$idx] = array(
183 "user_id" => $user["usr_id"],
184 "name" => $user["lastname"] . ", " . $user["firstname"],
185 "login" => $user["login"],
186 "type" => ilBadge::getExtendedTypeCaption($badge->getTypeInstance()),
187 "title" => $badge->getTitle(),
188 "issued" => $user_ass->getTimestamp(),
189 "parent_id" => $parent["id"],
190 "parent_meta" => $parent
191 );
192 }
193 }
194 // no badge yet, add dummy entry (for manual awarding)
195 elseif ($this->award_badge) {
196 $idx = "0-" . $user["usr_id"];
197
198 $data[$idx] = array(
199 "user_id" => $user["usr_id"],
200 "name" => $user["lastname"] . ", " . $user["firstname"],
201 "login" => $user["login"],
202 "type" => "",
203 "title" => "",
204 "issued" => "",
205 "parent_id" => ""
206 );
207 }
208 }
209
210 $this->setData($data);
211 }
212
213 protected function fillRow($a_set)
214 {
216
217 if ($this->award_badge) {
218 $this->tpl->setVariable("VAL_ID", $a_set["user_id"]);
219 }
220
221 $this->tpl->setVariable("TXT_NAME", $a_set["name"]);
222 $this->tpl->setVariable("TXT_LOGIN", $a_set["login"]);
223 $this->tpl->setVariable("TXT_TYPE", $a_set["type"]);
224 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
225 $this->tpl->setVariable("TXT_ISSUED", $a_set["issued"]
227 : "");
228
229 if ($a_set["parent_id"]) {
230 $parent = $a_set["parent_meta"];
231 $this->tpl->setVariable("PARENT", $parent["title"]);
232 $this->tpl->setVariable("PARENT_TYPE", $lng->txt("obj_" . $parent["type"]));
233 $this->tpl->setVariable(
234 "PARENT_ICON",
235 ilObject::_getIcon($parent["id"], "big", $parent["type"])
236 );
237 }
238 }
239}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static getInstancesByParentId($a_parent_obj_id)
static getInstance()
Constructor.
TableGUI class for badge user listing.
__construct($a_parent_obj, $a_parent_cmd="", $a_parent_ref_id, ilBadge $a_award_bagde=null, $a_parent_obj_id=null, $a_restrict_badge_id=null)
getItems($a_parent_ref_id, ilBadge $a_award_bagde=null, $a_parent_obj_id=null, $a_restrict_badge_id=null)
fillRow($a_set)
Standard Version of Fill Row.
Class ilBadge.
static getInstancesByParentId($a_parent_id, array $a_filter=null)
static getExtendedTypeCaption(ilBadgeType $a_type)
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilTable2GUI.
getParentCmd()
Get parent command.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
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.
setDescription($a_val)
Set description.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setFilterCommand($a_val, $a_caption=null)
Set filter command.
User query class.
filter()
Definition: filter.php:2
global $DIC
Definition: goto.php:24
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc