BlogSharedCategoriesExtension   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 7
dl 0
loc 110
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
B updateCMSFields() 0 27 1
A UsedCategories() 0 13 3
A UsedTags() 0 10 3
A Tags() 0 4 1
A Categories() 0 4 1
A getTags() 0 4 1
A getCategories() 0 4 1
1
<?php
2
3
/**
4
 * extends Blog
5
 *
6
 */
7
8
9
class BlogSharedCategoriesExtension extends DataExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    public function updateCMSFields(FieldList $fields)
12
    {
13
        $fields->removeByName("Categories");
14
        $fields->removeByName("Tags");
15
        $fields->addFieldsToTab(
16
            "Root.Categorisation",
17
            array(
18
                GridField::create(
19
                    "Categories",
20
                    "Categories",
21
                    $this->owner->Categories(),
22
                    GridFieldConfig_RecordEditor ::create()
23
                )
24
            )
25
        );
26
        $fields->addFieldsToTab(
27
            "Root.Tags",
28
            array(
29
                GridField::create(
30
                    "Tags",
31
                    "Tags",
32
                    $this->owner->Tags(),
33
                    GridFieldConfig_RecordEditor ::create()
34
                )
35
            )
36
        );
37
    }
38
39
    /**
40
     *
41
     * @return DataList
42
     */
43
    public function UsedCategories()
44
    {
45
        $categories = BlogCategory::get()
46
            ->filter(array('BlogID' => $this->owner->ID))
47
            ->sort(array('Title' => 'ASC'));
48
        foreach ($categories as $category) {
49
            if ($category->BlogPosts()->count() == 0) {
50
                $categories = $categories->exclude(array('BlogCategory.ID' => $category->ID));
51
            }
52
        }
53
54
        return $categories;
55
    }
56
57
    /**
58
     * overrules has_many method
59
     * to return ALL categories
60
     *
61
     * @return DataList
62
     */
63
    public function UsedTags()
64
    {
65
        $tags = BlogTag::get();
66
        foreach ($tags as $tag) {
67
            if ($tag->BlogPosts()->count() == 0) {
68
                $tags = $tags->exclude(array('BlogTag.ID' => $tag->ID));
69
            }
70
        }
71
        return $tags;
72
    }
73
74
75
    /**
76
     * overrules has_many method
77
     * to return ALL categories
78
     *
79
     * @return DataList
80
     */
81
    public function Tags()
82
    {
83
        return BlogTag::get();
84
    }
85
86
    /**
87
     * overrules has_many method
88
     * to return ALL categories
89
     *
90
     * @return DataList
91
     */
92
    public function Categories()
93
    {
94
        return BlogCategory::get();
95
    }
96
97
    /**
98
     * overrules has_many method
99
     * to return ALL categories
100
     *
101
     * @return DataList
102
     */
103
    public function getTags()
104
    {
105
        return BlogTag::get();
106
    }
107
108
    /**
109
     * overrules has_many method
110
     * to return ALL categories
111
     *
112
     * @return DataList
113
     */
114
    public function getCategories()
115
    {
116
        return BlogCategory::get();
117
    }
118
}
119