ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository Class Reference

Repository for suggested solutions. More...

+ Inheritance diagram for ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository:
+ Collaboration diagram for ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository:

Public Member Functions

 __construct (\ilDBInterface $db)
 
 create (int $question_id, string $type)
 
 selectFor (int $question_id)
 return assQuestionSuggestedSolution[] More...
 
 update (array $suggested_solutions)
 
 delete (int $suggested_solution_id)
 
 deleteForQuestion (int $question_id)
 
 syncForQuestion (int $source_question_id, int $target_question_id)
 

Data Fields

const TABLE_SUGGESTED_SOLUTIONS = 'qpl_sol_sug'
 

Protected Member Functions

 buildSuggestedSolution (int $id, int $question_id, string $internal_link, string $import_id, int $subquestion_index, string $type, string $value, \DateTimeImmutable $last_update)
 
 getNow ()
 
 additionalOnDelete (int $question_id)
 
 additionalOnStore (assQuestionSuggestedSolution $solution)
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::__construct ( \ilDBInterface  $db)

Member Function Documentation

◆ additionalOnDelete()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::additionalOnDelete ( int  $question_id)
protected

Definition at line 197 of file assQuestionSuggestedSolutionsDatabaseRepository.php.

References ilInternalLink\_deleteAllLinksOfSource().

Referenced by ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\deleteForQuestion().

197  : void
198  {
199  \ilInternalLink::_deleteAllLinksOfSource("qst", $question_id);
200  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ additionalOnStore()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::additionalOnStore ( assQuestionSuggestedSolution  $solution)
protected

Definition at line 202 of file assQuestionSuggestedSolutionsDatabaseRepository.php.

References ilInternalLink\_saveLink(), ILIAS\TA\Questions\assQuestionSuggestedSolution\getQuestionId(), ILIAS\Repository\int(), and ILIAS\TA\Questions\assQuestionSuggestedSolution\isOfTypeLink().

Referenced by ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\update().

202  : void
203  {
204  if ($solution->isOfTypeLink()) {
205  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution->getInternalLink(), $matches)) {
206  \ilInternalLink::_saveLink("qst", $solution->getQuestionId(), $matches[2], (int) $matches[3], (int) $matches[1]);
207  }
208  }
209  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildSuggestedSolution()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::buildSuggestedSolution ( int  $id,
int  $question_id,
string  $internal_link,
string  $import_id,
int  $subquestion_index,
string  $type,
string  $value,
\DateTimeImmutable  $last_update 
)
protected

Definition at line 155 of file assQuestionSuggestedSolutionsDatabaseRepository.php.

References ILIAS\TA\Questions\assQuestionSuggestedSolution\TYPE_FILE, ILIAS\TA\Questions\assQuestionSuggestedSolution\TYPE_GLOSARY_TERM, ILIAS\TA\Questions\assQuestionSuggestedSolution\TYPE_LM, ILIAS\TA\Questions\assQuestionSuggestedSolution\TYPE_LM_CHAPTER, and ILIAS\TA\Questions\assQuestionSuggestedSolution\TYPE_LM_PAGE.

Referenced by ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\create(), assQuestionSuggestedSolutionRepoMock\getSolution(), and ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\selectFor().

