ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilExerciseDerivedTaskProvider.php
Go to the documentation of this file.
1 <?php
2 
25 {
28  protected ilAccess $access;
29  protected ilLanguage $lng;
30 
31  public function __construct(
32  ilTaskService $task_service,
33  ilAccess $access,
34  ilLanguage $lng,
35  ilExerciseDerivedTaskAction $derived_task_action
36  ) {
37  $this->access = $access;
38  $this->task_service = $task_service;
39  $this->task_action = $derived_task_action;
40  $this->lng = $lng;
41 
42  $this->lng->loadLanguageModule("exc");
43  }
44 
45  public function isActive(): bool
46  {
47  return true;
48  }
49 
54  public function getTasks(int $user_id): array
55  {
56  $lng = $this->lng;
57 
58  $tasks = [];
59 
60  // open assignments
61  foreach ($this->task_action->getOpenAssignmentsOfUser($user_id) as $ass) {
62  $ref_id = $this->getFirstRefIdWithPermission("read", $ass->getExerciseId(), $user_id);
63  if ($ref_id == 0) {
64  continue;
65  }
66  $state = ilExcAssMemberState::getInstanceByIds($ass->getId(), $user_id);
67  $title = str_replace("%1", $ass->getTitle(), $lng->txt("exc_task_submission"));
68  $tasks[] = $this->task_service->derived()->factory()->task(
69  $title,
70  $ref_id,
71  $state->getOfficialDeadline(),
72  (int) $state->getGeneralStart()
73  );
74  }
75 
76  // open peer feedbacks
77  foreach ($this->task_action->getOpenPeerReviewsOfUser($user_id) as $ass) {
78  $ref_id = $this->getFirstRefIdWithPermission("read", $ass->getExerciseId(), $user_id);
79  if ($ref_id == 0) {
80  continue;
81  }
82  $state = ilExcAssMemberState::getInstanceByIds($ass->getId(), $user_id);
83  $title = str_replace("%1", $ass->getTitle(), $lng->txt("exc_task_peer_feedback"));
84  $tasks[] = $this->task_service->derived()->factory()->task(
85  $title,
86  $ref_id,
87  $state->getPeerReviewDeadline(),
88  0
89  );
90  }
91 
92  // open gradings
93  foreach ($this->task_action->getOpenGradingsOfUser($user_id) as $ass) {
94  $ref_id = $this->getFirstRefIdWithPermission("write", $ass->getExerciseId(), $user_id);
95  if ($ref_id == 0) {
96  continue;
97  }
98  $title = str_replace("%1", $ass->getTitle(), $lng->txt("exc_task_grading"));
99  $tasks[] = $this->task_service->derived()->factory()->task($title, $ref_id, 0, 0);
100  }
101 
102  return $tasks;
103  }
104 
105 
106  // Get first ref id for an object id with permission
107  protected function getFirstRefIdWithPermission(
108  string $perm,
109  int $obj_id,
110  int $user_id
111  ): int {
112  $access = $this->access;
113 
114  foreach (ilObject::_getAllReferences($obj_id) as $ref_id) {
115  if ($access->checkAccessOfUser($user_id, $perm, "", $ref_id)) {
116  return $ref_id;
117  }
118  }
119  return 0;
120  }
121 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
$ref_id
Definition: ltiauth.php:67
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
getFirstRefIdWithPermission(string $perm, int $obj_id, int $user_id)
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...
Task service.
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) ...
__construct(ilTaskService $task_service, ilAccess $access, ilLanguage $lng, ilExerciseDerivedTaskAction $derived_task_action)