Passed
Push — master ( e7cae8...5047e3 )
by Peter
02:30
created

Page::getCategoryName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Grid\Factory;
6
7
use AbterPhp\Framework\Constant\Html5;
8
use AbterPhp\Framework\Grid\Action\Action;
9
use AbterPhp\Framework\Grid\Component\Actions;
10
use AbterPhp\Framework\Grid\Factory\BaseFactory;
11
use AbterPhp\Framework\Grid\Factory\GridFactory;
12
use AbterPhp\Framework\Grid\Factory\PaginationFactory as PaginationFactory;
13
use AbterPhp\Website\Constant\Routes;
14
use AbterPhp\Website\Domain\Entities\Page as Entity;
15
use AbterPhp\Website\Grid\Factory\Table\Page as Table;
16
use AbterPhp\Website\Grid\Filters\Page as Filters;
17
use Opulence\Routing\Urls\UrlGenerator;
18
19
class Page extends BaseFactory
20
{
21
    const GROUP_ID         = 'page-id';
22
    const GROUP_IDENTIFIER = 'page-identifier';
23
    const GROUP_TITLE      = 'page-title';
24
    const GROUP_CATEGORY   = 'page-category';
25
26
    const GETTER_ID         = 'getId';
27
    const GETTER_IDENTIFIER = 'getIdentifier';
28
    const GETTER_TITLE      = 'getTitle';
29
    const GETTER_CATEGORY   = 'getCategory';
30
31
    /**
32
     * Page constructor.
33
     *
34
     * @param UrlGenerator      $urlGenerator
35
     * @param PaginationFactory $paginationFactory
36
     * @param Table             $tableFactory
37
     * @param GridFactory       $gridFactory
38
     * @param Filters           $filters
39
     */
40
    public function __construct(
41
        UrlGenerator $urlGenerator,
42
        PaginationFactory $paginationFactory,
43
        Table $tableFactory,
44
        GridFactory $gridFactory,
45
        Filters $filters
46
    ) {
47
        parent::__construct($urlGenerator, $paginationFactory, $tableFactory, $gridFactory, $filters);
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function getGetters(): array
54
    {
55
        return [
56
            static::GROUP_ID         => static::GETTER_ID,
57
            static::GROUP_IDENTIFIER => static::GETTER_IDENTIFIER,
58
            static::GROUP_TITLE      => static::GETTER_TITLE,
59
            static::GROUP_CATEGORY   => [$this, 'getCategoryName'],
60
        ];
61
    }
62
63
    /**
64
     * @param Entity $entity
65
     *
66
     * @return string
67
     */
68
    public function getCategoryName(Entity $entity): string
69
    {
70
        if ($entity->getCategory()) {
71
            return $entity->getCategory()->getName();
72
        }
73
74
        return '';
75
    }
76
77
    /**
78
     * @return Actions
79
     */
80
    protected function getRowActions(): Actions
81
    {
82
        $attributeCallbacks = $this->getAttributeCallbacks();
83
84
        $editAttributes   = [
85
            Html5::ATTR_HREF => Routes::ROUTE_PAGES_EDIT,
86
        ];
87
        $deleteAttributes = [
88
            Html5::ATTR_HREF => Routes::ROUTE_PAGES_DELETE,
89
        ];
90
91
        $cellActions   = new Actions();
92
        $cellActions[] = new Action(
93
            static::LABEL_EDIT,
94
            $this->editIntents,
95
            $editAttributes,
96
            $attributeCallbacks,
97
            Html5::TAG_A
98
        );
99
        $cellActions[] = new Action(
100
            static::LABEL_DELETE,
101
            $this->deleteIntents,
102
            $deleteAttributes,
103
            $attributeCallbacks,
104
            Html5::TAG_A
105
        );
106
107
        return $cellActions;
108
    }
109
}
110