ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Survey\Settings\SettingsDBRepository Class Reference

Survey settings db repository. More...

+ Collaboration diagram for ILIAS\Survey\Settings\SettingsDBRepository:

Public Member Functions

 __construct (InternalDataService $data, \ilDBInterface $db)
 
 hasEnded (array $survey_ids)
 Check if surveys have ended. More...
 
 getObjIdsForSurveyIds (array $survey_ids)
 
 getAccessSettings (array $survey_ids)
 

Protected Member Functions

 toUnixTS (string $date)
 Unix time from survey date. More...
 

Protected Attributes

ilDBInterface $db
 
SettingsFactory $set_factory
 

Detailed Description

Survey settings db repository.

This should wrap all svy_svy calls in the future.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 30 of file SettingsDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Survey\Settings\SettingsDBRepository::__construct ( InternalDataService  $data,
\ilDBInterface  $db 
)

Definition at line 35 of file SettingsDBRepository.php.

38 {
39 $this->db = $db;
40 $this->set_factory = $data->settings();
41 }

References $data, and ILIAS\Survey\Settings\SettingsDBRepository\$db.

Member Function Documentation

◆ getAccessSettings()

ILIAS\Survey\Settings\SettingsDBRepository::getAccessSettings ( array  $survey_ids)
Parameters
int[]$survey_ids
Returns
AccessSettings[]

Definition at line 105 of file SettingsDBRepository.php.

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 }
toUnixTS(string $date)
Unix time from survey date.
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
in(string $field, array $values, bool $negate=false, string $type="")

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ getObjIdsForSurveyIds()

ILIAS\Survey\Settings\SettingsDBRepository::getObjIdsForSurveyIds ( array  $survey_ids)
Parameters
int[]$survey_ids
Returns
array<int,int>

Definition at line 69 of file SettingsDBRepository.php.

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 }

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ hasEnded()

ILIAS\Survey\Settings\SettingsDBRepository::hasEnded ( array  $survey_ids)

Check if surveys have ended.

Parameters
int[]$survey_idssurvey IDs
Returns
bool[] has ended true/false

Definition at line 48 of file SettingsDBRepository.php.

48 : 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 }

References ILIAS\Survey\Settings\SettingsDBRepository\$db, ilDBInterface\fetchAssoc(), ilDBInterface\in(), ILIAS\Repository\int(), ilDBInterface\queryF(), and ILIAS\Survey\Settings\SettingsDBRepository\toUnixTS().

+ Here is the call graph for this function:

◆ toUnixTS()

ILIAS\Survey\Settings\SettingsDBRepository::toUnixTS ( string  $date)
protected

Unix time from survey date.

Parameters
string
Returns
int

Definition at line 92 of file SettingsDBRepository.php.

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 }

Referenced by ILIAS\Survey\Settings\SettingsDBRepository\hasEnded().

+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ILIAS\Survey\Settings\SettingsDBRepository::$db
protected

◆ $set_factory

SettingsFactory ILIAS\Survey\Settings\SettingsDBRepository::$set_factory
protected

Definition at line 33 of file SettingsDBRepository.php.


The documentation for this class was generated from the following file: