Test Setup Failed
Push — development ( 236f05...edaf4e )
by Ashutosh
08:38
created

getHelpdeskVpsTemplate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 17
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
nop 3
1
<?php
2
3
namespace App\Http\Controllers\Front;
4
5
use App\Http\Controllers\Controller;
6
7
class GetPageTemplateController extends Controller
8
{
9
    /**
10
     * Get  Template For Helpdsk Products.
11
     */
12
    public function getHelpdeskTemplate($helpdesk_products, $data, $trasform)
13
    {
14
        $temp_controller = new \App\Http\Controllers\Common\TemplateController();
15
        if (count($helpdesk_products) > 0) {
16
            foreach ($helpdesk_products as $key => $value) {
17
                $trasform[$value['id']]['price'] = $temp_controller->leastAmount($value['id']);
18
                $trasform[$value['id']]['name'] = $value['name'];
19
                $trasform[$value['id']]['feature'] = $value['description'];
20
                $trasform[$value['id']]['subscription'] = $temp_controller->plans($value['shoping_cart_link'], $value['id']);
21
                $trasform[$value['id']]['url'] = "<input type='submit' value='Order Now' class='btn btn-primary'></form>";
22
            }
23
            $template = $this->transform('cart', $data, $trasform);
24
        } else {
25
            $template = '';
26
        }
27
28
        return $template;
29
    }
30
31
32
     /**
33
     * Get  Template For Helpdesk Products.
34
     */
35
    public function getHelpdeskVpsTemplate($helpdesk_vps_product, $data, $trasform3)
36
    {
37
        $temp_controller = new \App\Http\Controllers\Common\TemplateController();
38
        if (count($helpdesk_vps_product) > 0) {
39
            foreach ($helpdesk_vps_product as $key => $value) {
40
                $trasform[$value['id']]['price'] = $temp_controller->leastAmount($value['id']);
41
                $trasform[$value['id']]['name'] = $value['name'];
42
                $trasform[$value['id']]['feature'] = $value['description'];
43
                $trasform[$value['id']]['subscription'] = $temp_controller->plans($value['shoping_cart_link'], $value['id']);
44
                $trasform[$value['id']]['url'] = "<input type='submit' value='Order Now' class='btn btn-primary'></form>";
45
            }
46
            $helpdeskVpstemplate = $this->transform('cart', $data, $trasform3);
47
        } else {
48
            $helpdeskVpstemplate = '';
49
        }
50
51
        return $helpdeskVpstemplate;
52
    }
53
54
    /**
55
     * Get  Template For Service Desk Products.
56
     */
57
    public function getServiceDeskdeskTemplate($sevice_desk_products, $data, $trasform1)
58
    {
59
        $temp_controller = new \App\Http\Controllers\Common\TemplateController();
60
        if (count($sevice_desk_products) > 0) {
61
            foreach ($sevice_desk_products as $key => $value) {
62
                $trasform1[$value['id']]['price'] = $temp_controller->leastAmount($value['id']);
63
                $trasform1[$value['id']]['name'] = $value['name'];
64
                $trasform1[$value['id']]['feature'] = $value['description'];
65
                $trasform1[$value['id']]['subscription'] = $temp_controller->plans($value['shoping_cart_link'], $value['id']);
66
67
                $trasform1[$value['id']]['url'] = "<input type='submit' value='Order Now' class='btn btn-primary'></form>";
68
            }
69
            $servicedesk_template = $this->transform('cart', $data, $trasform1);
70
        } else {
71
            $servicedesk_template = '';
72
        }
73
74
        return $servicedesk_template;
75
    }
76
77
    /**
78
     * Get  Template For Services.
79
     */
80
    public function getServiceTemplate($service, $data, $trasform2)
81
    {
82
        $temp_controller = new \App\Http\Controllers\Common\TemplateController();
83
        if (count($service) > 0) {
84
            foreach ($service as $key => $value) {
85
                $trasform2[$value['id']]['price'] = $temp_controller->leastAmountService($value['id']);
86
                $trasform2[$value['id']]['name'] = $value['name'];
87
                $trasform2[$value['id']]['feature'] = $value['description'];
88
                $trasform2[$value['id']]['subscription'] = $temp_controller->plans($value['shoping_cart_link'], $value['id']);
89
90
                $trasform2[$value['id']]['url'] = "<input type='submit' value='Order Now' class='btn btn-primary'></form>";
91
            }
92
            $service_template = $this->transform('cart', $data, $trasform2);
93
        } else {
94
            $service_template = '';
95
        }
96
97
        return $service_template;
98
    }
99
100
    /**
101
     *Get The currency of User.
102
     */
103
    public function getCurrency($location)
104
    {
105
        if ($location['country'] == 'India') {
106
            $currency = 'INR';
107
        } else {
108
            $currency = 'USD';
109
        }
110
        if (\Auth::user()) {
111
            $currency = 'INR';
112
            $user_currency = \Auth::user()->currency;
113
            if ($user_currency == 1 || $user_currency == 'USD') {
114
                $currency = 'USD';
115
            }
116
        }
117
118
        return $currency;
119
    }
120
121
    /*
122
    * To get the current location(ip details and location deails)
123
    */
124
    public function getLocation()
125
    {
126
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {   //check ip from share internet
127
            $ip = $_SERVER['HTTP_CLIENT_IP'];
128
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {   //to check ip is pass from proxy
129
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
130
        } else {
131
            $ip = $_SERVER['REMOTE_ADDR'];
132
        }
133
134
        if ($ip != '::1') {
135
            $location = json_decode(file_get_contents('http://ip-api.com/json/'.$ip), true);
136
        } else {
137
            $location = json_decode(file_get_contents('http://ip-api.com/json'), true);
138
        }
139
140
        return $location;
141
    }
142
143
    public function checkConfigKey($config, $transform)
144
    {
145
        $result = [];
146
        if (count($config) > 0) {
147
            foreach ($config as $key => $value) {
148
                if (array_key_exists($key, $transform)) {
149
                    $result[$value] = $transform[$key];
150
                }
151
            }
152
        }
153
154
        return $result;
155
    }
156
157
    public function result($search, $model)
158
    {
159
        try {
160
            $model = $model->where('name', 'like', '%'.$search.'%')
161
            ->orWhere('content', 'like', '%'.$search.'%')
162
            ->paginate(10);
163
164
            return $model->setPath('search');
165
        } catch (\Exception $ex) {
166
            throw new \Exception('Can not get the search result');
167
        }
168
    }
169
170
    public function keyArray($array)
171
    {
172
        $result = [];
173
        foreach ($array as $key => $value) {
174
            $result[] = $key;
175
        }
176
177
        return $result;
178
    }
179
180
    public function valueArray($array)
181
    {
182
        $result = [];
183
        foreach ($array as $key => $value) {
184
            $result[] = $value;
185
        }
186
187
        return $result;
188
    }
189
}
190