ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilExerciseDerivedTaskProvider.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
12 {
16  protected $task_service;
17 
21  protected $task_action;
22 
26  protected $access;
27 
31  protected $lng;
32 
37  {
38  $this->access = $access;
39  $this->task_service = $task_service;
40  $this->task_action = $derived_task_action;
41  $this->lng = $lng;
42 
43  $this->lng->loadLanguageModule("exc");
44  }
45 
49  public function isActive() : bool
50  {
51  return true;
52  }
53 
57  public function getTasks(int $user_id) : array
58  {
59  $lng = $this->lng;
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  (int) $state->getOfficialDeadline(),
75  (int) $state->getGeneralStart()
76  );
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  (int) $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 
116  protected function getFirstRefIdWithPermission($perm, int $obj_id, int $user_id) : int
117  {
119 
120  foreach (ilObject::_getAllReferences($obj_id) as $ref_id) {
121  if ($access->checkAccessOfUser($user_id, $perm, "", $ref_id)) {
122  return $ref_id;
123  }
124  }
125  return 0;
126  }
127 }
__construct(ilTaskService $task_service, \ilAccess $access, \ilLanguage $lng, ilExerciseDerivedTaskAction $derived_task_action)
Constructor.
Class ilAccessHandler.
static _getAllReferences($a_id)
get all reference ids of object
static getInstanceByIds($a_ass_id, $a_user_id=0)
Get instance by IDs (recommended for consumer code)
getFirstRefIdWithPermission($perm, int $obj_id, int $user_id)
Get first ref id for an object id with permission.
getTasks(int $user_id)
Get providers.ilDerivedTask[]
Action class for derived tasks, mostly getting user reponsibilities by respecting permissions as well...
language handling
Task service.