Completed
Push — master ( a284f8...7a851f )
by Mikołaj
03:34
created

View::isCategoryDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 4
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Modules\Albums\Category\One;
4
5
use Rudolf\Component\Helpers\Pagination\Calc as Pagination;
6
use Rudolf\Component\Helpers\Pagination\Loop;
7
use Rudolf\Component\Helpers\Pagination\TagsGenerator;
8
use Rudolf\Framework\View\FrontView;
9
10 View Code Duplication
class View extends FrontView
0 ignored issues
show
Duplication introduced by
This class 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...
11
{
12
    /**
13
     * @var Loop
14
     */
15
    protected $loop;
16
17
    /**
18
     * @var array
19
     */
20
    protected $categoryInfo;
21
22
    /**
23
     * @param array $data
24
     * @param Pagination $pagination
25
     * @param array $info
26
     */
27
    public function setData(array $data, Pagination $pagination, $info = [])
28
    {
29
        $path = '/foto/kategorie/'.$info['slug'];
30
        $this->loop = new Loop(
31
            $data,
32
            $pagination,
33
            'Rudolf\\Modules\\Albums\\One\\Album',
34
            $path
35
        );
36
37
        $tags = new TagsGenerator($pagination, $this->head);
38
        $tags->setPath($path);
39
        $tags->create();
40
41
        $this->categoryInfo = $info;
42
43
        $page = $pagination->getPageNumber();
44
        $allPages = $pagination->getAllPages();
45
46
        $titleBefore = null;
47
        $pageInfo = null;
48
49
        if (1 !== $page) {
50
            $titleBefore = sprintf(_('Page %1$s of %2$s'), $page, $allPages).' &ndash; ';
51
            $pageInfo = '/page/'.$page;
52
        }
53
54
        $this->head->setTitle($titleBefore.$this->categoryTitle(true));
55
        $this->head->setCanonical(DIR.$path.$pageInfo);
56
57
        $this->template = 'albums-category';
58
    }
59
60
    /**
61
     * Returns category title.
62
     *
63
     * @param bool $strip
64
     * @param bool $before
65
     *
66
     * @return string
67
     */
68
    public function categoryTitle($strip = false, $before = true)
69
    {
70
        $title = '<i>'.$this->categoryInfo['title'].'</i>';
71
72
        if (true === $strip) {
73
            $title = strip_tags($title);
74
        }
75
76
        if (true === $before) {
77
            $title = _('Albums from category').' '.$title;
78
        }
79
80
        return $title;
81
    }
82
83
    /**
84
     * Returns category description.
85
     *
86
     * @return string
87
     */
88
    public function categoryDescription()
89
    {
90
        return $this->categoryInfo['content'];
91
    }
92
93
    /**
94
     * Returns if category description exist
95
     *
96
     * @return boolean
97
     */
98
    public function isCategoryDescription()
99
    {
100
        return !empty($this->categoryInfo['content']);
101
    }
102
}
103