Passed
Push — master ( 81f334...c86e8c )
by Mihail
03:35
created

Comments::actionRead()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Apps\Controller\Admin;
4
5
use Apps\ActiveRecord\CommentPost;
6
use Apps\Model\Admin\Comments\FormSettings;
7
use Extend\Core\Arch\AdminController;
8
use Ffcms\Core\App;
9
use Ffcms\Core\Exception\NotFoundException;
10
11
/**
12
 * Class Comments. Admin controller for management user comments.
13
 * This class provide general admin implementation of control for user comments and its settings.
14
 * @package Apps\Controller\Admin
15
 */
16
class Comments extends AdminController
17
{
18
    const VERSION = '1.0.0';
19
    const ITEM_PER_PAGE = 10;
20
21
    const TYPE_COMMENT = 'comment';
22
    const TYPE_ANSWER = 'answer';
23
24
    public $type = 'widget';
25
26
    // heavy actions import
27
    use Comments\ActionIndex {
28
        index as actionIndex;
29
    }
30
31
    use Comments\ActionEdit {
32
        edit as actionEdit;
33
    }
34
35
    use Comments\ActionDelete {
36
        delete as actionDelete;
37
    }
38
39
    use Comments\ActionPublish {
40
        publish as actionPublish;
41
    }
42
43
    use Comments\ActionAnswerList {
44
        answerList as actionAnswerlist;
45
    }
46
47
    /**
48
     * List comment - read comment and list answers
49
     * @param int $id
50
     * @return string
51
     * @throws NotFoundException
52
     * @throws \Ffcms\Core\Exception\SyntaxException
53
     */
54
    public function actionRead($id)
55
    {
56
        // find object in active record model
57
        $record = CommentPost::find($id);
58
        if ($record === null || $record === false) {
59
            throw new NotFoundException(__('Comment is not founded'));
60
        }
61
62
        // render response
63
        return $this->view->render('comment_read', [
64
            'record' => $record
65
        ]);
66
    }
67
68
    /**
69
     * Comment widget global settings
70
     * @return string
71
     * @throws \Ffcms\Core\Exception\SyntaxException
72
     */
73 View Code Duplication
    public function actionSettings()
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...
74
    {
75
        // initialize settings model
76
        $model = new FormSettings($this->getConfigs());
77
78
        // check if form is send
79
        if ($model->send()) {
80
            if ($model->validate()) {
81
                $this->setConfigs($model->getAllProperties());
82
                App::$Session->getFlashBag()->add('success', __('Settings is successful updated'));
83
                $this->response->redirect('comments/index');
84
            } else {
85
                App::$Session->getFlashBag()->add('error', __('Form validation is failed'));
86
            }
87
        }
88
89
        // render view
90
        return $this->view->render('settings', [
91
            'model' => $model
92
        ]);
93
    }
94
}
95