ILIAS  release_8 Revision v8.23
class.ilEmployeeTalkMyStaffListGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
30 
40 {
41  private UIServices $ui;
43  private ilTabsGUI $tabs;
51 
52  public function __construct()
53  {
57  $container = $GLOBALS['DIC'];
58 
59  $container->language()->loadLanguageModule('etal');
60  $container->language()->loadLanguageModule('orgu');
61  $this->language = $container->language();
62  $this->http = $container->http();
63  $this->talkAccess = new ilObjEmployeeTalkAccess();
64  $this->access = ilMyStaffAccess::getInstance();
65 
66  $this->tabs = $container->tabs();
67  $this->ui = $container->ui();
68  $this->refinery = $container->refinery();
69  $this->controlFlow = $container->ctrl();
70  $this->currentUser = $container->user();
71  $this->repository = new IliasDBEmployeeTalkRepository($container->database());
72  }
73 
74  public function executeCommand(): void
75  {
76  $nextClass = $this->controlFlow->getNextClass();
77  $command = $this->controlFlow->getCmd(ControlFlowCommand::DEFAULT);
78  switch ($nextClass) {
79  case strtolower(ilObjEmployeeTalkSeriesGUI::class):
80  $gui = new ilObjEmployeeTalkSeriesGUI();
81  $this->controlFlow->forwardCommand($gui);
82  break;
83  case strtolower(ilObjEmployeeTalkGUI::class):
84  $gui = new ilObjEmployeeTalkGUI();
85  if ($this->access->hasCurrentUserAccessToTalks()) {
86  $this->tabs->setBackTarget(
87  $this->language->txt('etal_talks'),
88  $this->controlFlow->getLinkTarget($this, ControlFlowCommand::INDEX)
89  );
90  }
91  $this->controlFlow->forwardCommand($gui);
92  break;
93  case strtolower(ilFormPropertyDispatchGUI::class):
94  $this->controlFlow->setReturn($this, ControlFlowCommand::INDEX);
95  $table = new ilEmployeeTalkTableGUI($this, ControlFlowCommand::INDEX);
96  $table->executeCommand();
97  break;
98  default:
99  switch ($command) {
100  case ControlFlowCommand::APPLY_FILTER:
101  $this->applyFilter();
102  break;
103  case ControlFlowCommand::RESET_FILTER:
104  $this->resetFilter();
105  break;
106  case ControlFlowCommand::TABLE_ACTIONS:
107  $this->getActions();
108  break;
109  default:
110  $this->view();
111  }
112 
113  }
114  }
115 
116  private function getActions(): void
117  {
118  $listGUI = new ilAdvancedSelectionListGUI();
119 
120  $class = strtolower(ilObjEmployeeTalkGUI::class);
121  $classPath = [
122  strtolower(ilDashboardGUI::class),
123  strtolower(ilMyStaffGUI::class),
124  strtolower(ilEmployeeTalkMyStaffListGUI::class),
125  $class
126  ];
127 
128  $queryParams = $this->http->request()->getQueryParams();
129  if (!key_exists('ref_id', $queryParams)) {
130  echo $listGUI->getHTML(true);
131  exit;
132  }
133 
134  $refId = $this->http
135  ->wrapper()
136  ->query()
137  ->retrieve('ref_id', $this->refinery->kindlyTo()->int());
138  $this->controlFlow->setParameterByClass($class, "ref_id", $refId);
139  if ($this->talkAccess->canEdit($refId)) {
140  $listGUI->addItem($this->language->txt('edit'), '', $this->controlFlow->getLinkTargetByClass($classPath, ControlFlowCommand::UPDATE));
141  } else {
142  $listGUI->addItem($this->language->txt('view'), '', $this->controlFlow->getLinkTargetByClass($classPath, ControlFlowCommand::INDEX));
143  }
144 
145  if ($this->talkAccess->canDelete($refId)) {
146  $this->controlFlow->setParameterByClass($class, "item_ref_id", $refId);
147  $listGUI->addItem($this->language->txt('delete'), '', $this->controlFlow->getLinkTargetByClass($classPath, ControlFlowCommand::DELETE_INDEX));
148  }
149 
150  echo $listGUI->getHTML(true);
151  exit;
152  }
153 
154  private function applyFilter(): void
155  {
156  $table = new ilEmployeeTalkTableGUI($this, ControlFlowCommand::APPLY_FILTER);
157  $table->writeFilterToSession();
158  $table->resetOffset();
159  $this->view();
160  }
161 
162  private function resetFilter(): void
163  {
164  $table = new ilEmployeeTalkTableGUI($this, ControlFlowCommand::RESET_FILTER);
165  $table->resetOffset();
166  $table->resetFilter();
167  $this->view();
168  }
169 
170  private function view(): bool
171  {
172  $this->loadActionBar();
173  $this->loadTabs();
174  $this->ui->mainTemplate()->setTitle($this->language->txt('mm_org_etal'));
175  $this->ui->mainTemplate()->setTitleIcon(ilUtil::getImagePath('icon_etal.svg'));
176  $this->ui->mainTemplate()->setContent($this->loadTable()->getHTML());
177  return true;
178  }
179 
180  private function loadTabs(): void
181  {
182  $this->tabs->addTab("view_content", "Content", "#");
183  $this->tabs->activateTab("view_content");
184  //$this->tabs->addTab("placeholder", "", "#");
185  $this->tabs->setForcePresentationOfSingleTab(true);
186  }
187 
188  private function loadActionBar(): void
189  {
190  $talkAccess = new ilObjEmployeeTalkAccess();
191  if (!$talkAccess->canCreate()) {
192  return;
193  }
194 
195  $gl = new ilGroupedListGUI();
196  $gl->setAsDropDown(true, false);
197 
198  $templates = new CallbackFilterIterator(
200  function (array $item) {
201  return
202  (
203  $item['offline'] === "0" ||
204  $item['offline'] === null
205  ) && ilObjTalkTemplate::_hasUntrashedReference(intval($item['obj_id']));
206  }
207  );
208 
209  foreach ($templates as $item) {
210  $type = $item["type"];
211 
212  $objId = intval($item['obj_id']);
213  $path = ilObject::_getIcon($objId, 'tiny', $type);
214  $icon = ($path != "")
215  ? ilUtil::img($path, "") . " "
216  : "";
217 
218  $url = $this->controlFlow->getLinkTargetByClass(strtolower(ilObjEmployeeTalkSeriesGUI::class), ControlFlowCommand::CREATE);
220 
221  // Templates only have one ref id
222  $url .= "&new_type=" . ilObjEmployeeTalkSeries::TYPE;
223  $url .= "&template=" . array_pop($refId);
225 
226  $ttip = ilHelp::getObjCreationTooltipText("tals");
227 
228  $gl->addEntry(
229  $icon . $item["title"],
230  $url,
231  "_top",
232  "",
233  "",
234  $type,
235  $ttip,
236  "bottom center",
237  "top center",
238  false
239  );
240  }
241 
242  $adv = new ilAdvancedSelectionListGUI();
243  $adv->setListTitle($this->language->txt("etal_add_new_item"));
244  //$gl->getHTML();
245  $adv->setGroupedList($gl);
247  //$this->toolbar->addDropDown($this->language->txt("cntr_add_new_item"), $adv->getHTML());
248  $this->ui->mainTemplate()->setVariable("SELECT_OBJTYPE_REPOS", $adv->getHTML());
249  }
250 
251  private function loadTable(): ilEmployeeTalkTableGUI
252  {
253  $table = new ilEmployeeTalkTableGUI($this, ControlFlowCommand::DEFAULT);
254 
258  $talks = [];
259  if ($this->currentUser->getId() === 6) {
260  $talks = $this->repository->findAll();
261  } else {
262  $users = $this->getEmployeeIdsWithValidPermissionRights($this->currentUser->getId());
263  $talks = $this->repository->findByUserOrTheirEmployees($this->currentUser->getId(), $users);
264  }
265  $table->setTalkData($talks);
266 
267  return $table;
268  }
269 
270  private function getEmployeeIdsWithValidPermissionRights(int $userId): array
271  {
272  $myStaffAccess = ilMyStaffAccess::getInstance();
273  //The user has always access to his own talks
274  $managedUsers = [$userId];
275 
279  $managedOrgUnitUsersOfUserByPosition = $myStaffAccess->getUsersForUserPerPosition($userId);
280 
281  foreach ($managedOrgUnitUsersOfUserByPosition as $position => $managedOrgUnitUserByPosition) {
282  // Check if the position has any relevant position rights
284  $isAbleToExecuteOperation = array_reduce($permissionSet->getOperations(), function (bool $prev, ilOrgUnitOperation $it) {
285  return $prev || $it->getOperationString() === EmployeeTalkPositionAccessLevel::VIEW;
286  }, false);
287 
288  if (!$isAbleToExecuteOperation) {
289  continue;
290  }
291 
292  foreach ($managedOrgUnitUserByPosition as $managedOrgUnitUser) {
293  $managedUsers[] = intval($managedOrgUnitUser);
294  }
295  }
296 
297  $managedUsers = array_unique($managedUsers, SORT_NUMERIC);
298 
299  return $managedUsers;
300  }
301 }
static getObjCreationTooltipText(string $a_type)
Get object_creation tooltip tab text.
exit
Definition: login.php:28
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type
static _getAllReferences(int $id)
get all reference ids for object 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 getTemplateSetForContextName(string $context_name, string $position_id, bool $editable=false)
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
$objId
Definition: xapitoken.php:57
$refId
Definition: xapitoken.php:58
static _getObjectsByType(string $obj_type="", int $owner=null)
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
$path
Definition: ltiservices.php:32
$container
Definition: wac.php:14
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Provides fluid interface to RBAC services.
Definition: UIServices.php:23
canCreate(?ilObjUser $talkParticipant=null)
Checks if the user is allowed to create a new talks series.
static http()
Fetches the global http state from ILIAS.
Class ilObjEmployeeTalkGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
__construct(Container $dic, ilPlugin $plugin)
$url
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...