1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Egzaminer\Controller; |
4
|
|
|
|
5
|
|
|
use Egzaminer\Model\AnswersModel; |
6
|
|
|
use Egzaminer\Model\QuestionEditModel; |
7
|
|
|
use Egzaminer\Model\QuestionsModel; |
8
|
|
|
|
9
|
|
|
class QuestionEditController extends AdminController |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Edit question. |
13
|
|
|
* |
14
|
|
|
* GET /admin/exam/edit/[i:id]/question/edit/[i:qid] |
15
|
|
|
* |
16
|
|
|
* @param int $examID Exam id |
17
|
|
|
* @param int $questionID Question ID |
18
|
|
|
* |
19
|
|
|
* @return string |
20
|
|
|
*/ |
21
|
|
|
public function editAction(int $examID, int $questionID): string |
22
|
|
|
{ |
23
|
|
|
$question = (new QuestionsModel($this->get('dbh')))->getByQuestionId($questionID); |
24
|
|
|
$answers = (new AnswersModel($this->get('dbh')))->getAnswersByOneQuestionId($questionID); |
25
|
|
|
|
26
|
|
|
return $this->render('admin/question', [ |
27
|
|
|
'title' => 'Edycja pytania', |
28
|
|
|
'id' => $questionID, |
29
|
|
|
'examID' => $examID, |
30
|
|
|
'question' => $question, |
31
|
|
|
'answers' => $answers, |
32
|
|
|
'templateType' => 'edit', |
33
|
|
|
]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Edit question post action. |
38
|
|
|
* |
39
|
|
|
* POST /admin/exam/edit/[i:id]/question/edit/[i:qid] |
40
|
|
|
* |
41
|
|
|
* @param int $examID Exam id |
42
|
|
|
* @param int $questionID Question ID |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
public function postEditAction(int $examID, int $questionID) |
47
|
|
|
{ |
48
|
|
|
$editModel = new QuestionEditModel($this->get('dbh')); |
49
|
|
|
|
50
|
|
|
if ($editModel->edit( |
51
|
|
|
$questionID, |
52
|
|
|
$this->getFromRequest('post'), |
53
|
|
|
$this->getFromRequest('files', 'image'), |
54
|
|
|
$this->get('rootDir') |
55
|
|
|
)) { |
56
|
|
|
$this->setMessage('success', 'Uaktualniono pomyślnie!'); |
57
|
|
|
} else { |
58
|
|
|
$this->setMessage('warning', 'Coś się zepsuło!'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->redirect('/admin/exam/edit/'.$examID.'/question/edit/'.$questionID); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|