ILIAS  release_8 Revision v8.24
assOrderingQuestionDatabaseRepository.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
27{
28 public const TABLE_NAME_BASE = 'qpl_questions';
29 public const TABLE_NAME_QUESTIONS = 'qpl_qst_ordering';
30 public const TABLE_NAME_ANSWERS = 'qpl_a_ordering';
31
32 protected \ilDBInterface $db;
33
34 public function __construct(\ilDBInterface $db)
35 {
36 $this->db = $db;
37 }
38
39 public function getOrderingList(int $question_id): \ilAssOrderingElementList
40 {
41 return $this->buildOrderingList($question_id);
42 }
43
44 public function updateOrderingList(\ilAssOrderingElementList $list): void
45 {
46 $atom_query = $this->db->buildAtomQuery();
47 $atom_query->addTableLock(self::TABLE_NAME_ANSWERS);
48 $atom_query->addTableLock(self::TABLE_NAME_ANSWERS . '_seq');
49
50 $atom_query->addQueryCallable(
51 function (\ilDBInterface $db) use ($list) {
53 foreach ($list->getElements() as $order_element) {
54 $this->insertOrderingElement($order_element, $list->getQuestionId());
55 }
56 }
57 );
58 $atom_query->run();
59 }
60
61 protected function buildOrderingList(
62 int $question_id
64 $elements = $this->getOrderingElementsForList($question_id);
65 return new \ilAssOrderingElementList($question_id, $elements);
66 }
67
71 protected function getOrderingElementsForList(int $question_id): array
72 {
73 $query = 'SELECT' . PHP_EOL
74 . 'answer_id, answertext, solution_key, random_id, depth, position' . PHP_EOL
75 . 'FROM ' . self::TABLE_NAME_ANSWERS . PHP_EOL
76 . 'WHERE question_fi=' . $question_id . PHP_EOL
77 . 'ORDER BY position ASC';
78
79 $elements = [];
80 $res = $this->db->query($query);
81 while ($row = $this->db->fetchAssoc($res)) {
82 $elements[] = $this->buildOrderingElement(
83 (int) $row['answer_id'],
84 (int) $row['random_id'],
85 (int) $row['solution_key'],
86 (int) $row['position'],
87 (int) $row['depth'],
88 (string) $row['answertext']
89 );
90 }
91 return $elements;
92 }
93
94 protected function deleteOrderingElements(int $question_id): void
95 {
96 $query = 'DELETE FROM ' . self::TABLE_NAME_ANSWERS . PHP_EOL
97 . 'WHERE question_fi = ' . $question_id;
98 $this->db->manipulate($query);
99 }
100
101 protected function insertOrderingElement(\ilAssOrderingElement $order_element, int $question_id): void
102 {
103 $next_id = $this->db->nextId(self::TABLE_NAME_ANSWERS);
104 $values = array(
105 'answer_id' => ['integer', $next_id],
106 'question_fi' => ['integer', $question_id],
107 'answertext' => ['text', $order_element->getContent()],
108 'solution_key' => ['integer', $order_element->getSolutionIdentifier()],
109 'random_id' => ['integer', $order_element->getRandomIdentifier()],
110 'position' => ['integer', $order_element->getPosition()],
111 'depth' => ['integer', $order_element->getIndentation()],
112 'tstamp' => ['integer', $this->getTime()]
113 );
114 $this->db->insert(self::TABLE_NAME_ANSWERS, $values);
115 }
116
117 protected function getTime()
118 {
119 return time();
120 }
121
122 protected function buildOrderingElement(
123 int $answer_id,
124 int $random_identifier,
125 int $solution_identifier,
126 int $position,
127 int $indentation,
128 string $content
130 return (new \ilAssOrderingElement($answer_id))
131 ->withRandomIdentifier($random_identifier)
132 ->withSolutionIdentifier($solution_identifier)
133 ->withPosition($position)
134 ->withIndentation($indentation)
135 ->withContent($content);
136 }
137}
repository for assOrderingQuestion (the answer elements within, at least...)
insertOrderingElement(\ilAssOrderingElement $order_element, int $question_id)
buildOrderingElement(int $answer_id, int $random_identifier, int $solution_identifier, int $position, int $indentation, string $content)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query