Passed
Push — master ( 6084dc...68443e )
by Mihail
05:40
created

Comments::actionAnswerlist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Apps\Controller\Admin;
4
5
6
use Apps\ActiveRecord\CommentPost;
7
use Apps\Model\Admin\Comments\FormSettings;
8
use Extend\Core\Arch\AdminController;
9
use Ffcms\Core\App;
10
use Ffcms\Core\Helper\HTML\SimplePagination;
11
12
/**
13
 * Class Comments. Admin controller for management user comments.
14
 * This class provide general admin implementation of control for user comments and its settings.
15
 * @package Apps\Controller\Admin
16
 */
17
class Comments extends AdminController
18
{
19
    const VERSION = 0.1;
20
    const ITEM_PER_PAGE = 10;
21
22
    public $type = 'widget';
23
24
    /**
25
     * List user comments with pagination
26
     * @return string
27
     * @throws \Ffcms\Core\Exception\SyntaxException
28
     */
29 View Code Duplication
    public function actionIndex()
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...
30
    {
31
        // set current page and offset
32
        $page = (int)App::$Request->query->get('page');
33
        $offset = $page * self::ITEM_PER_PAGE;
34
35
        // initialize active record model
36
        $query = new CommentPost();
37
38
        // make pagination
39
        $pagination = new SimplePagination([
40
            'url' => ['comments/index'],
41
            'page' => $page,
42
            'step' => self::ITEM_PER_PAGE,
43
            'total' => $query->count()
0 ignored issues
show
Documentation Bug introduced by
The method count does not exist on object<Apps\ActiveRecord\CommentPost>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
44
        ]);
45
46
        // get result as active records object with offset
47
        $records = $query->orderBy('id', 'desc')->skip($offset)->take(self::ITEM_PER_PAGE)->get();
0 ignored issues
show
Documentation Bug introduced by
The method orderBy does not exist on object<Apps\ActiveRecord\CommentPost>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
48
49
        // render output view
50
        return App::$View->render('index', [
51
            'records' => $records,
52
            'pagination' => $pagination
53
        ]);
54
    }
55
56
    public function actionAnswerlist()
57
    {
58
59
    }
60
61
    /**
62
     * Comment widget global settings
63
     * @return string
64
     * @throws \Ffcms\Core\Exception\SyntaxException
65
     */
66 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...
67
    {
68
        // initialize settings model
69
        $model = new FormSettings($this->getConfigs());
70
71
        // check if form is send
72
        if ($model->send()) {
73
            if ($model->validate()) {
74
                $this->setConfigs($model->getAllProperties());
75
                App::$Session->getFlashBag()->add('success', __('Settings is successful updated'));
76
                App::$Response->redirect('comments/index');
77
            } else {
78
                App::$Session->getFlashBag()->add('error', __('Form validation is failed'));
79
            }
80
        }
81
82
        // render view
83
        return App::$View->render('settings', [
84
            'model' => $model
85
        ]);
86
    }
87
88
89
90
91
}