Distributor_MemberDOD::onAfterWrite()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.5555
c 0
b 0
f 0
cc 5
nc 4
nop 0
1
<?php
2
3
/**
4
 * adds a member to a distributor
5
 *
6
 */
7
8
class Distributor_MemberDOD extends DataExtension
9
{
10
    private static $has_one = array(
11
        'Distributor' => 'Distributor'
12
    );
13
14
    public function updateCMSFields(FieldList $fields)
15
    {
16
        $distributors = Distributor::get()->map('ID', 'Name')->toArray();
17
        $fields->addFieldToTab('Root.Distributor', new DropdownField('DistributorID', _t('Distributor.SINGULAR_NAME', 'Distributor'), $distributors, '', null, '-- Select --'));
18
    }
19
20
    public function onAfterWrite()
21
    {
22
        if ($this->owner->DistributorID) {
0 ignored issues
show
Bug introduced by
The property DistributorID does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
23
            $distributor = $this->owner->Distributor();
24
            if ($distributor && $distributor->exists()) {
25
                $group = Group::get()->filter(array("Code" => Config::inst()->get('Distributor', 'distributor_permission_code')))->first();
26
                if ($group) {
27
                    $this->owner->addToGroupByCode($group->Code);
28
                }
29
            }
30
        }
31
    }
32
}
33