Completed
Pull Request — master (#7)
by Jason
04:47
created

RecentBlogPostsBlock::canView()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
1
<?php
2
3
/**
4
 * Class RecentBlogPostsBlock
5
 */
6
class RecentBlogPostsBlock extends Block
7
{
8
    /**
9
     * @var string
10
     */
11
    private static $singular_name = 'Recent Blog Posts Block';
12
13
    /**
14
     * @var string
15
     */
16
    private static $plural_name = 'Recent Blog Posts Blocks';
17
18
    /**
19
     * @var array
20
     */
21
    private static $db = array(
22
        'Limit' => 'Int',
23
    );
24
25
    /**
26
     * @var array
27
     */
28
    private static $has_one = array(
29
        'Blog' => 'Blog',
30
    );
31
32
    /**
33
     * @var array
34
     */
35
    private static $defaults = array(
36
        'Limit' => 3,
37
    );
38
39
    /**
40
     * @return FieldList
41
     */
42 1
    public function getCMSFields()
43
    {
44 1
        $fields = parent::getCMSFields();
45
46
        $fields->addFieldsToTab('Root.Main', array(
47
            NumericField::create('Limit'),
48
        ));
49
50
        if (class_exists('Blog')) {
51
            $fields->addFieldToTab(
52
                'Root.Main',
53
                DropdownField::create('BlogID', 'Featured Blog', Blog::get()->map())
54
                    ->setEmptyString('')
55
            );
56
        }
57
58
        return $fields;
59
    }
60
61
    /**
62
     * @param null $member
63
     * @return bool
64
     */
65 1
    public function canCreate($member = null)
66
    {
67 1
        if (!class_exists('Blog')) {
68 1
            return false;
69
        }
70
        return parent::canCreate();
71
    }
72
73
    /**
74
     * @param null $member
75
     * @return bool
76
     */
77 1
    public function canView($member = null)
78
    {
79 1
        if (!class_exists('Blog')) {
80 1
            return false;
81
        }
82
        return parent::canView();
83
    }
84
}