Passed
Push — master ( 8ab489...e9dde7 )
by Iman
04:08
created

AdminUsersController::makeForm()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 22
nc 1
nop 0
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use crocodicstudio\crudbooster\controllers\CBController;
6
use crocodicstudio\crudbooster\helpers\CRUDBooster, CB;
7
use Illuminate\Support\Facades\Request;
8
9
class AdminUsersController extends CBController
10
{
11
    public function cbInit()
12
    {
13
        $this->makeConfigs();
14
        $this->makeCols();
15
        $this->makeForm();
16
    }
17
18
    public function hookQueryIndex(&$query)
19
    {
20
        $query->join('cms_privileges', 'cms_privileges.id', '=', 'id_cms_privileges');
21
        $query->addSelect('cms_privileges.name as cms_privileges_name');
22
    }
23
24
    public function getProfile()
25
    {
26
        $this->genericLoader();
27
        $this->cbFormLoader();
28
        $this->button_addmore = false;
29
        $this->button_cancel = false;
30
        $this->button_show = false;
0 ignored issues
show
Bug Best Practice introduced by
The property button_show does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
        $this->buttonAdd = false;
32
        $this->deleteBtn = false;
33
        $this->hide_form = ['id_cms_privileges'];
34
35
        session()->put('current_row_id', CRUDBooster::myId());
36
        $this->data['return_url'] = Request::fullUrl();
37
38
        $data['page_title'] = cbTrans("label_button_profile");
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
39
        $data['row'] = CRUDBooster::first('cms_users', CRUDBooster::myId());
40
        return $this->cbView('crudbooster::form.form', $data);
41
    }
42
43
    private function makeForm()
44
    {
45
        # START FORM DO NOT REMOVE THIS LINE
46
        $this->form = [];
47
        $this->form[] = ['label' => 'name', 'name' => 'name', 'required' => true, 'validation' => 'required|alpha_spaces|min:3'];
48
        $this->form[] = [
49
            'label' => "Email",
50
            'name' => "email",
51
            'required' => true,
52
            'type' => 'email',
53
            'validation' => 'required|email|unique:cms_users,email,'.CRUDBooster::getCurrentId(),
54
        ];
55
        $this->form[] = [
56
            'label' => "Photo",
57
            'name' => "photo",
58
            'type' => "upload",
59
            "help" => "Recommended resolution is 200x200px",
60
            'required' => true,
61
            'validation' => 'required|image|max:1000',
62
        ];
63
        $this->form[] = [
64
            'label' => "Privilege",
65
            'name' => "id_cms_privileges",
66
            'type' => "select_datatable",
67
            "options" => ["table" => "cms_privileges", "field_value" => "id", "field_label" => 'name'],
68
            'required' => true,
69
        ];
70
        $this->form[] = ['label' => "Password", 'name' => "password", 'type' => "password", "help" => "Please leave empty if not change"];
71
        # END FORM DO NOT REMOVE THIS LINE
72
    }
73
74
    private function makeCols()
75
    {
76
        # START COLUMNS DO NOT REMOVE THIS LINE
77
        $this->col = [];
78
        $this->col[] = ['label' => 'name', 'name' => 'name'];
79
        $this->col[] = ['label' => "Email", 'name' => "email"];
80
        $this->col[] = ['label' => "Privilege", 'name' => "cms_privileges_name"];
81
        $this->col[] = ['label' => "Photo", 'name' => "photo", "image" => 1];
82
        # END COLUMNS DO NOT REMOVE THIS LINE
83
    }
84
85
    private function makeConfigs()
86
    {
87
        # START CONFIGURATION DO NOT REMOVE THIS LINE
88
        $this->table = 'cms_users';
89
        $this->titleField = 'name';
90
        $this->button_action_style = 'button_icon';
91
        $this->button_import = false;
92
        $this->buttonExport = false;
93
        $this->button_save = true;
94
        # END CONFIGURATION DO NOT REMOVE THIS LINE
95
    }
96
}
97