ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.CodeManager.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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(),
53 $user_id
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 {
187 if ($user_id === ANONYMOUS_USER_ID) {
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
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
const ANONYMOUS_USER_ID
Definition: constants.php:27
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
if( $orgName !==null) if($spconfig->hasValue('contacts')) $email
Definition: metadata.php:302
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.Code.php:21