Completed
Push — rss-generator ( 3b0bb8...5a407c )
by Arnaud
02:11
created

Rss::generate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 9.424
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Generator;
10
11
use Cecil\Collection\Collection as PageCollection;
12
use Cecil\Collection\Page\Page;
13
use Cecil\Page\NodeType;
14
15
/**
16
 * Class Rss.
17
 */
18
class Rss extends AbstractGenerator implements GeneratorInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function generate(PageCollection $pageCollection, \Closure $messageCallback)
24
    {
25
        $generatedPages = new PageCollection();
26
27
        $filteredPages = $pageCollection->filter(function (Page $page) {
28
            //return in_array($page->getNodeType(), [NodeType::HOMEPAGE, NodeType::SECTION]);
29
            return in_array($page->getNodeType(), [NodeType::SECTION]);
30
        });
31
32
        /* @var $page Page */
33
        foreach ($filteredPages as $page) {
34
            //
35
            printf("%s\n", $page->getId());
36
            //
37
            /* @var $aliasPage Page */
38
            $rssPage = clone $page;
39
            $rssPage
40
                //->setId($page->getId().'/rss')
41
                //->setPathname(Page::urlize($page->getId().'/rss'))
42
                //->setTitle($page->getTitle().' - RSS')
43
                //->setNodeType(NodeType::SECTION)
44
                //->setSection($page->getSection())
45
                ->setLayout('rss.xml')
46
                ->setPermalink($page->getPathname().'/rss.xml')
47
                //->setDate($page->getDate())
48
                ;
49
            $generatedPages->add($rssPage);
50
        }
51
52
        return $generatedPages;
53
    }
54
}
55