ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PassPresentedVariablesRepo.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 public const TABLE_NAME = 'tst_qst_var_presented';
28
29 public function __construct(
30 protected ilDBInterface $db
31 ) {
32 }
33
34 public function getFor(
35 int $question_id,
36 int $active_id,
37 int $pass
38 ): ?array {
39 $query = 'SELECT variable, value FROM ' . self::TABLE_NAME . ' WHERE '
40 . 'question_id = %s AND '
41 . 'active_id = %s AND '
42 . 'pass = %s';
43
44 $result = $this->db->queryF(
45 $query,
46 ['integer','integer','integer'],
47 [$question_id, $active_id, $pass]
48 );
49
50 if($result->numRows() === 0) {
51 return null;
52 }
53
54 $values = [];
55 while ($row = $this->db->fetchAssoc($result)) {
56 $values[$row['variable']] = $row['value'];
57 }
58 return $values;
59 }
60
61 public function store(
62 int $question_id,
63 int $active_id,
64 int $pass,
65 array $values
66 ): void {
67 $query = 'INSERT INTO ' . self::TABLE_NAME
68 . ' (question_id, active_id, pass, variable, value) '
69 . ' VALUES (%s,%s,%s,%s,%s)';
70
71 foreach ($values as $k => $v) {
72 $this->db->manipulateF(
73 $query,
74 ['integer','integer','integer', 'text', 'text'],
75 [$question_id, $active_id, $pass, $k, $v]
76 );
77 }
78 }
79}
Stores random-generated parts of questions in order to present the user with a fixed question during ...
store(int $question_id, int $active_id, int $pass, array $values)
getFor(int $question_id, int $active_id, int $pass)
__construct(protected ilDBInterface $db)
Interface ilDBInterface.