ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ILIAS\Survey\Settings\SettingsDBRepository Class Reference

Survey settings db repository. More...

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

Public Member Functions

 __construct (\ilDBInterface $db=null, SettingsFactory $set_factory=null)
 Constructor. More...
 
 hasEnded (array $survey_ids)
 Check if surveys have ended. More...
 
 getObjIdsForSurveyIds (array $survey_ids)
 Check if surveys have ended. More...
 
 getAccessSettings (array $survey_ids)
 Get access settings. More...
 

Protected Member Functions

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

Protected Attributes

 $db
 
 $set_factory
 

Detailed Description

Survey settings db repository.

This should wrap all svy_svy calls in the future.

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

Definition at line 14 of file SettingsDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Survey\Settings\SettingsDBRepository::__construct ( \ilDBInterface  $db = null,
SettingsFactory  $set_factory = null 
)

Constructor.

Definition at line 29 of file SettingsDBRepository.php.

References ILIAS\Survey\Settings\SettingsDBRepository\$db, $DIC, and ILIAS\Survey\Settings\SettingsDBRepository\$set_factory.

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()
39  : $set_factory;
40  }
$DIC
Definition: xapitoken.php:46

Member Function Documentation

◆ getAccessSettings()

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

Get access settings.

Parameters
int[]$survey_ids
Returns
AccessSettings[]

Definition at line 110 of file SettingsDBRepository.php.

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

110  : 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  }
toUnixTS($date)
Unix time from survey date.
+ Here is the call graph for this function:

◆ getObjIdsForSurveyIds()

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

Check if surveys have ended.

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

Definition at line 71 of file SettingsDBRepository.php.

References ILIAS\Survey\Settings\SettingsDBRepository\$db.

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

◆ 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, 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"]] = !($rec["enddate"] == 0 || $this->toUnixTS($rec["enddate"]) > time());
61  }
62  return $has_ended;
63  }
toUnixTS($date)
Unix time from survey date.
+ Here is the call graph for this function:

◆ toUnixTS()

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

Unix time from survey date.

Parameters
string
Returns
int

Definition at line 94 of file SettingsDBRepository.php.

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

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

Field Documentation

◆ $db

◆ $set_factory

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

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