ILIAS  release_8 Revision v8.24
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: feed.php:28

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 234 of file class.RunDBRepository.php.

239 : int {
240 $db = $this->db;
241
242 $next_id = $db->nextId('svy_finished');
243 $affectedRows = $db->manipulateF(
244 "INSERT INTO svy_finished (finished_id, survey_fi, user_fi, anonymous_id, state, tstamp, appr_id) " .
245 "VALUES (%s, %s, %s, %s, %s, %s, %s)",
246 array('integer','integer','integer','text','text','integer','integer'),
247 array($next_id, $survey_id, $user_id, $code, 0, time(), $appraisee_id)
248 );
249
250 return $next_id;
251 }
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 256 of file class.RunDBRepository.php.

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

References $id.

◆ getById()

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

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

211 : ?Run {
212 $db = $this->db;
213
214 $sql = "SELECT * FROM svy_finished" .
215 " WHERE finished_id = " . $db->quote($run_id, "integer");
216 $set = $db->query($sql);
217 while ($row = $db->fetchAssoc($set)) {
218 return $this->data->run((int) $row["survey_fi"], (int) $row["user_fi"])
219 ->withId((int) $row["finished_id"])
220 ->withFinished((bool) $row["state"])
221 ->withCode((string) $row["anonymous_id"])
222 ->withTimestamp((int) $row["tstamp"])
223 ->withAppraiseeId((int) $row["appr_id"])
224 ->withLastPage((int) $row["lastpage"]);
225 }
226 return null;
227 }
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
130 if ($code !== "") { // #15031 - should not matter if code was used by registered or anonymous (each code must be unique)
131 $set = $db->queryF(
132 "SELECT * FROM svy_finished" .
133 " WHERE survey_fi = %s AND anonymous_id = %s AND appr_id = %s",
134 array('integer', 'text', 'integer'),
135 array($survey_id, $code, $appr_id)
136 );
137 } else {
138 $set = $db->queryF(
139 "SELECT * FROM svy_finished" .
140 " WHERE survey_fi = %s AND user_fi = %s AND appr_id = %s",
141 array('integer', 'integer', 'integer'),
142 array($survey_id, $user_id, $appr_id)
143 );
144 }
145 if ($rec = $db->fetchAssoc($set)) {
146 return (int) $rec["finished_id"];
147 }
148 return null;
149 }
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 171 of file class.RunDBRepository.php.

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

◆ getState()

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

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

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

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 267 of file class.RunDBRepository.php.

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

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: