AutomaticallyCreatedOrderDecorator::FuturePast()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
/**
4
 * @author nicolaas @ sunnysideup . co . nz
5
 */
6
7
class AutomaticallyCreatedOrderDecorator extends DataExtension
8
{
9
    private static $db= [
10
        "OrderDate" => "Date", //date at which the order should be placed
11
        "OrderDateInteger" => "Int" //date at which the order should be placed AS integer
12
    ];
13
14
    private static $has_one = [
15
        'RepeatOrder' => 'RepeatOrder'
16
    ];
17
18
    private static $indexes = [
19
        'OrderDateInteger' => true
20
    ];
21
    private static $searchable_fields = [
22
        'RepeatOrderID' => [
23
            'field' => 'NumericField',
24
            'title' => 'Repeat Order Number'
25
        ]
26
    ];
27
28
    public function updateCMSFields(FieldList $fields)
29
    {
30
        $fields->removeByName("OrderDate");
31
        $fields->removeByName("OrderDateInteger");
32
        $fields->removeByName("RepeatOrderID");
33
        if ($this->owner->RepeatOrderID) {
0 ignored issues
show
Bug introduced by
The property RepeatOrderID 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...
34
            $fields->addFieldToTab("Root.RepeatOrder", ReadonlyField::create("OrderDate", "Planned Next Order Date - based on repeating order schedule"));
35
            $fields->addFieldToTab("Root.RepeatOrder", ReadonlyField::create("RepeatOrderID", "Created as part of Repeat Order #"));
36
        }
37
    }
38
39
    public function FuturePast()
40
    {
41
        $currentTime = strtotime('Now');
42
        $orderTime = strtotime($this->owner->OrderDate);
0 ignored issues
show
Bug introduced by
The property OrderDate 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...
43
        if ($currentTime > $orderTime) {
44
            return "past";
45
        } elseif ($currentTime == $orderTime) {
46
            return "current";
47
        } else {
48
            return "future";
49
        }
50
    }
51
}
52