Completed
Pull Request — master (#292)
by Jason
09:05
created

Order::getReceiptLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
class Order extends DataObject implements PermissionProvider
4
{
5
6
    private static $db = array(
7
        'Order_ID' => 'Int',
8
        'TransactionDate' => 'SS_Datetime',
9
        'ProductTotal' => 'Currency',
10
        'TaxTotal' => 'Currency',
11
        'ShippingTotal' => 'Currency',
12
        'OrderTotal' => 'Currency',
13
        'ReceiptURL' => 'Varchar(255)',
14
        'OrderStatus' => 'Varchar(255)',
15
        'Response' => 'Text'
16
    );
17
18
    private static $has_one = array(
19
        'Member' => 'Member'
20
    );
21
22
    private static $has_many = array(
23
        'Details' => 'OrderDetail'
24
    );
25
26
    private static $singular_name = 'Order';
27
    private static $plural_name = 'Orders';
28
    private static $description = 'Orders from FoxyCart Datafeed';
29
    private static $default_sort = 'TransactionDate DESC, ID DESC';
0 ignored issues
show
Unused Code introduced by
The property $default_sort is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
31
    private static $summary_fields = array(
32
        'Order_ID',
33
        'TransactionDate.NiceUS',
34
        'Member.Name',
35
        'ProductTotal.Nice',
36
        'TaxTotal.Nice',
37
        'ShippingTotal.Nice',
38
        'OrderTotal.Nice',
39
        'ReceiptLink'
40
    );
41
42
    private static $searchable_fields = array(
43
        'Order_ID',
44
        'TransactionDate' => array(
45
            "field" => "DateField",
46
            "filter" => "PartialMatchFilter"
47
        ),
48
        'Member.ID',
49
        'OrderTotal',
50
        'Details.ProductID'
51
    );
52
53
    private static $casting = array(
54
        'ReceiptLink' => 'HTMLVarchar'
55
    );
56
    
57
    private static $indexes = array(
58
        'Order_ID' => true // make unique
59
    );
60
61
    public function fieldLabels($includerelations = true)
62
    {
63
        $labels = parent::fieldLabels();
64
65
        $labels['Order_ID'] = _t('Order.Order_ID', 'Order ID#');
66
        $labels['TransactionDate'] = _t('Order.TransactionDate', "Date");
67
        $labels['TransactionDate.NiceUS'] = _t('Order.TransactionDate', "Date");
68
        $labels['Member.Name'] = _t('Order.MemberName', 'Customer');
69
        $labels['Member.ID'] = _t('Order.MemberName', 'Customer');
70
        $labels['ProductTotal.Nice'] = _t('Order.ProductTotal', 'Sub Total');
71
        $labels['TaxTotal.Nice'] = _t('Order.TaxTotal', 'Tax');
72
        $labels['ShippingTotal.Nice'] = _t('Order.ShippingTotal', 'Shipping');
73
        $labels['OrderTotal'] = _t('Order.OrderTotal', 'Total');
74
        $labels['OrderTotal.Nice'] = _t('Order.OrderTotal', 'Total');
75
        $labels['ReceiptLink'] = _t('Order.ReceiptLink', 'Invoice');
76
        $labels['Details.ProductID'] = _t('Order.Details.ProductID', 'Product');
77
78
        return $labels;
79
    }
80
81
    public function ReceiptLink()
82
    {
83
        return $this->getReceiptLink();
84
    }
85
86
    public function getReceiptLink()
87
    {
88
        $obj= HTMLVarchar::create();
89
        $obj->setValue('<a href="' . $this->ReceiptURL . '" target="_blank" class="cms-panel-link action external-link">view</a>');
0 ignored issues
show
Documentation introduced by
The property ReceiptURL does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
90
        return $obj;
91
    }
92
93
    public function canView($member = false)
94
    {
95
        return Permission::check('Product_ORDERS');
96
    }
97
98
    public function canEdit($member = null)
99
    {
100
        //return Permission::check('Product_ORDERS');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
101
        return false;
102
    }
103
104
    public function canDelete($member = null)
105
    {
106
        return false;
107
        //return Permission::check('Product_ORDERS');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
108
    }
109
110
    public function canCreate($member = null)
111
    {
112
        return false;
113
    }
114
115
    public function providePermissions()
116
    {
117
        return array(
118
            'Product_ORDERS' => 'Allow user to manage Orders and related objects'
119
        );
120
    }
121
}
122