Passed
Push — master ( 46dd23...a76d17 )
by Dmitry
03:18
created

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\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 actions()
62
    {
63
        return [
64
            'add-to-cart' => [
65
                'class' => AddToCartAction::class,
66
                'productClass' => ServerOrderProduct::class,
67
                'redirectToCart' => true,
68
            ],
69
            'add-to-cart-dedicated' => [
70
                'class' => AddToCartAction::class,
71
                'productClass' => ServerOrderDedicatedProduct::class,
72
                'redirectToCart' => true,
73
            ],
74
        ];
75
    }
76
77
    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

77
    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...
78
    {
79
        return $this->redirectOutside();
80
        /***
81
        $package = ServerHelper::getAvailablePackages(null, $id);
82
        $osImages = ServerHelper::getOsimages($package->tariff->type);
83
84
        return $this->render('order', [
85
            'package' => $package,
86
            'product' => new ServerOrderProduct(['tariff_id' => $package->tariff->id]),
87
            'groupedOsimages' => ServerHelper::groupOsimages($osImages),
88
            'panels' => ServerHelper::getPanels(),
89
        ]);
90
        ***/
91
    }
92
93
    public function actionIndex()
94
    {
95
        return $this->redirectOutside();
96
        /***
97
        return $this->render('index');
98
         ***/
99
    }
100
101
    public function actionXenSsd()
102
    {
103
        return $this->redirectOutside();
104
        /***
105
        return $this->render('xen_ssd', [
106
            'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_XEN),
107
            'tariffTypes' => Yii::$app->params['vdsproduct'],
108
        ]);
109
        ***/
110
    }
111
112
    public function actionOpenVz()
113
    {
114
        return $this->redirectOutside();
115
        /***
116
        return $this->render('open_vz', [
117
            'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_OPENVZ),
118
            'tariffTypes' => Yii::$app->params['vdsproduct'],
119
        ]);
120
        ***/
121
    }
122
123
    public function actionDedicated()
124
    {
125
        $this->layout = '@hipanel/server/order/yii/views/layouts/advancedhosting';
126
        $configs = Config::find()->getAvailable()->withSellerOptions()->withPrices()->all();
127
        $osimages = Osimage::find()->where(['type' => 'dedicated'])->all();
128
129
        return $this->render('dedicated', compact('configs', 'osimages'));
130
    }
131
132
    public function actionTariffsDetails()
133
    {
134
        return $this->render('tariffs_details');
135
    }
136
137
    public function actionAdvantages()
138
    {
139
        return $this->render('advantages');
140
    }
141
142
    public function actionWhatIsVds()
143
    {
144
        return $this->render('what_is_vds');
145
    }
146
147
    protected function redirectOutside()
148
    {
149
        $language = Yii::$app->language;
150
        $template = Yii::$app->params['module.server.order.redirect.url'];
151
        $url = preg_replace('/{language}/', $language, $template);
152
        return $this->redirect($url);
153
    }
154
}
155