ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilBadgePersonalTableGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
28 {
29  protected ilObjUser $user;
30  private readonly UIServices $ui;
31  private readonly Tile $tile;
32  private readonly ilLanguage $language;
33 
34  public function __construct(
35  object $a_parent_obj,
36  string $a_parent_cmd,
37  int $a_user_id = null
38  ) {
39  global $DIC;
40 
41  $this->lng = $DIC->language();
42  $this->user = $DIC->user();
43  $this->ctrl = $DIC->ctrl();
44  $this->tpl = $DIC["tpl"];
45  $this->ui = $DIC->ui();
46  $this->tile = new Tile($DIC);
47  $this->language = $DIC->language();
48  $lng = $DIC->language();
49  $ilUser = $DIC->user();
50  $ilCtrl = $DIC->ctrl();
51  $tpl = $DIC["tpl"];
52 
53  if (!$a_user_id) {
54  $a_user_id = $ilUser->getId();
55  }
56 
57  $this->setId("bdgprs");
58 
59  parent::__construct($a_parent_obj, $a_parent_cmd);
60 
61  $this->setTitle($lng->txt("badge_personal_badges"));
62  $this->setEnableTitle(false);
63  $this->setEnableNumInfo(false);
64  $this->setShowRowsSelector(false);
65  $this->setLimit(PHP_INT_MAX);
66  $this->addColumn("", "", 1);
67  $this->addColumn($lng->txt("title"), "title");
68  $this->addColumn($lng->txt("awarded_by"), "parent_title");
69  $this->addColumn($lng->txt("badge_issued_on"), "issued_on");
70  $this->addColumn($lng->txt("badge_in_profile"), "active");
71 
72  $this->setDefaultOrderField("title");
73 
74  $this->setFormAction($ilCtrl->getFormAction($this->getParentObject()));
75  $this->setRowTemplate("tpl.personal_row.html", "Services/Badge");
76 
77  $this->addMultiCommand("activate", $lng->txt("badge_add_to_profile"));
78  $this->addMultiCommand("deactivate", $lng->txt("badge_remove_from_profile"));
79  $this->setSelectAllCheckbox("badge_id");
80 
81  $this->getItems($a_user_id);
82  }
83 
84  public function getItems(int $a_user_id): void
85  {
86  $lng = $this->lng;
87 
88  $data = [];
89 
90  foreach (ilBadgeAssignment::getInstancesByUserId($a_user_id) as $ass) {
91  $badge = new ilBadge($ass->getBadgeId());
92 
93  $parent = null;
94  if ($badge->getParentId()) {
95  $parent = $badge->getParentMeta();
96  if ($parent["type"] === "bdga") {
97  $parent = null;
98  }
99  }
100 
101  $data[] = array(
102  "id" => $badge->getId(),
103  "title" => $badge->getTitle(),
104  "image" => $badge->getImagePath(),
105  "issued_on" => $ass->getTimestamp(),
106  "parent_title" => $parent ? $parent["title"] : null,
107  "parent" => $parent,
108  "active" => (bool) $ass->getPosition(),
109  "renderer" => fn() => $this->tile->asTitle(
110  $this->tile->modalContentWithAssignment($badge, $ass)
111  ),
112  );
113  }
114 
115  $this->setData($data);
116  }
117 
118  protected function fillRow(array $a_set): void
119  {
120  $lng = $this->lng;
121  $ilCtrl = $this->ctrl;
122 
123  $current = $a_set["active"] ? [
124  'target' => 'deactivate',
125  'text' => 'badge_remove_from_profile',
126  'active' => $this->language->txt('yes'),
127  ] : [
128  'target' => 'activate',
129  'text' => 'badge_add_to_profile',
130  'active' => $this->language->txt('no'),
131  ];
132 
133  $this->tpl->setVariable("VAL_ID", $a_set["id"]);
134  $this->tpl->setVariable("PREVIEW", $this->ui->renderer()->render($a_set["renderer"]()));
135  $this->tpl->setVariable("TXT_ISSUED_ON", ilDatePresentation::formatDate(new ilDateTime($a_set["issued_on"], IL_CAL_UNIX)));
136  $this->tpl->setVariable("TXT_ACTIVE", $current["active"]);
137 
138  if ($a_set["parent"]) {
139  $this->tpl->setVariable("TXT_PARENT", $a_set["parent_title"]);
140  $this->tpl->setVariable(
141  "SRC_PARENT",
142  ilObject::_getIcon((int) $a_set["parent"]["id"], "big", $a_set["parent"]["type"])
143  );
144  }
145 
146  $ilCtrl->setParameter($this->getParentObject(), "badge_id", $a_set["id"]);
147  $url = $ilCtrl->getLinkTarget($this->getParentObject(), $current['target']);
148  $ilCtrl->setParameter($this->getParentObject(), "badge_id", "");
149  }
150 }
setData(array $a_data)
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)
setEnableTitle(bool $a_enabletitle)
static getInstancesByUserId(int $a_user_id)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
ilLanguage $lng
setId(string $a_val)
global $DIC
Definition: feed.php:28
Provides fluid interface to RBAC services.
Definition: UIServices.php:23
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
__construct(VocabulariesInterface $vocabularies)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
__construct(object $a_parent_obj, string $a_parent_cmd, int $a_user_id=null)
$url
Definition: ltiregstart.php:35
TableGUI class for user badge listing.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setEnableNumInfo(bool $a_val)
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)
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
addMultiCommand(string $a_cmd, string $a_text)