ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExerciseDerivedTaskProvider.php
Go to the documentation of this file.
1<?php
2
25{
26 protected \ILIAS\Exercise\PermanentLink\PermanentLinkManager $link_manager;
29 protected ilAccess $access;
30 protected ilLanguage $lng;
31
32 public function __construct(
36 ilExerciseDerivedTaskAction $derived_task_action,
37 \ILIAS\Exercise\PermanentLink\PermanentLinkManager $link_manager
38 ) {
39 $this->access = $access;
40 $this->task_service = $task_service;
41 $this->task_action = $derived_task_action;
42 $this->lng = $lng;
43 $this->link_manager = $link_manager;
44
45 $this->lng->loadLanguageModule("exc");
46 }
47
48 public function isActive(): bool
49 {
50 return true;
51 }
52
57 public function getTasks(int $user_id): array
58 {
60
61 $tasks = [];
62
63 // open assignments
64 foreach ($this->task_action->getOpenAssignmentsOfUser($user_id) as $ass) {
65 $ref_id = $this->getFirstRefIdWithPermission("read", $ass->getExerciseId(), $user_id);
66 if ($ref_id == 0) {
67 continue;
68 }
69 $state = ilExcAssMemberState::getInstanceByIds($ass->getId(), $user_id);
70 $title = str_replace("%1", $ass->getTitle(), $lng->txt("exc_task_submission"));
71 $tasks[] = $this->task_service->derived()->factory()->task(
72 $title,
73 $ref_id,
74 $state->getOfficialDeadline(),
75 (int) $state->getGeneralStart()
76 )->withUrl($this->link_manager->getPermanentLink($ref_id, $ass->getId()));
77 }
78
79 // open peer feedbacks
80 foreach ($this->task_action->getOpenPeerReviewsOfUser($user_id) as $ass) {
81 $ref_id = $this->getFirstRefIdWithPermission("read", $ass->getExerciseId(), $user_id);
82 if ($ref_id == 0) {
83 continue;
84 }
85 $state = ilExcAssMemberState::getInstanceByIds($ass->getId(), $user_id);
86 $title = str_replace("%1", $ass->getTitle(), $lng->txt("exc_task_peer_feedback"));
87 $tasks[] = $this->task_service->derived()->factory()->task(
88 $title,
89 $ref_id,
90 $state->getPeerReviewDeadline(),
91 0
92 );
93 }
94
95 // open gradings
96 foreach ($this->task_action->getOpenGradingsOfUser($user_id) as $ass) {
97 $ref_id = $this->getFirstRefIdWithPermission("write", $ass->getExerciseId(), $user_id);
98 if ($ref_id == 0) {
99 continue;
100 }
101 $title = str_replace("%1", $ass->getTitle(), $lng->txt("exc_task_grading"));
102 $tasks[] = $this->task_service->derived()->factory()->task($title, $ref_id, 0, 0);
103 }
104
105 return $tasks;
106 }
107
108
109 // Get first ref id for an object id with permission
110 protected function getFirstRefIdWithPermission(
111 string $perm,
112 int $obj_id,
113 int $user_id
114 ): int {
115 $access = $this->access;
116
117 foreach (ilObject::_getAllReferences($obj_id) as $ref_id) {
118 if ($access->checkAccessOfUser($user_id, $perm, "", $ref_id)) {
119 return $ref_id;
120 }
121 }
122 return 0;
123 }
124}
Class ilAccessHandler Checks access for ILIAS objects.
checkAccessOfUser(int $a_user_id, string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=0, ?int $a_tree_id=0)
check access for an object (provide $a_type and $a_obj_id if available for better performance)
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
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...
getFirstRefIdWithPermission(string $perm, int $obj_id, int $user_id)
__construct(ilTaskService $task_service, ilAccess $access, ilLanguage $lng, ilExerciseDerivedTaskAction $derived_task_action, \ILIAS\Exercise\PermanentLink\PermanentLinkManager $link_manager)
ILIAS Exercise PermanentLink PermanentLinkManager $link_manager
language handling
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...
static _getAllReferences(int $id)
get all reference ids for object ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.