ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.DerivedTaskProvider.php
Go to the documentation of this file.
1<?php
2
20
24
30{
31 protected \ilTaskService $task_service;
32 protected \ilAccessHandler $access;
33 protected \ilLanguage $lng;
37
38 public function __construct(
42 ) {
43 global $DIC;
44
45 $survey_service = $DIC->survey()->internal();
46
47 $this->access = $access;
48 $this->task_service = $task_service;
49 $this->lng = $lng;
50
51 $this->lng->loadLanguageModule("svy");
52
53 $this->inv_manager = $survey_service
54 ->domain()
55 ->participants()
56 ->invitations();
57
58 $this->set_repo = $survey_service->repo()->settings();
59 $this->svy_360_manager = new Survey360Manager(
60 $survey_service->repo()
61 );
62 }
63
64 public function isActive(): bool
65 {
66 return true;
67 }
68
69 public function getTasks(int $user_id): array
70 {
72
73 $tasks = [];
74
75 // open assignments
76 $survey_ids = $this->inv_manager->getOpenInvitationsOfUser($user_id);
77 if (count($survey_ids) > 0) {
78 $obj_ids = $this->set_repo->getObjIdsForSurveyIds($survey_ids);
79 $access = $this->set_repo->getAccessSettings($survey_ids);
80 foreach ($obj_ids as $survey_id => $obj_id) {
81 $ref_id = $this->getFirstRefIdWithPermission("read", $obj_id, $user_id);
82 if ($ref_id > 0) {
83 $title = str_replace("%1", \ilObject::_lookupTitle($obj_id), $lng->txt("svy_finish_survey"));
84 $tasks[] = $this->task_service->derived()->factory()->task(
85 $title,
86 $ref_id,
87 $access[$survey_id]->getEndDate(),
88 $access[$survey_id]->getStartDate()
89 );
90 }
91 }
92 }
93
94 // open raters in 360
95 $survey_ids = $this->svy_360_manager->getOpenSurveysForRater($user_id);
96 if (count($survey_ids) > 0) {
97 $obj_ids = $this->set_repo->getObjIdsForSurveyIds($survey_ids);
98 $access = $this->set_repo->getAccessSettings($survey_ids);
99 foreach ($obj_ids as $survey_id => $obj_id) {
100 $ref_id = $this->getFirstRefIdWithPermission("read", $obj_id, $user_id);
101 if ($ref_id > 0) {
102 $title = str_replace("%1", \ilObject::_lookupTitle($obj_id), $lng->txt("svy_finish_survey"));
103 $tasks[] = $this->task_service->derived()->factory()->task(
104 $title,
105 $ref_id,
106 $access[$survey_id]->getEndDate(),
107 $access[$survey_id]->getStartDate()
108 );
109 }
110 }
111 }
112
113 // unclosed 360 survey of appraisee
114 $survey_ids = $this->svy_360_manager->getOpenSurveysForAppraisee($user_id);
115 if (count($survey_ids) > 0) {
116 $obj_ids = $this->set_repo->getObjIdsForSurveyIds($survey_ids);
117 $access = $this->set_repo->getAccessSettings($survey_ids);
118 foreach ($obj_ids as $survey_id => $obj_id) {
119 $ref_id = $this->getFirstRefIdWithPermission("read", $obj_id, $user_id);
120 if ($ref_id > 0) {
121 $title = str_replace("%1", \ilObject::_lookupTitle($obj_id), $lng->txt("svy_finish_survey"));
122 $tasks[] = $this->task_service->derived()->factory()->task(
123 $title,
124 $ref_id,
125 $access[$survey_id]->getEndDate(),
126 $access[$survey_id]->getStartDate()
127 );
128 }
129 }
130 }
131
132 return $tasks;
133 }
134
135
139 protected function getFirstRefIdWithPermission(
140 string $perm,
141 int $obj_id,
142 int $user_id
143 ): int {
144 $access = $this->access;
145
146 foreach (\ilObject::_getAllReferences($obj_id) as $ref_id) {
147 if ($access->checkAccessOfUser($user_id, $perm, "", $ref_id)) {
148 return $ref_id;
149 }
150 }
151 return 0;
152 }
153}
__construct(\ilTaskService $task_service, \ilAccess $access, \ilLanguage $lng)
getFirstRefIdWithPermission(string $perm, int $obj_id, int $user_id)
Get first ref id for an object id with permission.
Class ilAccessHandler Checks access for ILIAS objects.
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
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkAccessOfUser(int $a_user_id, string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance)
$ref_id
Definition: ltiauth.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26