Completed
Pull Request — master (#12)
by Matthew
11:11
created

ManageableObjectDataExtension::getListingPage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Dynamic\ManageableDataObject\Extensions;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\ORM\DataExtension;
7
use SilverStripe\Security\Security;
8
9
/**
10
 * Class ManageableObjectDataExtension
11
 *
12
 * @property \Dynamic\ManageableDataObject\Extensions\ManageableObjectDataExtension|\SilverStripe\ORM\DataObject $owner
13
 */
14
class ManageableObjectDataExtension extends DataExtension
15
{
16
17
    /**
18
     * Get the listing page to view this Event on (used in Link functions below)
19
     *
20
     * @return mixed
21
     */
22
    public function getListingPage()
23
    {
24
25
        $listingClass = $this->owner->config()->get('listing_page_class');
0 ignored issues
show
Bug introduced by
The method config() does not exist on Dynamic\ManageableDataOb...ableObjectDataExtension. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        $listingClass = $this->owner->/** @scrutinizer ignore-call */ config()->get('listing_page_class');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
27
        if ($listingPage = $listingClass::get()->first()) {
28
            return $listingPage;
29
        }
30
31
        return false;
32
    }
33
34
    /**
35
     * @return bool
36
     */
37
    public function getAddLink()
38
    {
39
        if ($this->owner->getListingPage()->hasMethod('Link') && $this->owner->canCreate(Security::getCurrentUser())) {
40
            return $this->owner->getListingPage()->Link('add');
41
        }
42
43
        return false;
44
    }
45
46
    /**
47
     * @return bool|String
48
     */
49
    public function getEditLink()
50
    {
51
        if ($this->owner->getListingPage()->hasMethod('Link') && $this->owner->canEdit(Security::getCurrentUser())) {
52
            $field = ($this->owner->config()->get('query_field'))
53
                ? $this->owner->config()->get('query_field')
54
                : 'ID';
55
56
            return Controller::join_links($this->owner->getListingPage()->Link('edit'), $this->owner->$field);
57
        }
58
59
        return false;
60
    }
61
62
    /**
63
     * @return bool|String
64
     */
65
    public function getDeleteLink()
66
    {
67
        if ($this->owner->getListingPage()->hasMethod('Link') && $this->owner->canDelete(Security::getCurrentUser())) {
68
            $field = ($this->owner->config()->get('query_field'))
69
                ? $this->owner->config()->get('query_field')
70
                : 'ID';
71
72
            return Controller::join_links($this->owner->getListingPage()->Link('delete'), $this->owner->$field);
73
        }
74
75
        return false;
76
    }
77
78
}
79