3 declare(strict_types=1);
    31     protected \ilDBInterface 
$db;
    51             "DELETE FROM svy_anonymous WHERE " .
    61     public function delete(
int $survey_id, 
string $code): 
void    67                 "DELETE FROM svy_anonymous WHERE " .
    68                 " survey_fi = %s AND survey_key = %s",
    78     protected function getNew(
int $survey_id): string
    81         $codestring = 
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    84         for ($i = 1; $i <= 5; $i++) {
    85             $index = random_int(0, strlen($codestring) - 1);
    86             $code .= substr($codestring, $index, 1);
    89         while ($this->
exists($survey_id, $code)) {
    90             $code = $this->
getNew($survey_id);
   104             "SELECT anonymous_id FROM svy_anonymous " .
   105             " WHERE survey_fi = %s AND survey_key = %s ",
   109         return ($set->numRows() > 0);
   117         $user_key = ($user_id > 0)
   118             ? md5((
string) $user_id)
   133         string $last_name = 
"",
   134         string $first_name = 
"",
   141             $code = $this->
getNew($survey_id);
   143         if ($this->
exists($survey_id, $code)) {
   144             throw new \ilSurveyException(
"Code $code already exists.");
   153         $next_id = $db->nextId(
'svy_anonymous');
   155         $db->insert(
"svy_anonymous", [
   156             "anonymous_id" => [
"integer", $next_id],
   157             "survey_key" => [
"text", $code],
   158             "survey_fi" => [
"integer", $survey_id],
   159             "user_key" => [
"text", $user_key],
   160             "tstamp" => [
"integer", $tstamp],
   161             "sent" => [
"integer", $sent]
   164         if ($email !== 
"" || $last_name !== 
"" || $first_name !== 
"") {
   188             $ids[] = $this->
add($survey_id);
   205         $email = trim($email);
   211         $data = array(
"email" => $email,
   212                       "lastname" => trim($last_name),
   213                       "firstname" => trim($first_name));
   216             "externaldata" => array(
"text", serialize($data)),
   217             "sent" => array(
"integer", $sent)
   223             array(
"anonymous_id" => array(
"integer", $code_id))
   239             "SELECT survey_key FROM svy_anonymous " .
   240             " WHERE survey_fi = %s ",
   245         while ($rec = $db->fetchAssoc($set)) {
   246             $codes[] = $rec[
"survey_key"];
   261             "SELECT * FROM svy_anonymous " .
   262             " WHERE survey_fi = %s ",
   267         while ($rec = $db->fetchAssoc($set)) {
   268             $codes[] = $this->data->code($rec[
"survey_key"])
   269                 ->withId((
int) $rec[
"anonymous_id"])
   270                 ->withSurveyId((
int) $rec[
"survey_fi"])
   271                 ->withUserKey((
string) $rec[
"user_key"])
   272                 ->withTimestamp((
int) $rec[
"tstamp"])
   273                 ->withSent((
int) $rec[
"sent"])
   274                 ->withEmail((
string) $rec[
"email"])
   275                 ->withFirstName((
string) $rec[
"firstname"])
   276                 ->withLastName((
string) $rec[
"lastname"]);
   289             "SELECT * FROM svy_anonymous " .
   290             " WHERE survey_fi = %s AND survey_key = %s",
   291             [
"integer", 
"string"],
   292             [$survey_id, $survey_key]
   295         if ($rec = $db->fetchAssoc($set)) {
   296             $ext_data = unserialize((
string) $rec[
"externaldata"], [
"allowed_classes" => 
false]);
   297             return $this->data->code($rec[
"survey_key"])
   298                                   ->withId((
int) $rec[
"anonymous_id"])
   299                                   ->withSurveyId((
int) $rec[
"survey_fi"])
   300                                   ->withUserKey((
string) $rec[
"user_key"])
   301                                   ->withTimestamp((
int) $rec[
"tstamp"])
   302                                   ->withSent((
int) $rec[
"sent"])
   303                                   ->withEmail((
string) ($ext_data[
"email"] ?? 
""))
   304                                   ->withFirstName((
string) ($ext_data[
"firstname"] ?? 
""))
   305                                   ->withLastName((
string) ($ext_data[
"lastname"] ?? 
""));
   326             "user_key" => [
"text", $user_key]
   329                 "survey_fi" => [
"integer", $survey_id],
   330                 "survey_key" => [
"text", $code]
   347             "SELECT survey_key FROM svy_anonymous " .
   348             " WHERE survey_fi = %s AND user_key = %s ",
   349             [
"integer", 
"string"],
   350             [$survey_id, $user_key]
   352         $rec = $db->fetchAssoc($set);
   353         return $rec[
"survey_key"] ?? 
"";
   363             "SELECT survey_key FROM svy_anonymous " .
   364             " WHERE survey_fi = %s AND anonymous_id = %s ",
   365             [
"integer", 
"integer"],
   366             [$survey_id, $code_id]
   368         $rec = $db->fetchAssoc($set);
   369         return $rec[
"survey_key"] ?? 
"";
 bindUser(int $survey_id, string $code, int $user_id)
Bind registered user to a code. 
 
manipulateF(string $query, array $types, array $values)
 
static is_email(string $a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid. 
 
getNew(int $survey_id)
Get a new unique code. 
 
__construct(InternalDataService $data, \ilDBInterface $db)
 
InternalDataService $data
 
deleteAll(int $survey_id)
Delete all codes of a survey. 
 
getAll(int $survey_id)
Get all access keys of a survey. 
 
queryF(string $query, array $types, array $values)
 
addCodes(int $survey_id, int $nr)
Add multiple codes. 
 
getAllData(int $survey_id)
Get all codes of a survey. 
 
exists(int $survey_id, string $code)
Does code exist in survey? 
 
getByUserKey(int $survey_id, string $survey_key)
 
getUserKey(int $user_id)
Get user key for id. 
 
add(int $survey_id, string $code="", int $user_id=0, string $email="", string $last_name="", string $first_name="", int $sent=0, int $tstamp=0)
Saves a survey access code for a registered user to the database. 
 
updateExternalData(int $code_id, string $email, string $last_name, string $first_name, int $sent)
Update external data of a code. 
 
getByUserId(int $survey_id, int $user_id)
Get code for a registered user. 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
Survey internal data service. 
 
getByCodeId(int $survey_id, int $code_id)