CwpAtomFeed   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A linkToFeed() 0 6 1
A outputToBrowser() 0 7 1
A __construct() 0 23 1
1
<?php
2
3
namespace CWP\Core\Feed;
4
5
/**
6
 * CwpAtomFeed class
7
 *
8
 * This class is used to create an Atom feed.
9
 * @todo Improve documentation
10
 * @package cwp-core
11
 */
12
use SilverStripe\Control\Controller;
13
use SilverStripe\Control\RSS\RSSFeed;
14
use SilverStripe\Core\Convert;
15
use SilverStripe\ORM\FieldType\DBHTMLText;
16
use SilverStripe\ORM\SS_List;
17
use SilverStripe\View\Requirements;
18
19
class CwpAtomFeed extends RSSFeed
20
{
21
    public function __construct(
22
        SS_List $entries,
23
        $link,
24
        $title,
25
        $description = null,
26
        $titleField = "Title",
27
        $descriptionField = "Content",
28
        $authorField = null,
29
        $lastModified = null,
30
        $etag = null
31
    ) {
32
        parent::__construct(
33
            $entries,
34
            $link,
35
            $title,
36
            $description,
37
            $titleField,
38
            $descriptionField,
39
            $authorField,
40
            $lastModified
41
        );
42
43
        $this->setTemplate(__CLASS__);
44
    }
45
46
    /**
47
     * Include an link to the feed
48
     *
49
     * @param string $url URL of the feed
50
     * @param string $title Title to show
51
     */
52
    public static function linkToFeed($url, $title = null)
53
    {
54
        $title = Convert::raw2xml($title);
55
        Requirements::insertHeadTags(
56
            '<link rel="alternate" type="application/atom+xml" title="' . $title .
57
            '" href="' . $url . '" />'
58
        );
59
    }
60
61
    /**
62
     * Output the feed to the browser
63
     *
64
     * @return DBHTMLText
65
     */
66
    public function outputToBrowser()
67
    {
68
        $output = parent::outputToBrowser();
69
        $response = Controller::curr()->getResponse();
70
        $response->addHeader("Content-Type", "application/atom+xml");
71
72
        return $output;
73
    }
74
}
75