Completed
Push — develop ( 9a2d03...4f224f )
by Nate
09:22
created

VisitorsController::baseUpsertVariables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\cp\controllers\view;
10
11
use flipbox\craft\hubspot\HubSpot;
12
use flipbox\craft\hubspot\records\Visitor;
13
use yii\web\Response;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.1.0
18
 */
19
class VisitorsController extends AbstractController
20
{
21
    /**
22
     * The template base path
23
     */
24
    const TEMPLATE_BASE = parent::TEMPLATE_BASE . '/visitors';
25
26
    /**
27
     * The index view template path
28
     */
29
    const TEMPLATE_INDEX = self::TEMPLATE_BASE . '/index';
30
31
    /**
32
     * The detail view template path
33
     */
34
    const TEMPLATE_DETAIL = self::TEMPLATE_BASE . '/detail';
35
36
    /**
37
     * @return Response
38
     */
39
    public function actionIndex(): Response
40
    {
41
        $variables = [];
42
        $this->baseVariables($variables);
43
44
        $variables['visitors'] = Visitor::find()->all();
45
46
        return $this->renderTemplate(
47
            static::TEMPLATE_INDEX,
48
            $variables
49
        );
50
    }
51
52
    /**
53
     * @param $identifier
54
     * @return Response
55
     * @throws \flipbox\craft\ember\exceptions\RecordNotFoundException
56
     */
57
    public function actionDetail($identifier): Response
58
    {
59
        $visitor = Visitor::getOne($identifier);
60
61
        $variables = [];
62
63
        $this->baseUpsertVariables($variables, $visitor);
64
65
        // Full page form in the CP
66
        $variables['fullPageForm'] = true;
67
68
        $variables['visitor'] = $visitor;
69
        $variables['statusOptions'] = [
70
            [
71
                'label' => HubSpot::t("Successful"),
72
                'value' => Visitor::STATUS_SUCCESSFUL
73
            ],
74
            [
75
                'label' => HubSpot::t("Pending"),
76
                'value' => Visitor::STATUS_PENDING
77
            ],
78
            [
79
                'label' => HubSpot::t("Not Found"),
80
                'value' => Visitor::STATUS_NOT_FOUND
81
            ],
82
            [
83
                'label' => HubSpot::t("Error"),
84
                'value' => Visitor::STATUS_ERROR
85
            ]
86
        ];
87
88
        return $this->renderTemplate(
89
            static::TEMPLATE_DETAIL,
90
            $variables
91
        );
92
    }
93
94
95
    /*******************************************
96
     * BASE PATHS
97
     *******************************************/
98
99
    /**
100
     * @return string
101
     */
102
    protected function getBaseActionPath(): string
103
    {
104
        return parent::getBaseActionPath() . '/visitors';
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    protected function getBaseCpPath(): string
111
    {
112
        return parent::getBaseCpPath() . '/visitors';
113
    }
114
115
    /*******************************************
116
     * VARIABLES
117
     *******************************************/
118
119
    /**
120
     * @param array $variables
121
     * @param Visitor $visitor
122
     */
123
    protected function baseUpsertVariables(array &$variables = [], Visitor $visitor)
124
    {
125
        $this->baseVariables($variables);
126
127
        $variables['title'] .= ': ' . $visitor->token;
128
    }
129
130
    /**
131
     * @inheritdoc
132
     */
133
    protected function baseVariables(array &$variables = [])
134
    {
135
        parent::baseVariables($variables);
136
137
        $title = HubSpot::t("Visitors");
138
        $variables['title'] .= ' ' . $title;
139
140
        // Breadcrumbs
141
        $variables['crumbs'][] = [
142
            'label' => $title,
143
            'url' => ''
144
        ];
145
    }
146
}