Completed
Push — master ( ac011d...56c397 )
by Mikołaj
03:19
created

QuestionAddController::addAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 15
nc 1
nop 1
1
<?php
2
3
namespace Egzaminer\Controller;
4
5
use Egzaminer\Model\QuestionAddModel;
6
7
class QuestionAddController extends AdminController
8
{
9
    /**
10
     * Add question.
11
     *
12
     * GET /admin/exam/edit/[i:tid]/question/add
13
     *
14
     * @param int $examID Exam id
15
     *
16
     * @return void
17
     */
18
    public function addAction($examID)
19
    {
20
        $question = [
21
            'content' => '',
22
            'correct' => '',
23
            'image'   => '',
24
        ];
25
        $answers = [
26
            ['content' => '', 'id' => '1'],
27
            ['content' => '', 'id' => '2'],
28
            ['content' => '', 'id' => '3'],
29
            ['content' => '', 'id' => '4'],
30
        ];
31
32
        $this->render('admin/question', [
33
            'title'    => 'Dodawanie pytania',
34
            'examID'   => $examID,
35
            'question' => $question,
36
            'answers'  => $answers,
37
        ]);
38
    }
39
40
    /**
41
     * Add question post action.
42
     *
43
     * POST /admin/exam/edit/[i:tid]/question/add
44
     *
45
     * @param int $examID Exam id
46
     *
47
     * @return void
48
     */
49 View Code Duplication
    public function postAddAction($examID)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $model = new QuestionAddModel($this->get('dbh'));
52
53
        if ($id = $model->add($examID, $this->getFromRequest('post'))) {
54
            $this->setMessage('success', 'Dodano pomyślnie!');
55
            $this->redirect('/admin/exam/edit/'.$examID.'/question/edit/'.$id);
56
57
            return;
58
        }
59
60
        $this->setMessage('warning', 'Coś się zepsuło!');
61
        $this->redirect('/admin/exam/edit/'.$examID.'/question/add');
62
    }
63
}
64