ILIAS  release_8 Revision v8.23
class.ilLSLaunchlinksBuilder.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
28 {
29  public const PERM_PARTICIPATE = 'participate';
30  public const PERM_UNPARTICIPATE = 'unparticipate';
31 
37 
38  protected ilLanguage $lng;
39  protected ilAccess $access;
40  protected ilCtrl $ctrl;
42  protected int $lso_ref_id;
43  protected int $usr_id;
44  protected $first_access;
47 
48  public function __construct(
49  ilLanguage $language,
50  ilAccess $access,
51  ilCtrl $ctrl,
52  ILIAS\UI\Factory $ui_factory,
53  int $lso_ref_id,
54  int $usr_id,
57  ilLSLearnerItemsQueries $ls_items
58  ) {
59  $this->lng = $language;
60  $this->access = $access;
61  $this->ctrl = $ctrl;
62  $this->ui_factory = $ui_factory;
63 
64  $this->lso_ref_id = $lso_ref_id;
65  $this->usr_id = $usr_id;
66  $this->first_access = $first_access;
67  $this->roles = $roles;
68  $this->ls_items = $ls_items;
69  }
70 
71  protected function mayJoin(): bool
72  {
73  return $this->access->checkAccess(self::PERM_PARTICIPATE, '', $this->lso_ref_id);
74  }
75 
76 
77  public function currentUserMayUnparticipate(): bool
78  {
79  return $this->mayUnparticipate();
80  }
81 
82  protected function mayUnparticipate(): bool
83  {
84  return $this->access->checkAccess(self::PERM_UNPARTICIPATE, '', $this->lso_ref_id);
85  }
86 
87  protected function isMember(): bool
88  {
89  return $this->roles->isMember($this->usr_id);
90  }
91 
92  protected function hasCompleted(): bool
93  {
94  return $this->roles->isCompletedByUser($this->usr_id);
95  }
96 
97  protected function getLink(string $cmd): string
98  {
99  return $this->ctrl->getLinkTargetByClass('ilObjLearningSequenceLearnerGUI', $cmd);
100  }
101 
102  public function getLinks(): array
103  {
104  $cmd = $this->ctrl->getCmd();
105  $links = [];
106 
107  if (!$this->isMember() && $this->mayJoin()) {
108  if (!$this->ls_items->hasItems()) {
109  return [];
110  }
111  return [[
112  $this->lng->txt("lso_player_start"),
113  $this->getLink(self::CMD_START),
114  true
115  ]];
116  }
117 
118  if (!$this->hasCompleted() && $this->ls_items->hasItems()) {
119  $label = "lso_player_resume";
120  if ($this->first_access === -1) {
121  $label = "lso_player_start";
122  }
123  $links[] = [
124  $this->lng->txt($label),
125  $this->getLink(self::CMD_VIEW),
126  true
127  ];
128  } else {
129  if ($this->ls_items->hasItems()) {
130  $links[] = [
131  $this->lng->txt("lso_player_review"),
132  $this->getLink(self::CMD_VIEW),
133  true
134  ];
135  }
136 
137  if ($cmd === self::CMD_STANDARD) {
138  $links[] = [
139  $this->lng->txt("lso_player_extro"),
140  $this->getLink(self::CMD_EXTRO),
141  false
142  ];
143  }
144  if ($cmd === self::CMD_EXTRO) {
145  $links[] = [
146  $this->lng->txt("lso_player_abstract"),
147  $this->getLink(self::CMD_STANDARD),
148  false
149  ];
150  }
151  }
152 
153  if ($this->mayUnparticipate()) {
154  $links[] = [
155  $this->lng->txt("unparticipate"),
156  $this->getLink(self::CMD_UNSUBSCRIBE),
157  false
158  ];
159  }
160 
161  return $links;
162  }
163 
164  public function getLaunchbuttonsComponent(): array
165  {
166  $buttons = [];
167  foreach ($this->getLinks() as $idx => $entry) {
168  list($label, $link) = $entry;
169  $buttons[] = $this->ui_factory->button()->standard($label, $link);
170  }
171  return $buttons;
172  }
173 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class Factory.
ilLSLearnerItemsQueries $ls_items
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilLanguage $language, ilAccess $access, ilCtrl $ctrl, ILIAS\UI\Factory $ui_factory, int $lso_ref_id, int $usr_id, $first_access, ilLearningSequenceRoles $roles, ilLSLearnerItemsQueries $ls_items)
This combines calls to ProgressDB and StateDB to handle learner-items in the context of a specific LS...