Completed
Push — 1.0 ( 958294...8e72cf )
by Morven
03:15
created

ContactExtension   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 17

6 Methods

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 21 3
A canDelete() 0 5 4
A canEdit() 0 5 4
A HistoricInvoices() 0 6 1
A OutstandingInvoices() 0 6 1
A canView() 0 5 4
1
<?php
2
3
namespace SilverCommerce\OrdersAdmin\Extensions;
4
5
use SilverStripe\ORM\DataExtension;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\DropdownField;
8
use SilverStripe\Forms\GridField\GridFieldDetailForm;
9
use SilverStripe\Core\Config\Config;
10
use SilverStripe\Security\Member;
11
use SilverCommerce\OrdersAdmin\Forms\GridField\OrdersDetailForm;
12
use SilverCommerce\OrdersAdmin\Model\Invoice;
13
use SilverCommerce\OrdersAdmin\Model\Estimate;
14
15
/**
16
 * Add additional functions to a contact
17
 */
18
class ContactExtension extends DataExtension
19
{   
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
20
    private static $has_many = [
0 ignored issues
show
introduced by
The private property $has_many is not used, and could be removed.
Loading history...
21
        "Invoices" => Invoice::class,
22
        "Estimates"=> Estimate::class
23
    ];
24
25
    public function updateCMSFields(FieldList $fields)
26
    {
27
        // Filter the invoice list
28
        $invoices_field = $fields->dataFieldByName("Invoices");
29
        $estimate_field = $fields->dataFieldByName("Estimates");
30
31
        if ($invoices_field) {
0 ignored issues
show
introduced by
$invoices_field is of type SilverStripe\Forms\FormField, thus it always evaluated to true.
Loading history...
32
            $invoices_field
33
                ->getConfig()
34
                ->removeComponentsByType(GridFieldDetailForm::class)
35
                ->addComponent(new OrdersDetailForm());
36
        }
37
38
        if ($estimate_field) {
0 ignored issues
show
introduced by
$estimate_field is of type SilverStripe\Forms\FormField, thus it always evaluated to true.
Loading history...
39
            $list = $estimate_field->getList();
40
            $list = $list->filter("ClassName", Estimate::class);
41
            $estimate_field->setList($list);
42
            $estimate_field
43
                ->getConfig()
44
                ->removeComponentsByType(GridFieldDetailForm::class)
45
                ->addComponent(new OrdersDetailForm());
46
        }
47
    }
48
49
    /**
50
     * Get all orders that have been generated and are marked
51
     * as paid or processing
52
     *
53
     * @return DataList
0 ignored issues
show
Bug introduced by
The type SilverCommerce\OrdersAdmin\Extensions\DataList was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
54
     */
55
    public function OutstandingInvoices()
56
    {
57
        return $this
58
            ->owner
59
            ->Invoices()
60
            ->filter("Status", Config::inst()->get(Invoice::class, "outstanding_statuses"));
61
    }
62
63
    /**
64
     * Get all orders that have been generated and are marked
65
     * as dispatched or canceled
66
     *
67
     * @return DataList
68
     */
69
    public function HistoricInvoices()
70
    {
71
        return $this
72
            ->owner
73
            ->Invoices()
74
            ->filter("Status", Config::inst()->get(Invoice::class, "historic_statuses"));
75
    }
76
77
    public function canView($member)
78
    {
79
        // Members can view their own records
80
        if ($member && $member->exists() && $member->ID == $this->owner->MemberID) {
81
            return true;
82
        }
83
    }
84
85
    public function canEdit($member)
86
    {
87
        // Members can edit their own records
88
        if ($member && $member->exists() && $member->ID == $this->owner->MemberID) {
89
            return true;
90
        }
91
    }
92
93
    public function canDelete($member)
94
    {
95
        // Members can delete their own records
96
        if ($member && $member->exists() && $member->ID == $this->owner->MemberID) {
97
            return true;
98
        }
99
    }
100
}
101