Passed
Push — master ( d2343f...8ab489 )
by Iman
04:02
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
        # START CONFIGURATION DO NOT REMOVE THIS LINE
14
        $this->table = 'cms_users';
15
        $this->titleField = 'name';
16
        $this->button_action_style = 'button_icon';
17
        $this->button_import = false;
18
        $this->buttonExport = false;
19
        $this->button_save = true;
20
        # END CONFIGURATION DO NOT REMOVE THIS LINE
21
        $this->makeCols();
22
        $this->makeForm();
23
    }
24
25
    public function hookQueryIndex(&$query)
26
    {
27
        $query->join('cms_privileges', 'cms_privileges.id', '=', 'id_cms_privileges');
28
        $query->addSelect('cms_privileges.name as cms_privileges_name');
29
    }
30
31
    public function getProfile()
32
    {
33
        $this->genericLoader();
34
        $this->cbFormLoader();
35
        $this->button_addmore = false;
36
        $this->button_cancel = false;
37
        $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...
38
        $this->buttonAdd = false;
39
        $this->deleteBtn = false;
40
        $this->hide_form = ['id_cms_privileges'];
41
42
        session()->put('current_row_id', CRUDBooster::myId());
43
        $this->data['return_url'] = Request::fullUrl();
44
45
        $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...
46
        $data['row'] = CRUDBooster::first('cms_users', CRUDBooster::myId());
47
        return $this->cbView('crudbooster::form.form', $data);
48
    }
49
50
    private function makeForm()
51
    {
52
# START FORM DO NOT REMOVE THIS LINE
53
        $this->form = [];
54
        $this->form[] = ['label' => 'name', 'name' => 'name', 'required' => true, 'validation' => 'required|alpha_spaces|min:3'];
55
        $this->form[] = [
56
            'label' => "Email",
57
            'name' => "email",
58
            'required' => true,
59
            'type' => 'email',
60
            'validation' => 'required|email|unique:cms_users,email,'.CRUDBooster::getCurrentId(),
61
        ];
62
        $this->form[] = [
63
            'label' => "Photo",
64
            'name' => "photo",
65
            'type' => "upload",
66
            "help" => "Recommended resolution is 200x200px",
67
            'required' => true,
68
            'validation' => 'required|image|max:1000',
69
        ];
70
        $this->form[] = [
71
            'label' => "Privilege",
72
            'name' => "id_cms_privileges",
73
            'type' => "select_datatable",
74
            "options" => ["table" => "cms_privileges", "field_value" => "id", "field_label" => 'name'],
75
            'required' => true,
76
        ];
77
        $this->form[] = ['label' => "Password", 'name' => "password", 'type' => "password", "help" => "Please leave empty if not change"];
78
        # END FORM DO NOT REMOVE THIS LINE
79
    }
80
81
    private function makeCols()
82
    {
83
# START COLUMNS DO NOT REMOVE THIS LINE
84
        $this->col = [];
85
        $this->col[] = ['label' => 'name', 'name' => 'name'];
86
        $this->col[] = ['label' => "Email", 'name' => "email"];
87
        $this->col[] = ['label' => "Privilege", 'name' => "cms_privileges_name"];
88
        $this->col[] = ['label' => "Photo", 'name' => "photo", "image" => 1];
89
        # END COLUMNS DO NOT REMOVE THIS LINE
90
    }
91
}
92