ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
SettingsDBRepository.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
15{
19 protected $db;
20
24 protected $set_factory;
25
29 public function __construct(\ilDBInterface $db = null, SettingsFactory $set_factory = null)
30 {
31 global $DIC;
32
33 $this->db = (is_null($db))
34 ? $DIC->database()
35 : $db;
36
37 $this->set_factory = (is_null($set_factory))
38 ? new SettingsFactory()
40 }
41
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"]] = !($rec["enddate"] == 0 || $this->toUnixTS($rec["enddate"]) > time());
61 }
62 return $has_ended;
63 }
64
71 public function getObjIdsForSurveyIds(array $survey_ids) : array
72 {
73 $db = $this->db;
74
75 $set = $db->queryF(
76 "SELECT survey_id, obj_fi FROM svy_svy " .
77 " WHERE " . $db->in("survey_id", $survey_ids, false, "integer"),
78 [],
79 []
80 );
81 $obj_ids = [];
82 while ($rec = $db->fetchAssoc($set)) {
83 $obj_ids[(int) $rec["survey_id"]] = (int) $rec["obj_fi"];
84 }
85 return $obj_ids;
86 }
87
94 protected function toUnixTS($date) : int
95 {
96 if ($date > 0) {
97 if (preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $date, $matches)) {
98 return (int) mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
99 }
100 }
101 return 0;
102 }
103
110 public function getAccessSettings(array $survey_ids) : array
111 {
112 $db = $this->db;
113
114 $set = $db->queryF(
115 "SELECT startdate, enddate, anonymize, survey_id FROM svy_svy " .
116 " WHERE " . $db->in("survey_id", $survey_ids, false, "integer"),
117 [],
118 []
119 );
120 $settings = [];
121 while ($rec = $db->fetchAssoc($set)) {
122 $settings[(int) $rec["survey_id"]] = $this->set_factory->accessSettings(
123 $this->toUnixTS($rec["startdate"]),
124 $this->toUnixTS($rec["enddate"]),
125 in_array($rec["anonymize"], ["1", "3"])
126 );
127 }
128 return $settings;
129 }
130}
An exception for terminatinating execution or to throw for unit testing.
toUnixTS($date)
Unix time from survey date.
hasEnded(array $survey_ids)
Check if surveys have ended.
getAccessSettings(array $survey_ids)
Get access settings.
__construct(\ilDBInterface $db=null, SettingsFactory $set_factory=null)
Constructor.
getObjIdsForSurveyIds(array $survey_ids)
Check if surveys have ended.
Interface ilDBInterface.
$DIC
Definition: xapitoken.php:46