Passed
Push — master ( db1581...a5af1f )
by Ferry
04:30
created

Module::getTable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 2/4/2019
6
 * Time: 3:44 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\helpers;
10
11
12
use crocodicstudio\crudbooster\controllers\CBController;
13
use crocodicstudio\crudbooster\controllers\scaffolding\ColumnSingleton;
0 ignored issues
show
Bug introduced by
The type crocodicstudio\crudboost...folding\ColumnSingleton was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Illuminate\Support\Facades\DB;
15
16
class Module
17
{
18
    private $controller;
19
    private $controller_class;
20
    private $privilege;
21
    private $module;
22
    private $menu;
23
24
    public function __construct()
25
    {
26
        $routeArray = request()->route()->getAction();
27
        $this->controller = class_basename($routeArray['controller']);
28
        $this->controller = strtok($this->controller,"@");
29
30
        $className = "\\".$routeArray["namespace"]."\\".$this->controller;
31
        if(class_exists($className)) {
32
            $this->controller_class = new $className();
33
            $this->module = cb()->find("cb_modules",["controller"=>$this->controller]);
34
            $this->menu = cb()->find("cb_menus",["cb_modules_id"=>$this->module->id]);
35
            $this->menu = (!$this->menu)?cb()->find("cb_menus",["type"=>"path","path"=>request()->segment(2)]):$this->menu;
36
            $this->privilege = DB::table("cb_role_privileges")
37
                ->where("cb_menus_id", $this->menu->id)
38
                ->where("cb_roles_id", cb()->session()->roleId())
39
                ->first();
40
        }
41
    }
42
43
    /**
44
     * @return \crocodicstudio\crudbooster\controllers\scaffolding\singletons\ColumnSingleton
45
     */
46
    public function getColumnSingleton()
47
    {
48
        return app('ColumnSingleton');
0 ignored issues
show
Bug Best Practice introduced by
The expression return app('ColumnSingleton') also could return the type Illuminate\Contracts\Foundation\Application which is incompatible with the documented return type crocodicstudio\crudboost...gletons\ColumnSingleton.
Loading history...
49
    }
50
51
    public function getData($key) {
52
        return ($this->controller_class)?$this->controller_class->getData($key)?:cb()->getAppName():null;
53
    }
54
55
    /**
56
     * @return CBController
57
     */
58
    public function getController() {
59
        return ($this->controller_class)?$this->controller_class:null;
60
    }
61
62
    public function getPageTitle()
63
    {
64
        return ($this->controller_class)?$this->controller_class->getData("page_title")?:cb()->getAppName():null;
65
    }
66
67
    public function getTable()
68
    {
69
        return ($this->controller_class)?$this->controller_class->getData("table"):null;
70
    }
71
72
    public function getPageIcon()
73
    {
74
        return ($this->controller_class)?$this->controller_class->getData('page_icon')?:"fa fa-bars":null;
75
    }
76
77
    public function canBrowse() {
78
        if($this->privilege) {
79
            if($this->privilege->can_browse) return true;
80
            else return false;
81
        }else{
82
            return true;
83
        }
84
    }
85
86
    public function canCreate() {
87
        if($this->privilege) {
88
            if($this->privilege->can_create) return true;
89
            else return false;
90
        }else{
91
            return true;
92
        }
93
    }
94
95
    public function canRead() {
96
        if($this->privilege) {
97
            if($this->privilege->can_read) return true;
98
            else return false;
99
        }else{
100
            return true;
101
        }
102
    }
103
104
    public function canUpdate() {
105
        if($this->privilege) {
106
            if($this->privilege->can_update) return true;
107
            else return false;
108
        }else{
109
            return true;
110
        }
111
    }
112
113
    public function canDelete() {
114
        if($this->privilege) {
115
            if($this->privilege->can_delete) return true;
116
            else return false;
117
        }else{
118
            return true;
119
        }
120
    }
121
122
    public function addURL()
123
    {
124
        if($this->controller_class && method_exists($this->controller_class, 'getAdd')) {
125
            return action($this->controller.'@getAdd');
126
        }else{
127
            return null;
128
        }
129
    }
130
131
    public function addSaveURL()
132
    {
133
        if($this->controller_class && method_exists($this->controller_class, 'postAddSave')) {
134
            return action($this->controller.'@postAddSave');
135
        }else{
136
            return null;
137
        }
138
    }
139
140
    public function editURL($id = null)
141
    {
142
        if($this->controller_class && method_exists($this->controller_class, 'getEdit')) {
143
            return action($this->controller.'@getEdit',['id'=>$id]);
144
        }else{
145
            return null;
146
        }
147
    }
148
149
    public function editSaveURL($id = null)
150
    {
151
        if(method_exists($this->controller_class, 'postEditSave')) {
152
            return action($this->controller.'@postEditSave',['id'=>$id]);
153
        }else{
154
            return null;
155
        }
156
    }
157
158
    public function detailURL($id=null)
159
    {
160
        if($this->controller_class && method_exists($this->controller_class, 'getDetail')) {
161
            return action($this->controller.'@getDetail',['id'=>$id]);
162
        }else{
163
            return null;
164
        }
165
    }
166
167
    public function deleteURL($id=null)
168
    {
169
        if($this->controller_class && method_exists($this->controller_class, 'getDelete')) {
170
            return action($this->controller.'@getDelete',['id'=>$id]);
171
        }else{
172
            return null;
173
        }
174
    }
175
176
    public function url($path = null)
177
    {
178
        if($this->controller_class && method_exists($this->controller_class, 'getIndex')) {
179
            return trim(action($this->controller.'@getIndex').'/'.$path,'/');
180
        }else{
181
            return null;
182
        }
183
    }
184
}