ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.CodeManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Survey\Code;
22
26
32{
33 protected int $survey_ref_id = 0;
36 protected int $survey_id;
38 protected \ilLanguage $lng;
39
40 public function __construct(
43 \ilObjSurvey $survey,
44 InternalDomainService $domain_service,
45 int $user_id
46 ) {
47 $this->data = $data;
48 $this->code_repo = $code_repo;
49 $this->survey_id = $survey->getSurveyId();
50 $this->survey_ref_id = $survey->getRefId();
51 $this->access = $domain_service->access(
52 $survey->getRefId(),
54 );
55 $this->lng = $domain_service->lng();
56 }
57
61 protected function checkPermission(): void
62 {
63 if (!$this->access->canManageCodes()) {
64 throw new \ilPermissionException($this->lng->txt("permission_denied") .
65 " (" . $this->survey_ref_id . ")");
66 }
67 }
68
73 public function deleteAll(bool $force = false): void
74 {
75 if (!$force) {
76 $this->checkPermission();
77 }
78 $repo = $this->code_repo;
79 $repo->deleteAll($this->survey_id);
80 }
81
86 public function delete(string $code): void
87 {
88 $this->checkPermission();
89 $repo = $this->code_repo;
90 $repo->delete($this->survey_id, $code);
91 }
92
96 public function exists(string $code): bool
97 {
98 $repo = $this->code_repo;
99 return $repo->exists($this->survey_id, $code);
100 }
101
106 public function add(
107 Code $code
108 ): int {
109 //$this->checkPermission();
110 $repo = $this->code_repo;
111 return $repo->add(
112 $this->survey_id,
113 $code->getCode(),
114 $code->getUserId(),
115 $code->getEmail(),
116 $code->getLastName(),
117 $code->getFirstName(),
118 $code->getSent(),
119 $code->getTimestamp()
120 );
121 }
122
130 public function addCodes(int $nr): array
131 {
132 $this->checkPermission();
133 return $this->code_repo->addCodes($this->survey_id, $nr);
134 }
135
140 public function updateExternalData(
141 int $code_id,
142 string $email,
143 string $last_name,
144 string $first_name,
145 int $sent
146 ): bool {
147 $this->checkPermission();
148 return $this->code_repo->updateExternalData(
149 $code_id,
150 $email,
151 $last_name,
152 $first_name,
153 $sent
154 );
155 }
156
162 public function getAll(): array
163 {
164 $this->checkPermission();
165 return $this->code_repo->getAll($this->survey_id);
166 }
167
173 public function getAllData(): array
174 {
175 $this->checkPermission();
176 return $this->code_repo->getAllData($this->survey_id);
177 }
178
183 public function bindUser(
184 string $code,
185 int $user_id
186 ): void {
188 return;
189 }
190 $this->code_repo->bindUser($this->survey_id, $code, $user_id);
191 }
192
196 public function getByUserId(
197 int $user_id
198 ): string {
199 return $this->code_repo->getByUserId($this->survey_id, $user_id);
200 }
201
202 public function getByCodeId(
203 int $code_id
204 ): string {
205 return $this->code_repo->getByCodeId($this->survey_id, $code_id);
206 }
207
211 public function getByUserKey(string $user_key): ?Code
212 {
213 return $this->code_repo->getByUserKey($this->survey_id, $user_key);
214 }
215}
DB survey codes (table.
deleteAll(int $survey_id)
Delete all codes of a survey.
delete(int $survey_id, string $code)
Delete single code.
exists(int $survey_id, string $code)
Does code exist in survey?
getAll()
Get all access keys of a survey.
exists(string $code)
Does code exist in survey?
bindUser(string $code, int $user_id)
Bind registered user to a code.
getAllData()
Get all codes of a survey.
getByUserId(int $user_id)
Get access key for a registered user.
updateExternalData(int $code_id, string $email, string $last_name, string $first_name, int $sent)
Update external data of a code.
getByUserKey(string $user_key)
Get code object for an access key.
deleteAll(bool $force=false)
Delete all codes of survey.
__construct(CodeDBRepo $code_repo, InternalDataService $data, \ilObjSurvey $survey, InternalDomainService $domain_service, int $user_id)
add(Code $code)
Saves a survey access code for a registered user to the database.
addCodes(int $nr)
Add multiple new codes.
Code data class.
Definition: class.Code.php:28
const ANONYMOUS_USER_ID
Definition: constants.php:27
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))