ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Survey\Execution\RunDBRepository Class Reference

DB repo for survey run. More...

+ Collaboration diagram for ILIAS\Survey\Execution\RunDBRepository:

Public Member Functions

 __construct (InternalDataService $data, ?\ilDBInterface $db=null)
 
 getFinishedSurveysOfUser (int $user_id)
 Get all finished surveys of a user. More...
 
 getUnfinishedSurveysOfUser (int $user_id)
 Get all unfinished surveys of a user. More...
 
 getFinishedAppraiseesForRater (int $rater_id)
 
 getCurrentRunId (int $survey_id, int $user_id, string $code="", int $appr_id=0)
 
 getState (int $run_id)
 
 getRunsForUser (int $survey_id, int $user_id, string $code="")
 
 getById (int $run_id)
 
 add (int $survey_id, int $user_id, string $code, int $appraisee_id=0)
 Add new run. More...
 
 addTime (int $run_id, int $time, int $first_question)
 Add time record. More...
 
 updateTime (int $run_id, int $time, int $entered_time)
 

Data Fields

const NOT_STARTED = -1
 
const STARTED_NOT_FINISHED = 0
 
const FINISHED = 1
 

Protected Attributes

ilDBInterface $db
 
InternalDataService $data
 

Detailed Description

DB repo for survey run.

Table svy_finished. Please note that there are lots of accesses to svy_finished in other classes.

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

Definition at line 31 of file class.RunDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Survey\Execution\RunDBRepository::__construct ( InternalDataService  $data,
?\ilDBInterface  $db = null 
)

Definition at line 40 of file class.RunDBRepository.php.

43 {
44 global $DIC;
45
46 $this->data = $data;
47 $this->db = (is_null($db))
48 ? $DIC->database()
49 : $db;
50 }
global $DIC
Definition: shib_login.php:26

References ILIAS\Survey\Execution\RunDBRepository\$data, ILIAS\Survey\Execution\RunDBRepository\$db, and $DIC.

Member Function Documentation

◆ add()

ILIAS\Survey\Execution\RunDBRepository::add ( int  $survey_id,
int  $user_id,
string  $code,
int  $appraisee_id = 0 
)

Add new run.

Returns
int run id

Definition at line 236 of file class.RunDBRepository.php.

241 : int {
242 $db = $this->db;
243
244 $next_id = $db->nextId('svy_finished');
245 $affectedRows = $db->manipulateF(
246 "INSERT INTO svy_finished (finished_id, survey_fi, user_fi, anonymous_id, state, tstamp, appr_id) " .
247 "VALUES (%s, %s, %s, %s, %s, %s, %s)",
248 array('integer','integer','integer','text','text','integer','integer'),
249 array($next_id, $survey_id, $user_id, $code, 0, time(), $appraisee_id)
250 );
251
252 return $next_id;
253 }
nextId(string $table_name)
manipulateF(string $query, array $types, array $values)

◆ addTime()

ILIAS\Survey\Execution\RunDBRepository::addTime ( int  $run_id,
int  $time,
int  $first_question 
)

Add time record.

Definition at line 258 of file class.RunDBRepository.php.

258 : void
259 {
260 $db = $this->db;
261 $id = $db->nextId('svy_times');
263 "INSERT INTO svy_times (id, finished_fi, entered_page, left_page, first_question) VALUES (%s, %s, %s, %s,%s)",
264 array('integer','integer', 'integer', 'integer', 'integer'),
265 array($id, $run_id, $time, null, $first_question)
266 );
267 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

◆ getById()

ILIAS\Survey\Execution\RunDBRepository::getById ( int  $run_id)

Definition at line 211 of file class.RunDBRepository.php.

