Completed
Push — master ( 862cc7...24e4b3 )
by Nate
03:30
created

LimitsController::actionIndex()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 21
cp 0
rs 9.52
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/force/license
6
 * @link       https://www.flipboxfactory.com/software/force/
7
 */
8
9
namespace flipbox\craft\salesforce\cp\controllers\view;
10
11
use craft\helpers\UrlHelper;
12
use flipbox\craft\salesforce\criteria\InstanceCriteria;
13
use flipbox\craft\salesforce\Force;
14
use flipbox\craft\salesforce\transformers\DynamicModelResponse;
15
use yii\web\Response;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class LimitsController extends AbstractController
22
{
23
    /**
24
     * The template base path
25
     */
26
    const TEMPLATE_BASE = parent::TEMPLATE_BASE . '/limits';
27
28
    /**
29
     * The index view template path
30
     */
31
    const TEMPLATE_INDEX = self::TEMPLATE_BASE . '/index';
32
33
    /**
34
     * @return Response
35
     */
36
    public function actionIndex(): Response
37
    {
38
        $variables = [];
39
        $this->baseVariables($variables);
40
41
        if (null !== ($connection = $this->findActiveConnection())) {
42
            $criteria = new InstanceCriteria([
43
                'connection' => $connection->getConnection()
44
            ]);
45
46
            $model = call_user_func_array(
47
                new DynamicModelResponse(),
48
                [
49
                    $criteria->limits()
50
                ]
51
            );
52
        }
53
54
        $variables['limits'] = $model ?? $this->invalidConnectionModel();
55
56
        return $this->renderTemplate(
57
            static::TEMPLATE_INDEX,
58
            $variables
59
        );
60
    }
61
62
    /*******************************************
63
     * BASE PATHS
64
     *******************************************/
65
66
    /**
67
     * @return string
68
     */
69
    protected function getBaseCpPath(): string
70
    {
71
        return parent::getBaseCpPath() . '/limits';
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    protected function getBaseActionPath(): string
78
    {
79
        return parent::getBaseActionPath() . '/limits';
80
    }
81
82
    /*******************************************
83
     * VARIABLES
84
     *******************************************/
85
86
    /**
87
     * @inheritdoc
88
     */
89
    protected function baseVariables(array &$variables = [])
90
    {
91
        parent::baseVariables($variables);
92
93
        $title = Force::t("Limits");
94
        $variables['title'] .= ' ' . $title;
95
96
        // Breadcrumbs
97
        $variables['crumbs'][] = [
98
            'label' => $title,
99
            'url' => UrlHelper::url($this->getBaseCpPath())
100
        ];
101
    }
102
}
103