ViewTrait::createView()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Lagdo\DbAdmin\Db\Driver\Facades;
4
5
use Exception;
6
7
/**
8
 * Facade to view functions
9
 */
10
trait ViewTrait
11
{
12
    use AbstractTrait;
13
14
    /**
15
     * Get the facade
16
     *
17
     * @return ViewFacade
18
     */
19
    protected function viewFacade(): ViewFacade
20
    {
21
        return $this->di()->g(ViewFacade::class);
22
    }
23
24
    /**
25
     * Get details about a view
26
     *
27
     * @param string $view      The view name
28
     *
29
     * @return array
30
     */
31
    public function getViewInfo(string $view): array
32
    {
33
        $this->connectToSchema();
34
        $this->breadcrumbs(true)
35
            ->item($this->utils->trans->lang('Views'))
36
            ->item("<i><b>$view</b></i>");
37
        $this->utils->input->table = $view;
38
        return $this->viewFacade()->getViewInfo($view);
39
    }
40
41
    /**
42
     * Get details about a view
43
     *
44
     * @param string $view The view name
45
     *
46
     * @return array
47
     * @throws Exception
48
     */
49
    public function getViewFields(string $view): array
50
    {
51
        $this->connectToSchema();
52
        $this->utils->input->table = $view;
53
        return $this->viewFacade()->getViewFields($view);
54
    }
55
56
    /**
57
     * Get the triggers of a view
58
     *
59
     * @param string $view      The view name
60
     *
61
     * @return array|null
62
     */
63
    public function getViewTriggers(string $view): ?array
64
    {
65
        $this->connectToSchema();
66
        $this->utils->input->table = $view;
67
        return $this->viewFacade()->getViewTriggers($view);
68
    }
69
70
    /**
71
     * Get a view
72
     *
73
     * @param string $view The view name
74
     *
75
     * @return array
76
     * @throws Exception
77
     */
78
    public function getView(string $view): array
79
    {
80
        $this->connectToSchema();
81
        $this->utils->input->table = $view;
82
        return $this->viewFacade()->getView($view);
83
    }
84
85
    /**
86
     * Create a view
87
     *
88
     * @param array $values The view values
89
     *
90
     * @return array
91
     * @throws Exception
92
     */
93
    public function createView(array $values): array
94
    {
95
        $this->connectToSchema();
96
        $this->utils->input->table = $values['name'];
97
        return $this->viewFacade()->createView($values);
98
    }
99
100
    /**
101
     * Update a view
102
     *
103
     * @param string $view The view name
104
     * @param array $values The view values
105
     *
106
     * @return array
107
     * @throws Exception
108
     */
109
    public function updateView(string $view, array $values): array
110
    {
111
        $this->connectToSchema();
112
        $this->utils->input->table = $view;
113
        return $this->viewFacade()->updateView($view, $values);
114
    }
115
116
    /**
117
     * Drop a view
118
     *
119
     * @param string $view The view name
120
     *
121
     * @return array
122
     * @throws Exception
123
     */
124
    public function dropView(string $view): array
125
    {
126
        $this->connectToSchema();
127
        $this->utils->input->table = $view;
128
        return $this->viewFacade()->dropView($view);
129
    }
130
}
131