213 : ?Run {
214 $db = $this->db;
215
216 $sql = "SELECT * FROM svy_finished" .
217 " WHERE finished_id = " . $db->quote($run_id, "integer");
218 $set = $db->query($sql);
219 while ($row = $db->fetchAssoc($set)) {
220 return $this->data->run((int) $row["survey_fi"], (int) $row["user_fi"])
221 ->withId((int) $row["finished_id"])
222 ->withFinished((bool) $row["state"])
223 ->withCode((string) $row["anonymous_id"])
224 ->withTimestamp((int) $row["tstamp"])
225 ->withAppraiseeId((int) $row["appr_id"])
226 ->withLastPage((int) $row["lastpage"]);
227 }
228 return null;
229 }
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
fetchAssoc(ilDBStatement $statement)

References ILIAS\Survey\Execution\Run\withId().

+ Here is the call graph for this function:

◆ getCurrentRunId()

ILIAS\Survey\Execution\RunDBRepository::getCurrentRunId ( int  $survey_id,
int  $user_id,
string  $code = "",
int  $appr_id = 0 
)

Definition at line 122 of file class.RunDBRepository.php.

127 : ?int {
128 $db = $this->db;
129 if ($code !== "") { // #15031 - should not matter if code was used by registered or anonymous (each code must be unique)
130 $set = $db->queryF(
131 "SELECT * FROM svy_finished" .
132 " WHERE survey_fi = %s AND anonymous_id = %s AND appr_id = %s",
133 array('integer', 'text', 'integer'),
134 array($survey_id, $code, $appr_id)
135 );
136 } else {
137 if ($user_id === ANONYMOUS_USER_ID) {
138 return null;
139 }
140 $set = $db->queryF(
141 "SELECT * FROM svy_finished" .
142 " WHERE survey_fi = %s AND user_fi = %s AND appr_id = %s",
143 array('integer', 'integer', 'integer'),
144 array($survey_id, $user_id, $appr_id)
145 );
146 }
147 if ($rec = $db->fetchAssoc($set)) {
148 return (int) $rec["finished_id"];
149 }
150 return null;
151 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
queryF(string $query, array $types, array $values)

Referenced by ILIAS\Survey\Execution\RunManager\belongsToFinishedRun(), and ILIAS\Survey\Execution\RunManager\getCurrentRunId().

+ Here is the caller graph for this function:

◆ getFinishedAppraiseesForRater()

ILIAS\Survey\Execution\RunDBRepository::getFinishedAppraiseesForRater ( int  $rater_id)
Parameters
int$rater_id
Returns
array{survey_id: int, appr_id: int}[]

Definition at line 101 of file class.RunDBRepository.php.

103 : array {
104 $db = $this->db;
105
106 $set = $db->queryF(
107 "SELECT survey_fi, appr_id FROM svy_finished " .
108 " WHERE user_fi = %s AND state = %s",
109 ["integer", "integer"],
110 [$rater_id, 1]
111 );
112 $appraisee = [];
113 while ($rec = $db->fetchAssoc($set)) {
114 $appraisee[] = [
115 "survey_id" => (int) $rec["survey_fi"],
116 "appr_id" => (int) $rec["appr_id"]
117 ];
118 }
119 return $appraisee;
120 }

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ getFinishedSurveysOfUser()

ILIAS\Survey\Execution\RunDBRepository::getFinishedSurveysOfUser ( int  $user_id)

Get all finished surveys of a user.

Returns
int[] survey ids

Definition at line 57 of file class.RunDBRepository.php.

59 : array {
60 $db = $this->db;
61
62 $set = $db->queryF(
63 "SELECT survey_fi FROM svy_finished " .
64 " WHERE user_fi = %s AND state = %s",
65 ["integer", "integer"],
66 [$user_id, 1]
67 );
68 $items = [];
69 while ($rec = $db->fetchAssoc($set)) {
70 $items[] = (int) $rec["survey_fi"];
71 }
72 return $items;
73 }

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ getRunsForUser()

ILIAS\Survey\Execution\RunDBRepository::getRunsForUser ( int  $survey_id,
int  $user_id,
string  $code = "" 
)
Returns
Run[]

Definition at line 173 of file class.RunDBRepository.php.

177 : array {
178 $db = $this->db;
179
180 $sql = "SELECT * FROM svy_finished" .
181 " WHERE survey_fi = " . $db->quote($survey_id, "integer");
182 // if proper user id is given, use it or current code
183 if ($user_id !== ANONYMOUS_USER_ID) {
184 $sql .= " AND (user_fi = " . $db->quote($user_id, "integer");
185 if ($code !== "") {
186 $sql .= " OR anonymous_id = " . $db->quote($code, "text");
187 }
188 $sql .= ")";
189 }
190 // use anonymous code to find finished id(s)
191 else {
192 if ($code === "") {
193 return [];
194 }
195 $sql .= " AND anonymous_id = " . $db->quote($code, "text");
196 }
197 $set = $db->query($sql);
198 $runs = [];
199 while ($row = $db->fetchAssoc($set)) {
200 $runs[$row["finished_id"]] = $this->data->run($survey_id, $user_id)
201 ->withId((int) $row["finished_id"])
202 ->withFinished((bool) $row["state"])
203 ->withCode((string) $row["anonymous_id"])
204 ->withTimestamp((int) $row["tstamp"])
205 ->withAppraiseeId((int) $row["appr_id"])
206 ->withLastPage((int) $row["lastpage"]);
207 }
208 return $runs;
209 }

References $user_id.

◆ getState()

ILIAS\Survey\Execution\RunDBRepository::getState ( int  $run_id)

Definition at line 153 of file class.RunDBRepository.php.

155 : int {
156 $db = $this->db;
157
158 $set = $db->queryF(
159 "SELECT * FROM svy_finished" .
160 " WHERE finished_id = %s ",
161 array('integer'),
162 array($run_id)
163 );
164 if ($rec = $db->fetchAssoc($set)) {
165 return (int) $rec["state"];
166 }
167 return self::NOT_STARTED;
168 }

Referenced by ILIAS\Survey\Execution\RunManager\belongsToFinishedRun(), and ILIAS\Survey\Execution\RunManager\getCurrentState().

+ Here is the caller graph for this function:

◆ getUnfinishedSurveysOfUser()

ILIAS\Survey\Execution\RunDBRepository::getUnfinishedSurveysOfUser ( int  $user_id)

Get all unfinished surveys of a user.

Returns
int[] survey ids

Definition at line 79 of file class.RunDBRepository.php.

81 : array {
82 $db = $this->db;
83
84 $set = $db->queryF(
85 "SELECT survey_fi FROM svy_finished " .
86 " WHERE user_fi = %s AND state = %s",
87 ["integer", "integer"],
88 [$user_id, 0]
89 );
90 $items = [];
91 while ($rec = $db->fetchAssoc($set)) {
92 $items[] = (int) $rec["survey_fi"];
93 }
94 return $items;
95 }

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ updateTime()

ILIAS\Survey\Execution\RunDBRepository::updateTime ( int  $run_id,
int  $time,
int  $entered_time 
)

Definition at line 269 of file class.RunDBRepository.php.

269 : void
270 {
271 $db = $this->db;
273 "UPDATE svy_times SET left_page = %s WHERE finished_fi = %s AND entered_page = %s",
274 array('integer', 'integer', 'integer'),
275 array($time, $run_id, $entered_time)
276 );
277 }

Field Documentation

◆ $data

InternalDataService ILIAS\Survey\Execution\RunDBRepository::$data
protected

◆ $db

ilDBInterface ILIAS\Survey\Execution\RunDBRepository::$db
protected

◆ FINISHED

◆ NOT_STARTED

const ILIAS\Survey\Execution\RunDBRepository::NOT_STARTED = -1

Definition at line 33 of file class.RunDBRepository.php.

◆ STARTED_NOT_FINISHED

const ILIAS\Survey\Execution\RunDBRepository::STARTED_NOT_FINISHED = 0

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