Completed
Push — development ( 75522b...9443e0 )
by Ashutosh
09:07
created

Orders::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers\Order;
4
5
use App\Http\Controllers\Controller;
6
use App\Model\Order\Order;
7
8
class Orders extends Controller
9
{
10
    public $orderid;
11
12
    public function __construct($order_id)
13
    {
14
        $this->orderid = $order_id;
15
    }
16
17
    public function getOrder()
18
    {
19
        /** @scrutinizer ignore-call */
20
        $order = self::find($this->orderid);
21
22
        return $order;
23
    }
24
25
    public function getSubscription()
26
    {
27
        $order = $this->getOrder();
28
        if ($order) {
29
            $subscription = $order->subscription;
30
31
            return $subscription;
32
        }
33
    }
34
35
    public function getProduct()
36
    {
37
        $order = $this->getOrder();
38
        if ($order) {
39
            $product = $order->product;
40
41
            return $product;
42
        }
43
    }
44
45
    public function getPlan()
46
    {
47
        $subscription = $this->getSubscription();
48
        if ($subscription) {
49
            $plan = $subscription->plan;
50
51
            return $plan;
52
        }
53
    }
54
55
    public function subscriptionPeriod()
56
    {
57
        $days = '';
58
        $plan = $this->getPlan();
59
        if ($plan) {
60
            $days = $plan->days;
61
        }
62
63
        return $days;
64
    }
65
66
    public function version()
67
    {
68
        $subscription = $this->getSubscription();
69
        if ($subscription) {
70
            $version = $subscription->vesion;
71
        }
72
73
        return $version;
74
    }
75
76
    public function isExpired()
77
    {
78
        $expired = false;
79
        $subscription = $this->getSubscription();
80
        if ($subscription) {
81
            $end = $subscription->ends_at;
82
            $today = \Carbon\Carbon::now();
83
            if ($today->gt($end)) {
84
                $expired = true;
85
            }
86
        }
87
88
        return $expired;
89
    }
90
91
    public function productName()
92
    {
93
        $name = '';
94
        $product = $this->getProduct();
95
        if ($product) {
96
            $name = $product->name;
97
        }
98
99
        return $name;
100
    }
101
102
    public function isDownloadable()
103
    {
104
        $check = false;
105
        $product = $this->getProduct();
106
        if ($product) {
107
            $type = $product->type;
108
            if ($type) {
109
                $type_name = $type->name;
110
                if ($type_name == 'download') {
111
                    $check = true;
112
                }
113
            }
114
        }
115
116
        return $check;
117
    }
118
}
119