ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
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.

References ILIAS\Survey\Settings\SettingsDBRepository\$db, and ILIAS\Survey\InternalDataService\settings().

38  {
39  $this->db = $db;
40  $this->set_factory = $data->settings();
41  }
+ Here is the call graph for this function:

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.

References ILIAS\Survey\Settings\SettingsDBRepository\$db, ILIAS\LTI\ToolProvider\$settings, ILIAS\Repository\int(), ilDBInterface\queryF(), and ILIAS\Survey\Settings\SettingsDBRepository\toUnixTS().

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  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
fetchAssoc(ilDBStatement $statement)
toUnixTS(string $date)
Unix time from survey date.
queryF(string $query, array $types, array $values)
in(string $field, array $values, bool $negate=false, string $type="")
+ 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.

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

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  }
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
in(string $field, array $values, bool $negate=false, string $type="")
+ 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_ids survey IDs
Returns
bool[] has ended true/false

Definition at line 48 of file SettingsDBRepository.php.

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

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

Referenced by ILIAS\Survey\Settings\SettingsDBRepository\getAccessSettings(), and ILIAS\Survey\Settings\SettingsDBRepository\hasEnded().

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  }
+ Here is the caller graph for this function:

Field Documentation

◆ $db

◆ $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: