Issues (213)

src/controllers/OrderController.php (1 issue)

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\modules\server\cart\ServerOrderDedicatedProduct;
15
use hipanel\modules\server\cart\ServerOrderProduct;
16
use hipanel\modules\server\models\Config;
17
use hipanel\modules\server\models\Osimage;
18
use hipanel\modules\server\Module;
19
use hipanel\filters\EasyAccessControl;
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' => EasyAccessControl::ALLOW_ANY,
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
            if (empty(Yii::$app->user->identity)) {
67
                Yii::$app->get('hiart')->disableAuth();
68
            }
69
        }
70
71
        return parent::beforeAction($action);
72
    }
73
74
    public function actions()
75
    {
76
        return [
77
            'add-to-cart' => [
78
                'class' => AddToCartAction::class,
79
                'productClass' => ServerOrderProduct::class,
80
                'redirectToCart' => true,
81
            ],
82
            'add-to-cart-dedicated' => [
83
                'class' => AddToCartAction::class,
84
                'productClass' => ServerOrderDedicatedProduct::class,
85
                'redirectToCart' => true,
86
            ],
87
        ];
88
    }
89
90
    public function actionOrder($id)
0 ignored issues
show
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

90
    public function actionOrder(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91
    {
92
        return $this->redirectOutside();
93
        /***
94
        $package = ServerHelper::getAvailablePackages(null, $id);
95
        $osImages = ServerHelper::getOsimages($package->tariff->type);
96
97
        return $this->render('order', [
98
            'package' => $package,
99
            'product' => new ServerOrderProduct(['tariff_id' => $package->tariff->id]),
100
            'groupedOsimages' => ServerHelper::groupOsimages($osImages),
101
            'panels' => ServerHelper::getPanels(),
102
        ]);
103
        ***/
104
    }
105
106
    public function actionIndex()
107
    {
108
        return $this->redirectOutside();
109
        /***
110
        return $this->render('index');
111
         ***/
112
    }
113
114
    public function actionXenSsd()
115
    {
116
        return $this->redirectOutside();
117
        /***
118
        return $this->render('xen_ssd', [
119
            'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_XEN),
120
            'tariffTypes' => Yii::$app->params['vdsproduct'],
121
        ]);
122
        ***/
123
    }
124
125
    public function actionOpenVz()
126
    {
127
        return $this->redirectOutside();
128
        /***
129
        return $this->render('open_vz', [
130
            'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_OPENVZ),
131
            'tariffTypes' => Yii::$app->params['vdsproduct'],
132
        ]);
133
        ***/
134
    }
135
136
    public function actionDedicated()
137
    {
138
        Yii::$app->get('hiart')->disableAuth();
139
        $this->layout = '@hipanel/server/order/yii/views/layouts/advancedhosting';
140
        $configs = Config::find()->getAvailable()->withSellerOptions()->withPrices()->addOption('batch', true)->createCommand()->send()->getData();
141
        $osimages = Osimage::find()->where(['type' => 'dedicated'])->all();
142
143
        return $this->render('dedicated', compact('configs', 'osimages'));
144
    }
145
146
    public function actionTariffsDetails()
147
    {
148
        return $this->render('tariffs_details');
149
    }
150
151
    public function actionAdvantages()
152
    {
153
        return $this->render('advantages');
154
    }
155
156
    public function actionWhatIsVds()
157
    {
158
        return $this->render('what_is_vds');
159
    }
160
161
    protected function redirectOutside()
162
    {
163
        $language = Yii::$app->language;
164
        $template = Yii::$app->params['module.server.order.redirect.url'];
165
        $url = preg_replace('/{language}/', $language, $template);
166
        return $this->redirect($url);
167
    }
168
}
169