DistributorAdmin.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
/**
 * Description of DistributorAdmin
 *
 * @author Joshua
 */
class DistributorAdmin extends ModelAdmin
{
    static $managed_models = array(
        'Distributor',
    );

    static $url_segment = 'distributors';
    static $menu_title = 'Distributors';
}
?>

Distributor.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
 * Description of Distributor
 *
 * @author Joshua
 */
class Distributor extends Member
{
    static $db = array(
        'LiftGateService' => 'Boolean',
        'DeliveryNotice' => 'Boolean',
        'BillingAddress' => 'Text',
        'ShippingSame' => 'Boolean',
        'ShippingAddress' => 'Text',
        'PrimaryPhone' => 'Varchar',
        'FAXNumber' => 'Varchar',
        'ContactNotes' => 'Text',
        'ShippingNotes' => 'Text',
        'AccessCarWash' => 'Boolean',
        'AccessDetail' => 'Boolean',
        'AccessAdditive' => 'Boolean'
    );

    public function canCreate($member = null) 
    {
        return true;
    }
    public function canEdit($member = null)
    {
        return true;
    }

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        //Remove fields created by parent which are unneded or that conflict
        //with fields created in FieldGroups below.
        $fields->removeByName('AccessCarWash');
        $fields->removeByName('AccessDetail');
        $fields->removeByName('AccessAdditive');
        $fields->removeByName('Locale');
        $fields->removeByName('DeliveryNotice');
        $fields->removeByName('LiftGateService');


        //Setup Main tab
        $accessFields = new FieldGroup(
            array(
                new CheckboxField('AccessCarWash', 'Car Wash'),
                new CheckboxField('AccessDetail', 'Detail'),
                new CheckboxField('AccessAdditive', 'Additive'),
                new LabelField('AccessLabel', 'Grants access to each product line\'s MSDS and order form.')
            )
        );
        $accessFields->subfieldParam = 'FieldHolder';
        $accessHeader = new Headerfield('AccessHeader', 'Product Access', 3);
        $fields->addFieldstoTab('Root.Main', array($accessHeader, $accessFields));

        //Setup Contact tab
        // Setup fields
        $billingAddress = new TextareaField('BillingAddress', 'Billing Address');
        $contactNotes = new TextAreaField('ContactNotes', 'Other Contact Information');
        $primaryPhone = new TextField('PrimaryPhone', 'Primary Number');

        // Set notes.
        $billingAddress->setRightTitle('Standard multi-line address.');
        $contactNotes->setRightTitle('Any extra notes or contact/billing information.');
        $primaryPhone->setRightTitle('');
        $contactFields = array(
            $billingAddress,
            $primaryPhone,
            new TextField('FAXNumber', 'FAX Number'),
            $contactNotes,
        );
        $fields->addFieldstoTab('Root.Contact Info', $contactFields);

        //Setup Delivery tab
        $shippingAddress = new TextareaField('ShippingAddress', 'Shipping Address');
        $shippingAddress->setRightTitle('Standard multi-line address. Only needed if it differs from the billing address.');
        $shippingNotes = new TextareaField('ShippingNotes', 'Other Shipping Notes');
        $shippingNotes->setRightTitle('Any extra notes or shipping information.');
        $shippingChecks = new FieldGroup(array(
            new CheckboxField('LiftGateService', 'Liftgate Service'),
            new CheckboxField('DeliveryNotice', 'Call before delivery.'),
        ));
        $shippingChecks->subfieldParam = 'FieldHolder';
        $deliveryFields = array(
            new HeaderField('ShippingAddressHeader', 'Shipping Address', 3),
            new CheckboxField('ShippingSame', 'Billing and shipping address are the same.'),
            $shippingAddress,
            new HeaderField('ShippingNotesHeader', 'Shipping Notes', 3),
            $shippingChecks,
            $shippingNotes,
        );
        $fields->addFieldstoTab('Root.Shipping Info', $deliveryFields);
        return $fields;
    }

    public static function checkProductAccess($className, $member = null)
    {
        if(!$member){
            $member = Member::currentUser();
        }
        if(is_a($member, 'Distributor')){
            if($className == 'ProductObjectCarwash' && $member->AccessCarWash == TRUE){
                return true;
            } elseif($className == 'ProductObjectAdditive' && $member->AccessAdditive == TRUE){
                return true;
            } elseif($className == 'ProductObjectDetail' && $member->AccessDetail){
                return true;
            } else {
                return false;
            }
        }
        return false;
    }
}
?>