Grid   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 28
c 2
b 0
f 0
dl 0
loc 55
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildFilter() 0 7 1
A decoratePagination() 0 3 1
A init() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\PropellerAdmin\Decorator;
6
7
use AbterPhp\Framework\Decorator\Decorator;
8
use AbterPhp\Framework\Decorator\Rule;
9
use AbterPhp\Framework\Grid\Cell\Sortable;
10
use AbterPhp\Framework\Grid\Filter\Filter;
11
use AbterPhp\Framework\Grid\Pagination\Pagination;
12
13
class Grid extends Decorator
14
{
15
    const FILTER_WRAPPER_CLASS = 'form-group pmd-textfield pmd-textfield-floating-label';
16
    const FILTER_LABEL_CLASS   = 'control-label';
17
    const FILTER_INPUT_CLASS   = 'form-control';
18
19
    const FILTER_ATTR_DATA_TOGGLE    = 'data-toggle';
20
    const FILTER_ATTR_DATA_PLACEMENT = 'data-placement';
21
    const FILTER_DATA_TOGGLE_TOOLTIP = 'tooltip';
22
    const FILTER_DATA_PLACEMENT_LEFT = 'left';
23
24
    const PAGINATION_CLASS    = 'grid-pagination row';
25
    const PAGINATION_TEMPLATE = '<div class="gp-numbers col-md-6">%1$s</div><div class="gp-options col-md-6">%2$s%3$s</div>'; // nolint
26
27
    const HELP_BLOCK_CLASS = 'help-block';
28
29
    const CARET_CLASS = 'caret';
30
    const CARET_ACTIVE_CLASS = 'caret-active';
31
    const CARET_DOWN_CLASS = 'caret-down';
32
    const CARET_UP_CLASS = 'caret-up';
33
34
    /**
35
     * @return $this
36
     */
37
    public function init(): Decorator
38
    {
39
        $this->rules[] = new Rule([], Filter::class, [static::FILTER_INPUT_CLASS], [], [$this, 'buildFilter']);
40
        $this->rules[] = new Rule([], Pagination::class, [static::PAGINATION_CLASS], [], [$this, 'decoratePagination']);
41
        $this->rules[] = new Rule([Filter::INTENT_HELP_BLOCK], null, [static::HELP_BLOCK_CLASS]);
42
        $this->rules[] = new Rule([Sortable::BTN_INTENT_SHOARTING], null, [static::CARET_CLASS]);
43
        $this->rules[] = new Rule([Sortable::BTN_INTENT_CARET_ACTIVE], null, [static::CARET_ACTIVE_CLASS]);
44
        $this->rules[] = new Rule([Sortable::BTN_INTENT_CARET_DOWN], null, [static::CARET_DOWN_CLASS]);
45
        $this->rules[] = new Rule([Sortable::BTN_INTENT_CARET_UP], null, [static::CARET_UP_CLASS]);
46
47
        return $this;
48
    }
49
50
    /**
51
     * @param Filter $input
52
     */
53
    public function buildFilter(Filter $input)
54
    {
55
        $input->setAttribute(static::FILTER_ATTR_DATA_TOGGLE, static::FILTER_DATA_TOGGLE_TOOLTIP);
56
        $input->setAttribute(static::FILTER_ATTR_DATA_PLACEMENT, static::FILTER_DATA_PLACEMENT_LEFT);
57
58
        $input->getWrapper()->appendToClass(static::FILTER_WRAPPER_CLASS);
59
        $input->getLabel()->appendToClass(static::FILTER_LABEL_CLASS);
60
    }
61
62
    /**
63
     * @param Pagination $pagination
64
     */
65
    public function decoratePagination(Pagination $pagination)
66
    {
67
        $pagination->setTemplate(static::PAGINATION_TEMPLATE);
68
    }
69
}
70