|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Server module for HiPanel |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-server |
|
6
|
|
|
* @package hipanel-module-server |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hipanel\modules\server\controllers; |
|
12
|
|
|
|
|
13
|
|
|
use hipanel\base\CrudController; |
|
14
|
|
|
use hipanel\filters\EasyAccessControl; |
|
15
|
|
|
use hipanel\modules\server\cart\ServerOrderDedicatedProduct; |
|
16
|
|
|
use hipanel\modules\server\cart\ServerOrderProduct; |
|
17
|
|
|
use hipanel\modules\server\models\Config; |
|
18
|
|
|
use hipanel\modules\server\models\Osimage; |
|
19
|
|
|
use hipanel\modules\server\Module; |
|
20
|
|
|
use hiqdev\yii2\cart\actions\AddToCartAction; |
|
21
|
|
|
use Yii; |
|
22
|
|
|
use yii\web\ForbiddenHttpException; |
|
23
|
|
|
|
|
24
|
|
|
class OrderController extends CrudController |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* OrderController constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $id |
|
30
|
|
|
* @param Module $module |
|
31
|
|
|
* @param array $config |
|
32
|
|
|
* @throws ForbiddenHttpException |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(string $id, Module $module, array $config = []) |
|
35
|
|
|
{ |
|
36
|
|
|
parent::__construct($id, $module, $config); |
|
37
|
|
|
|
|
38
|
|
|
if (!$module->orderIsAllowed) { |
|
39
|
|
|
throw new ForbiddenHttpException('Server order is not allowed'); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function behaviors() |
|
44
|
|
|
{ |
|
45
|
|
|
return array_merge(parent::behaviors(), [ |
|
46
|
|
|
[ |
|
47
|
|
|
'class' => EasyAccessControl::class, |
|
48
|
|
|
'actions' => [ |
|
49
|
|
|
'add-to-cart' => 'server.pay', |
|
50
|
|
|
'add-to-cart-dedicated' => 'server.pay', |
|
51
|
|
|
'index' => 'server.pay', |
|
52
|
|
|
'xen-ssd' => 'server.pay', |
|
53
|
|
|
'open-vz' => 'server.pay', |
|
54
|
|
|
'dedicated' => '?', |
|
55
|
|
|
'*' => 'server.read', |
|
56
|
|
|
], |
|
57
|
|
|
], |
|
58
|
|
|
]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function beforeAction($action) |
|
62
|
|
|
{ |
|
63
|
|
|
if ($action->id == 'add-to-cart-dedicated') { |
|
64
|
|
|
$this->enableCsrfValidation = false; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return parent::beforeAction($action); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function actions() |
|
71
|
|
|
{ |
|
72
|
|
|
return [ |
|
73
|
|
|
'add-to-cart' => [ |
|
74
|
|
|
'class' => AddToCartAction::class, |
|
75
|
|
|
'productClass' => ServerOrderProduct::class, |
|
76
|
|
|
'redirectToCart' => true, |
|
77
|
|
|
], |
|
78
|
|
|
'add-to-cart-dedicated' => [ |
|
79
|
|
|
'class' => AddToCartAction::class, |
|
80
|
|
|
'productClass' => ServerOrderDedicatedProduct::class, |
|
81
|
|
|
'redirectToCart' => true, |
|
82
|
|
|
], |
|
83
|
|
|
]; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function actionOrder($id) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
return $this->redirectOutside(); |
|
89
|
|
|
/*** |
|
90
|
|
|
$package = ServerHelper::getAvailablePackages(null, $id); |
|
91
|
|
|
$osImages = ServerHelper::getOsimages($package->tariff->type); |
|
92
|
|
|
|
|
93
|
|
|
return $this->render('order', [ |
|
94
|
|
|
'package' => $package, |
|
95
|
|
|
'product' => new ServerOrderProduct(['tariff_id' => $package->tariff->id]), |
|
96
|
|
|
'groupedOsimages' => ServerHelper::groupOsimages($osImages), |
|
97
|
|
|
'panels' => ServerHelper::getPanels(), |
|
98
|
|
|
]); |
|
99
|
|
|
***/ |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function actionIndex() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->redirectOutside(); |
|
105
|
|
|
/*** |
|
106
|
|
|
return $this->render('index'); |
|
107
|
|
|
***/ |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function actionXenSsd() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->redirectOutside(); |
|
113
|
|
|
/*** |
|
114
|
|
|
return $this->render('xen_ssd', [ |
|
115
|
|
|
'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_XEN), |
|
116
|
|
|
'tariffTypes' => Yii::$app->params['vdsproduct'], |
|
117
|
|
|
]); |
|
118
|
|
|
***/ |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function actionOpenVz() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->redirectOutside(); |
|
124
|
|
|
/*** |
|
125
|
|
|
return $this->render('open_vz', [ |
|
126
|
|
|
'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_OPENVZ), |
|
127
|
|
|
'tariffTypes' => Yii::$app->params['vdsproduct'], |
|
128
|
|
|
]); |
|
129
|
|
|
***/ |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function actionDedicated() |
|
133
|
|
|
{ |
|
134
|
|
|
$this->layout = '@hipanel/server/order/yii/views/layouts/advancedhosting'; |
|
135
|
|
|
$configs = Config::find()->getAvailable()->withSellerOptions()->withPrices()->addOption('batch', true)->createCommand()->send()->getData(); |
|
136
|
|
|
$osimages = Osimage::find()->where(['type' => 'dedicated'])->all(); |
|
137
|
|
|
|
|
138
|
|
|
return $this->render('dedicated', compact('configs', 'osimages')); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function actionTariffsDetails() |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->render('tariffs_details'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function actionAdvantages() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->render('advantages'); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function actionWhatIsVds() |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->render('what_is_vds'); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
protected function redirectOutside() |
|
157
|
|
|
{ |
|
158
|
|
|
$language = Yii::$app->language; |
|
159
|
|
|
$template = Yii::$app->params['module.server.order.redirect.url']; |
|
160
|
|
|
$url = preg_replace('/{language}/', $language, $template); |
|
161
|
|
|
return $this->redirect($url); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.