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