ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.DerivedTaskProvider.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
6
10
18{
22 protected $task_service;
23
27 protected $access;
28
32 protected $lng;
33
37 protected $inv_manager;
38
42 protected $set_repo;
43
48
53 {
54 $this->access = $access;
55 $this->task_service = $task_service;
56 $this->lng = $lng;
57
58 $this->lng->loadLanguageModule("svy");
59
60 $this->inv_manager = new InvitationsManager();
61 $this->set_repo = new SettingsDBRepository();
62 $this->svy_360_manager = new Survey360Manager();
63 }
64
68 public function isActive() : bool
69 {
70 return true;
71 }
72
76 public function getTasks(int $user_id) : array
77 {
79
80 $tasks = [];
81
82 // open assignments
83 $survey_ids = $this->inv_manager->getOpenInvitationsOfUser($user_id);
84 if (count($survey_ids) > 0) {
85 $obj_ids = $this->set_repo->getObjIdsForSurveyIds($survey_ids);
86 $access = $this->set_repo->getAccessSettings($survey_ids);
87 foreach ($obj_ids as $survey_id => $obj_id) {
88 $ref_id = $this->getFirstRefIdWithPermission("read", $obj_id, $user_id);
89 if ($ref_id > 0) {
90 $title = str_replace("%1", \ilObject::_lookupTitle($obj_id), $lng->txt("svy_finish_survey"));
91 $tasks[] = $this->task_service->derived()->factory()->task(
92 $title,
93 $ref_id,
94 (int) $access[$survey_id]->getEndDate(),
95 (int) $access[$survey_id]->getStartDate()
96 );
97 }
98 }
99 }
100
101 // open raters in 360
102 $survey_ids = $this->svy_360_manager->getOpenSurveysForRater($user_id);
103 if (count($survey_ids) > 0) {
104 $obj_ids = $this->set_repo->getObjIdsForSurveyIds($survey_ids);
105 $access = $this->set_repo->getAccessSettings($survey_ids);
106 foreach ($obj_ids as $survey_id => $obj_id) {
107 $ref_id = $this->getFirstRefIdWithPermission("read", $obj_id, $user_id);
108 if ($ref_id > 0) {
109 $title = str_replace("%1", \ilObject::_lookupTitle($obj_id), $lng->txt("svy_finish_survey"));
110 $tasks[] = $this->task_service->derived()->factory()->task(
111 $title,
112 $ref_id,
113 (int) $access[$survey_id]->getEndDate(),
114 (int) $access[$survey_id]->getStartDate()
115 );
116 }
117 }
118 }
119
120 // unclosed 360 survey of appraisee
121 $survey_ids = $this->svy_360_manager->getOpenSurveysForAppraisee($user_id);
122 if (count($survey_ids) > 0) {
123 $obj_ids = $this->set_repo->getObjIdsForSurveyIds($survey_ids);
124 $access = $this->set_repo->getAccessSettings($survey_ids);
125 foreach ($obj_ids as $survey_id => $obj_id) {
126 $ref_id = $this->getFirstRefIdWithPermission("read", $obj_id, $user_id);
127 if ($ref_id > 0) {
128 $title = str_replace("%1", \ilObject::_lookupTitle($obj_id), $lng->txt("svy_finish_survey"));
129 $tasks[] = $this->task_service->derived()->factory()->task(
130 $title,
131 $ref_id,
132 (int) $access[$survey_id]->getEndDate(),
133 (int) $access[$survey_id]->getStartDate()
134 );
135 }
136 }
137 }
138
139 return $tasks;
140 }
141
142
150 protected function getFirstRefIdWithPermission($perm, int $obj_id, int $user_id) : int
151 {
153
154 foreach (\ilObject::_getAllReferences($obj_id) as $ref_id) {
155 if ($access->checkAccessOfUser($user_id, $perm, "", $ref_id)) {
156 return $ref_id;
157 }
158 }
159 return 0;
160 }
161}
An exception for terminatinating execution or to throw for unit testing.
getFirstRefIdWithPermission($perm, int $obj_id, int $user_id)
Get first ref id for an object id with permission.
__construct(\ilTaskService $task_service, \ilAccess $access, \ilLanguage $lng)
Constructor.
getTasks(int $user_id)
Get providers.ilDerivedTask[]
Class ilAccessHandler.
language handling
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object