ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SettingsDBRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Survey\Settings;
22
24
31{
32 protected \ilDBInterface $db;
34
35 public function __construct(
38 ) {
39 $this->db = $db;
40 $this->set_factory = $data->settings();
41 }
42
48 public function hasEnded(array $survey_ids): array
49 {
50 $db = $this->db;
51
52 $set = $db->queryF(
53 "SELECT survey_id, enddate FROM svy_svy " .
54 " WHERE " . $db->in("survey_id", $survey_ids, false, "integer"),
55 [],
56 []
57 );
58 $has_ended = [];
59 while ($rec = $db->fetchAssoc($set)) {
60 $has_ended[(int) $rec["survey_id"]] = !((int) $rec["enddate"] === 0 || $this->toUnixTS($rec["enddate"]) > time());
61 }
62 return $has_ended;
63 }
64
69 public function getObjIdsForSurveyIds(
70 array $survey_ids
71 ): array {
72 $db = $this->db;
73
74 $set = $db->queryF(
75 "SELECT survey_id, obj_fi FROM svy_svy " .
76 " WHERE " . $db->in("survey_id", $survey_ids, false, "integer"),
77 [],
78 []
79 );
80 $obj_ids = [];
81 while ($rec = $db->fetchAssoc($set)) {
82 $obj_ids[(int) $rec["survey_id"]] = (int) $rec["obj_fi"];
83 }
84 return $obj_ids;
85 }
86
92 protected function toUnixTS(
93 string $date
94 ): int {
95 if ($date > 0 && preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $date, $matches)) {
96 return (int) mktime((int) $matches[4], (int) $matches[5], (int) $matches[6], (int) $matches[2], (int) $matches[3], (int) $matches[1]);
97 }
98 return 0;
99 }
100
105 public function getAccessSettings(
106 array $survey_ids
107 ): array {
108 $db = $this->db;
109
110 $set = $db->queryF(
111 "SELECT startdate, enddate, anonymize, survey_id FROM svy_svy " .
112 " WHERE " . $db->in("survey_id", $survey_ids, false, "integer"),
113 [],
114 []
115 );
116 $settings = [];
117 while ($rec = $db->fetchAssoc($set)) {
118 $settings[(int) $rec["survey_id"]] = $this->set_factory->accessSettings(
119 $this->toUnixTS($rec["startdate"] ?? ''),
120 $this->toUnixTS($rec["enddate"] ?? ''),
121 in_array($rec["anonymize"], ["1", "3"], true)
122 );
123 }
124 return $settings;
125 }
126}
__construct(InternalDataService $data, \ilDBInterface $db)
hasEnded(array $survey_ids)
Check if surveys have ended.
toUnixTS(string $date)
Unix time from survey date.
Interface ilDBInterface.
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
in(string $field, array $values, bool $negate=false, string $type="")
if(!file_exists('../ilias.ini.php'))