ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLPPersonalGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=0);
20 
23 use ILIAS\Tracking\View\FactoryInterface as ViewFactoryInterface;
27 use ILIAS\Tracking\View\Factory as ViewFactory;
32 use ILIAS\Data\URI as URI;
33 
38 {
39  protected const PRESENTATION_OPTION_CURRENT = "current";
40  protected const PRESENTATION_OPTION_FUTURE = "future";
41  protected const PRESENTATION_OPTION_PAST = "past";
42  protected const PRESENTATION_OPTION_ALL = "all";
43  protected const URL_VAR_MODE = "viewcontrol_plp_mode";
44  protected const URL_VAR_ACTION_MODE = "mode";
45  protected const URL_NAMESPACE_PLP = "plp";
46  protected const URL_NAMESPACE_VIEWCONTROL = "viewcontrol";
47  protected const LNG_VAR_PRESENTATION_OPTION_CURRENT = "view_mode_current";
48  protected const LNG_VAR_PRESENTATION_OPTION_FUTURE = "view_mode_future";
49  protected const LNG_VAR_PRESENTATION_OPTION_PAST = "view_mode_past";
50  protected const LNG_VAR_PRESENTATION_OPTION_ALL = "view_mode_all";
51  protected const LNG_VAR_PROPERTY_CRS_START = "trac_begin_at";
52  protected const LNG_VAR_PROPERTY_CRS_END = "trac_end_at";
53  protected const LNG_VAR_PROPERTY_CRS_ONLINE = "online";
54  protected const LNG_VAR_PROPERTY_CRS_ONLINE_YES = "yes";
55  protected const LNG_VAR_PROPERTY_CRS_ONLINE_NO = "no";
56  protected const LNG_VAR_LISTING_TITLE = "courses";
57  protected HTTPServices $http;
58  protected UIServices $ui;
59  protected ilCtrl $ctrl;
60  protected ilObjUser $user;
61  protected ilLanguage $lng;
66  protected ViewFactoryInterface $tracking_view;
67 
68  public function __construct()
69  {
70  global $DIC;
71 
72  $this->ui = $DIC->ui();
73  $this->ctrl = $DIC->ctrl();
74  $this->user = $DIC->user();
75  $this->lng = $DIC->language();
76  $this->http = $DIC->http();
77  $this->refinery = $DIC->refinery();
78  $this->access = $DIC->access();
79  $this->data_factory = new DataFactory();
80  $this->static_url = $DIC['static_url'];
81  $this->tracking_view = new ViewFactory();
82  $this->lng->loadLanguageModule("trac");
83  }
84 
85  public function executeCommand(): void
86  {
87  $this->listCourses();
88  }
89 
90  protected function getCurrentPresentationModeFromQuery(): string
91  {
92  if ($this->http->wrapper()->query()->has(self::URL_VAR_MODE)) {
93  return $this->http->wrapper()->query()->retrieve(
94  self::URL_VAR_MODE,
95  $this->refinery->kindlyTo()->string()
96  );
97  }
98  return self::PRESENTATION_OPTION_CURRENT;
99  }
100 
101  protected function buildViewControls(): array
102  {
103  $current_presentation = $this->getCurrentPresentationModeFromQuery();
104  $presentation_options = [
105  self::PRESENTATION_OPTION_CURRENT => $this->lng->txt(self::LNG_VAR_PRESENTATION_OPTION_CURRENT),
106  self::PRESENTATION_OPTION_FUTURE => $this->lng->txt(self::LNG_VAR_PRESENTATION_OPTION_FUTURE),
107  self::PRESENTATION_OPTION_PAST => $this->lng->txt(self::LNG_VAR_PRESENTATION_OPTION_PAST),
108  self::PRESENTATION_OPTION_ALL => $this->lng->txt(self::LNG_VAR_PRESENTATION_OPTION_ALL),
109  ];
110  $uri = $this->http->request()->getUri()->__toString();
111  $url_builder = new URLBuilder($this->data_factory->uri($uri));
112  list($url_builder, $action_parameter_token) =
113  $url_builder->acquireParameters(
114  [self::URL_NAMESPACE_VIEWCONTROL, self::URL_NAMESPACE_PLP],
115  self::URL_VAR_ACTION_MODE
116  );
117  $modes = $this->ui->factory()->viewControl()->mode(
118  [
119  $presentation_options[self::PRESENTATION_OPTION_CURRENT] => (string) $url_builder->withParameter($action_parameter_token, self::PRESENTATION_OPTION_CURRENT)->buildURI(),
120  $presentation_options[self::PRESENTATION_OPTION_FUTURE] => (string) $url_builder->withParameter($action_parameter_token, self::PRESENTATION_OPTION_FUTURE)->buildURI(),
121  $presentation_options[self::PRESENTATION_OPTION_PAST] => (string) $url_builder->withParameter($action_parameter_token, self::PRESENTATION_OPTION_PAST)->buildURI(),
122  $presentation_options[self::PRESENTATION_OPTION_ALL] => (string) $url_builder->withParameter($action_parameter_token, self::PRESENTATION_OPTION_ALL)->buildURI(),
123  ],
124  'Presentation Mode'
125  )
126  ->withActive($presentation_options[$current_presentation]);
127  return [
128  $modes
129  ];
130  }
131 
135  protected function buildPanelItems(
136  string $presentation_mode
137  ): array {
138  $ids = ilParticipants::_getMembershipByType($this->user->getId(), ["crs"], true);
139  $ids_with_lp = [];
140  $filter = $this->tracking_view->dataRetrieval()->filter()
141  ->withUserIds($this->user->getId())
142  ->withObjectIds(...$ids)
143  ->withOnlyDataOfObjectWithLPEnabled(false);
144  $view_info = $this->tracking_view->dataRetrieval()->service()->retrieveViewInfo($filter);
145  $items = [];
146  foreach ($view_info->combinedInfoIterator() as $combinedInfo) {
147  $obj_id = $combinedInfo->getObjectInfo()->getObjectId();
148  $ids_with_lp[] = $obj_id;
150  $crs = ilObjectFactory::getInstanceByObjId($obj_id);
151  if (
152  !$this->hasReadAccess($obj_id) ||
153  !$this->isPresentable($presentation_mode, $crs->getCourseStart(), $crs->getCourseEnd())
154  ) {
155  continue;
156  }
157  $offline_str = $crs->getOfflineStatus()
158  ? $this->lng->txt(self::LNG_VAR_PROPERTY_CRS_ONLINE_NO)
159  : $this->lng->txt(self::LNG_VAR_PROPERTY_CRS_ONLINE_YES);
160  $property_builder = $this->tracking_view->propertyList()->builder();
161  if (!is_null($crs->getCourseStart())) {
162  $crs_start = ilDatePresentation::formatDate($crs->getCourseStart());
163  $property_builder = $property_builder
164  ->withProperty($this->lng->txt(self::LNG_VAR_PROPERTY_CRS_START), $crs_start);
165  }
166  if (!is_null($crs->getCourseEnd())) {
167  $crs_end = ilDatePresentation::formatDate($crs->getCourseEnd());
168  $property_builder = $property_builder
169  ->withProperty($this->lng->txt(self::LNG_VAR_PROPERTY_CRS_END), $crs_end);
170  }
171  $property_builder = $property_builder
172  ->withProperty($this->lng->txt(self::LNG_VAR_PROPERTY_CRS_ONLINE), $offline_str);
173  $item = $this->tracking_view->renderer()->service()->standardItem(
174  $combinedInfo->getObjectInfo(),
175  $property_builder->getList(),
176  $this->buildLinkToCourse($obj_id)
177  );
178  if (
179  $combinedInfo->getLPInfo()->getLPMode() !== ilLPObjSettings::LP_MODE_UNDEFINED &&
180  $combinedInfo->getLPInfo()->getLPMode() !== ilLPObjSettings::LP_MODE_DEACTIVATED
181  ) {
182  $progress_chart = $this->tracking_view->renderer()->service()->standardProgressMeter($combinedInfo->getLPInfo());
183  $item = $item->withProgress($progress_chart);
184  }
185  $items[$obj_id] = $item;
186  }
187  return $items;
188  }
189 
190  protected function isPresentable(
191  string $presentation_mode,
192  ilDateTime|null $crs_start,
193  ilDateTime|null $crs_end
194  ): bool {
195  $now = new ilDateTime(time(), IL_CAL_UNIX);
196  $crs_start = (is_null($crs_start) || $crs_start->isNull()) ? $now : $crs_start;
197  $crs_end = (is_null($crs_end) || $crs_end->isNull()) ? $now : $crs_end;
198  if ($presentation_mode === self::PRESENTATION_OPTION_ALL) {
199  return true;
200  }
201  // courses without end are never in the past
202  if (
203  $presentation_mode === self::PRESENTATION_OPTION_PAST &&
204  ilDateTime::_after($now, $crs_end)
205  ) {
206  return true;
207  }
208  // courses without start are never in the future
209  if (
210  $presentation_mode === self::PRESENTATION_OPTION_FUTURE &&
211  ilDateTime::_before($now, $crs_start)
212  ) {
213  return true;
214  }
215  // courses without start and end are always current
216  // courses without start or end are current if their end/start is not in the past/future
217  if (
218  $presentation_mode === self::PRESENTATION_OPTION_CURRENT &&
219  ilDateTime::_within($now, $crs_start, $crs_end)
220  ) {
221  return true;
222  }
223  return false;
224  }
225 
226  protected function listCourses(): void
227  {
228  $view_controls = $this->buildViewControls();
229  $items = $this->buildPanelItems($this->getCurrentPresentationModeFromQuery());
230  $crs_item_group = $this->ui->factory()->item()->group("", $items);
231  $ui_panel = $this->ui->factory()->panel()->listing()->standard(
232  $this->lng->txt(self::LNG_VAR_LISTING_TITLE),
233  [
234  $crs_item_group
235  ]
236  )
237  ->withViewControls($view_controls);
238  $this->ui->mainTemplate()->setContent($this->ui->renderer()->render([$ui_panel]));
239  }
240 
241  protected function hasReadAccess(int $obj_id): bool
242  {
243  foreach (ilObject::_getAllReferences($obj_id) as $ref_id) {
244  if ($this->access->checkAccess("read", "", $ref_id)) {
245  return true;
246  }
247  }
248  return false;
249  }
250 
251  protected function buildLinkToCourse(int $obj_id): ?URI
252  {
253  $ref_ids = ilObject::_getAllReferences($obj_id);
254  if (count($ref_ids) === 0) {
255  return null;
256  }
257  return $this->static_url->builder()->build(
258  'crs',
259  $this->data_factory->refId((int) current($ref_ids))
260  );
261  }
262 }
const LNG_VAR_PRESENTATION_OPTION_CURRENT
const LNG_VAR_PRESENTATION_OPTION_FUTURE
buildLinkToCourse(int $obj_id)
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
static _getAllReferences(int $id)
get all reference ids for object ID
acquireParameters(array $namespace, string ... $names)
Definition: URLBuilder.php:138
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_UNIX
isPresentable(string $presentation_mode, ilDateTime|null $crs_start, ilDateTime|null $crs_end)
RefineryFactory $refinery
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Provides fluid interface to RBAC services.
Definition: UIServices.php:24
$ref_id
Definition: ltiauth.php:65
static http()
Fetches the global http state from ILIAS.
ViewFactoryInterface $tracking_view
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:22
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
ilAccessHandler $access
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
static _getMembershipByType(int $a_usr_id, array $a_type, bool $a_only_member_role=false)
get membership by type Get course or group membership
URLBuilder.
Definition: URLBuilder.php:40
static _within(ilDateTime $dt, ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check whether an date is within a date duration given by start and end.