Passed
Pull Request — master (#1239)
by
unknown
05:35
created

AdminUsersController::hook_before_edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Crocodicstudio\Crudbooster\Controllers\CBController;
6
use Crocodicstudio\Crudbooster\Helpers\CRUDBooster;
7
8
class AdminUsersController extends CBController
9
{
10
    public function cbInit()
11
    {
12
        $this->makeConfigs();
13
        $this->makeCols();
14
        $this->makeForm();
15
    }
16
17
    public function hookQueryIndex($query)
18
    {
19
        $query->join('cms_roles', 'cms_roles.id', '=', 'cms_roles_id');
20
        $query->addSelect('cms_roles.name as cms_roles_name');
21
    }
22
23
    public function getProfile()
24
    {
25
        $this->genericLoader();
26
        $this->cbFormLoader();
27
        $this->addMoreButton = false;
28
        $this->buttonCancel = false;
29
        $this->buttonShow = false;
30
        $this->buttonAdd = false;
31
        $this->deleteBtn = false;
0 ignored issues
show
Bug Best Practice introduced by
The property deleteBtn does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32
        $this->hide_form = ['cms_roles_id'];
33
34
        session()->put('current_row_id', auth('cbAdmin')->id());
35
36
        $this->data['return_url'] = request()->fullUrl();
37
38
        $data = [
39
            'page_title' => cbTrans("label_button_profile"),
40
            'row' => cbUser(),
41
        ];
42
        return $this->cbView('crudbooster::form.form', $data);
43
    }
44
45
    private function makeForm()
46
    {
47
        # START FORM DO NOT REMOVE THIS LINE
48
        $this->form = [];
49
        $this->form[] = [
50
            'label' => 'name',
51
            'name' => 'name',
52
            'required' => true,
53
            'validation' => 'required|alpha_spaces|min:3'
54
        ];
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
            'validation' => 'image|max:1000',
68
        ];
69
        $this->form[] = [
70
            'label' => "Privilege",
71
            'name' => "cms_roles_id",
72
            'type' => "select_datatable",
73
            "options" => ["table" => "cms_roles", "field_value" => "id", "field_label" => 'name'],
74
            'required' => true,
75
        ];					
76
		$this->form[] = array("label"=>"Password","name"=>"password","type"=>"password","help"=>"Please leave empty if not change");
77
		$this->form[] = array("label"=>"Password Confirmation","name"=>"password_confirmation","type"=>"password","help"=>"Please leave empty if not change");
78
		
79
        # END FORM DO NOT REMOVE THIS LINE
80
    }
81
82
    private function makeCols()
83
    {
84
        # START COLUMNS DO NOT REMOVE THIS LINE
85
        $this->col = [];
86
        $this->col[] = ['label' => 'Name', 'name' => 'name'];
87
        $this->col[] = ['label' => "Email", 'name' => "email"];
88
        $this->col[] = ['label' => "Role", 'name' => "cms_roles_name"];
89
        $this->col[] = ['label' => "Photo", 'name' => "photo", "image" => 1];
90
        # END COLUMNS DO NOT REMOVE THIS LINE
91
    }
92
93
    private function makeConfigs()
94
    {
95
        # START CONFIGURATION DO NOT REMOVE THIS LINE
96
        $this->table = 'cms_users';
97
        $this->titleField = 'name';
98
        $this->buttonActionStyle = 'button_icon';
99
        $this->buttonImport = false;
100
        $this->buttonExport = false;
101
        $this->button_save = true;
102
        # END CONFIGURATION DO NOT REMOVE THIS LINE
103
    }
104
    public function hook_before_edit(&$postdata,$id) { 
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

104
    public function hook_before_edit(&$postdata,/** @scrutinizer ignore-unused */ $id) { 

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
105
		unset($postdata['password_confirmation']);
106
	}
107
	public function hook_before_add(&$postdata) {      
108
	    unset($postdata['password_confirmation']);
109
	}
110
}
111