| @@ 10-102 (lines=93) @@ | ||
| 7 | use Rudolf\Component\Helpers\Pagination\TagsGenerator; |
|
| 8 | use Rudolf\Framework\View\FrontView; |
|
| 9 | ||
| 10 | class View extends FrontView |
|
| 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).' – '; |
|
| 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 | ||
| @@ 10-102 (lines=93) @@ | ||
| 7 | use Rudolf\Component\Helpers\Pagination\TagsGenerator; |
|
| 8 | use Rudolf\Framework\View\FrontView; |
|
| 9 | ||
| 10 | class View extends FrontView |
|
| 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 = '/artykuly/kategorie/'.$info['slug']; |
|
| 30 | $this->loop = new Loop( |
|
| 31 | $data, |
|
| 32 | $pagination, |
|
| 33 | 'Rudolf\\Modules\\Articles\\One\\Article', |
|
| 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).' – '; |
|
| 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 = 'articles-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 = _('Articles 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 | ||