164  : assQuestionSuggestedSolution {
165  switch ($type) {
167  $suggestion_class = assSuggestedSolutionFile::class;
168  break;
173  $suggestion_class = assSuggestedSolutionLink::class;
174  $value = $internal_link;
175  break;
176  default:
177  throw new \LogicException('invalid suggestion-type in repo.');
178  }
179 
180  return new $suggestion_class(
181  $id,
182  $question_id,
183  $subquestion_index,
184  $import_id,
185  $last_update,
186  $type,
187  $value
188  );
189  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ create()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::create ( int  $question_id,
string  $type 
)

Definition at line 39 of file assQuestionSuggestedSolutionsDatabaseRepository.php.

References ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\buildSuggestedSolution(), and ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\getNow().

39  : assQuestionSuggestedSolution
40  {
41  $solution = $this->buildSuggestedSolution(
42  -1,
43  $question_id,
44  '',
45  '',
46  0,
47  $type,
48  '',
49  $this->getNow()
50  );
51  return $solution;
52  }
buildSuggestedSolution(int $id, int $question_id, string $internal_link, string $import_id, int $subquestion_index, string $type, string $value, \DateTimeImmutable $last_update)
+ Here is the call graph for this function:

◆ delete()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::delete ( int  $suggested_solution_id)

Definition at line 127 of file assQuestionSuggestedSolutionsDatabaseRepository.php.

127  : void
128  {
129  $query = 'DELETE FROM ' . self::TABLE_SUGGESTED_SOLUTIONS . PHP_EOL
130  . 'WHERE suggested_solution_id = ' . $this->db->quote($suggested_solution_id, 'integer');
131  $this->db->manipulate($query);
132  }

◆ deleteForQuestion()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::deleteForQuestion ( int  $question_id)

Definition at line 134 of file assQuestionSuggestedSolutionsDatabaseRepository.php.

References ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\additionalOnDelete().

Referenced by ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\syncForQuestion().

134  : void
135  {
136  $query = 'DELETE FROM ' . self::TABLE_SUGGESTED_SOLUTIONS . PHP_EOL
137  . 'WHERE question_fi = ' . $this->db->quote($question_id, 'integer');
138  $this->db->manipulate($query);
139  $this->additionalOnDelete($question_id);
140  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNow()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::getNow ( )
protected

Definition at line 191 of file assQuestionSuggestedSolutionsDatabaseRepository.php.

Referenced by ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\create(), and ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\update().

191  : \DateTimeImmutable
192  {
193  return new \DateTimeImmutable();
194  }
+ Here is the caller graph for this function:

◆ selectFor()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::selectFor ( int  $question_id)

return assQuestionSuggestedSolution[]

Definition at line 57 of file assQuestionSuggestedSolutionsDatabaseRepository.php.

References ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\buildSuggestedSolution().

Referenced by ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\syncForQuestion().

57  : array
58  {
59  $ret = [];
60  $query = 'SELECT' . PHP_EOL
61  . 'suggested_solution_id, question_fi, internal_link, import_id, '
62  . 'subquestion_index, type, tstamp, value' . PHP_EOL
63  . 'FROM ' . self::TABLE_SUGGESTED_SOLUTIONS . PHP_EOL
64  . 'WHERE question_fi = ' . $this->db->quote($question_id, 'integer');
65 
66  $result = $this->db->query($query);
67 
68  while ($row = $this->db->fetchAssoc($result)) {
69  $last_update = \DateTimeImmutable::createFromFormat('U', (string) $row['tstamp']);
70 
71  if ($row['type'] === null || $row['type'] === '' || $row['type'] === 'text') {
72  continue;
73  }
74 
75  $ret[] = $this->buildSuggestedSolution(
76  (int) $row['suggested_solution_id'],
77  (int) $row['question_fi'],
78  (string) $row['internal_link'],
79  (string) $row['import_id'],
80  (int) $row['subquestion_index'],
81  (string) $row['type'],
82  (string) $row['value'],
83  $last_update
84  );
85  }
86 
87  return $ret;
88  }
buildSuggestedSolution(int $id, int $question_id, string $internal_link, string $import_id, int $subquestion_index, string $type, string $value, \DateTimeImmutable $last_update)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ syncForQuestion()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::syncForQuestion ( int  $source_question_id,
int  $target_question_id 
)

Definition at line 142 of file assQuestionSuggestedSolutionsDatabaseRepository.php.

References ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\deleteForQuestion(), ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\selectFor(), and ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\update().

142  : void
143  {
144  if ($source_question_id === $target_question_id) {
145  throw new \LogicException('do not sync with same question');
146  }
147  $this->deleteForQuestion($target_question_id);
148  $suggested_solutions = [];
149  foreach ($this->selectFor($source_question_id) as $solution) {
150  $suggested_solutions[] = $solution->withQuestionId($target_question_id);
151  }
152  $this->update($suggested_solutions);
153  }
+ Here is the call graph for this function:

◆ update()

ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::update ( array  $suggested_solutions)

Definition at line 90 of file assQuestionSuggestedSolutionsDatabaseRepository.php.

References ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\additionalOnStore(), and ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\getNow().

Referenced by ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository\syncForQuestion().

90  : void
91  {
92  foreach ($suggested_solutions as $solution) {
93  if (!is_a($solution, assQuestionSuggestedSolution::class)) {
94  throw new \Exception('cannot update other than assQuestionSuggestedSolution');
95  }
96  };
97 
98  foreach ($suggested_solutions as $solution) {
99  $query = 'DELETE FROM ' . self::TABLE_SUGGESTED_SOLUTIONS . PHP_EOL
100  . 'WHERE question_fi = ' . $this->db->quote($solution->getQuestionId(), 'integer') . PHP_EOL
101  . 'AND subquestion_index = ' . $this->db->quote($solution->getSubQuestionIndex(), 'integer');
102  $this->db->manipulate($query);
103 
104  $next_id = $this->db->nextId(self::TABLE_SUGGESTED_SOLUTIONS);
105  $internal_link = '';
106  if ($solution->isOfTypeLink()) {
107  $internal_link = $solution->getInternalLink();
108  }
109  $this->db->insert(
110  self::TABLE_SUGGESTED_SOLUTIONS,
111  [
112  'suggested_solution_id' => ['integer', $next_id],
113  'question_fi' => ['integer', $solution->getQuestionId()],
114  'type' => ['text',$solution->getType()],
115  'value' => ['clob', $solution->getStorableValue()],
116  'internal_link' => ['text', $internal_link],
117  'import_id' => ['text', $solution->getImportId()],
118  'subquestion_index' => ['integer', $solution->getSubquestionIndex() ],
119  'tstamp' => ['integer', $this->getNow()->format('U')]
120  ]
121  );
122 
123  $this->additionalOnStore($solution);
124  }
125  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::$db
protected

◆ TABLE_SUGGESTED_SOLUTIONS

const ILIAS\TA\Questions\assQuestionSuggestedSolutionsDatabaseRepository::TABLE_SUGGESTED_SOLUTIONS = 'qpl_sol_sug'

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