ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSessionOverviewTableGUI.php
Go to the documentation of this file.
1 <?php
2 
20 declare(strict_types=1);
21 
29 {
30  protected ilTree $tree;
32  protected array $events = [];
33 
37  protected $renderer;
38 
42  protected $ui_factory;
43 
44  public function __construct(object $a_parent_obj, string $a_parent_cmd, int $a_crs_ref_id, array $a_members)
45  {
46  global $DIC;
47 
48  $this->ui_factory = $DIC->ui()->factory();
49  $this->renderer = $DIC->ui()->renderer();
50 
51  $this->tree = $DIC->repositoryTree();
52  $this->access = $DIC->access();
53 
54  $this->setId('sessov');
55 
56  parent::__construct($a_parent_obj, $a_parent_cmd);
57 
58  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
59 
60  $this->setTitle($this->lng->txt('event_overview'));
61 
62  $this->addColumn($this->lng->txt('name'), 'name');
63  $this->addColumn($this->lng->txt('login'), 'login');
64 
65  $this->events = $this->gatherEvents($a_crs_ref_id);
66  foreach ($this->events as $idx => $event_obj) {
67  // tooltip properties
68  $tt = [];
69  if (trim($event_obj->getTitle())) {
70  $tt[] = $event_obj->getTitle();
71  }
72  if (trim($event_obj->getDescription())) {
73  $tt[] = $event_obj->getDescription();
74  }
75  if (trim($event_obj->getLocation())) {
76  $tt[] = $this->lng->txt("event_location") . ': ' . $event_obj->getLocation();
77  }
78  $tt[] = $this->lng->txt("event_date_time") . ': ' . $event_obj->getFirstAppointment()->appointmentToString();
79 
80  // use title/datetime
81  if (sizeof($this->events) <= 4) {
82  $caption = $event_obj->getFirstAppointment()->appointmentToString();
83  if (sizeof($tt) == 1) {
84  $tt = [];
85  }
86  }
87  // use sequence
88  else {
89  $caption = $idx + 1;
90  }
91  $tt = implode("<br />\n", $tt);
92 
93  $this->addColumn((string) $caption, 'event_' . $event_obj->getId(), '', false, '', $tt, true);
94  }
95 
96  $this->setDefaultOrderField('name');
97  $this->setDefaultOrderDirection('asc');
98 
99  $this->setRowTemplate('tpl.sess_list_row.html', 'Modules/Session');
100 
101  $this->getItems($this->events, $a_members);
102  }
103 
104  protected function gatherEvents(int $a_crs_ref_id): array
105  {
106  $tree = $this->tree;
107  $ilAccess = $this->access;
108 
109  $events = [];
110  foreach ($tree->getSubtree($tree->getNodeData($a_crs_ref_id), false, ['sess']) as $event_id) {
111  $tmp_event = ilObjectFactory::getInstanceByRefId($event_id, false);
112  if (!is_object($tmp_event) ||
113  !$ilAccess->checkAccess('manage_members', '', $event_id)) {
114  continue;
115  }
116  // sort by date of 1st appointment
117  $events[$tmp_event->getFirstAppointment()->getStartingTime() . '_' . $tmp_event->getId()] = $tmp_event;
118  }
119 
120  ksort($events);
121  return array_values($events);
122  }
123 
124  protected function getItems(array $a_events, array $a_members): void
125  {
126  $data = [];
127  foreach ($a_members as $user_id) {
128  $name = ilObjUser::_lookupName($user_id);
129  $data[$user_id] = array(
130  'name' => $name['lastname'] . ', ' . $name['firstname'],
131  'login' => $name['login']
132  );
133  }
134  foreach ($a_events as $event_obj) {
135  $users_of_event = ilEventParticipants::_getParticipated($event_obj->getID());
136  foreach ($a_members as $user_id) {
137  if (array_key_exists($user_id, $users_of_event)) {
138  $data[$user_id]['event_' . $event_obj->getId()] = true;
139  } else {
140  $data[$user_id]['event_' . $event_obj->getId()] = false;
141  }
142  }
143  }
144  $this->setData($data);
145  }
146 
147  protected function fillRow(array $a_set): void
148  {
149  $this->tpl->setVariable('NAME', $a_set['name']);
150  $this->tpl->setVariable('LOGIN', $a_set['login']);
151 
152  $this->tpl->setCurrentBlock('eventcols');
153  foreach ($this->events as $event_obj) {
154  if ($a_set['event_' . $event_obj->getId()]) {
155  $icon = $this->ui_factory->symbol()->icon()->custom(ilUtil::getImagePath('icon_ok.svg'), $this->lng->txt('event_participated'));
156  } else {
157  $icon = $this->ui_factory->symbol()->icon()->custom(ilUtil::getImagePath('icon_not_ok.svg'), $this->lng->txt('event_not_participated'));
158  }
159  $this->tpl->setVariable("IMAGE_PARTICIPATED", $this->renderer->render($icon));
160  $this->tpl->parseCurrentBlock();
161  }
162  }
163 }
setData(array $a_data)
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
setFormAction(string $a_form_action, bool $a_multipart=false)
getItems(array $a_events, array $a_members)
static _getParticipated(int $a_event_id)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static _lookupName(int $a_user_id)
lookup user name
Table presentation for session overview.
__construct(object $a_parent_obj, string $a_parent_cmd, int $a_crs_ref_id, array $a_members)
setId(string $a_val)
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
setDefaultOrderDirection(string $a_defaultorderdirection)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
__construct(Container $dic, ilPlugin $plugin)
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)