1 | <?php |
||
22 | class User extends FormAbstract |
||
23 | { |
||
24 | /** |
||
25 | * @return array |
||
26 | */ |
||
27 | 2 | public function actions() |
|
28 | { |
||
29 | 2 | if ($this->isEditing()) { |
|
30 | return [ |
||
31 | 1 | 'submit' => 'update', |
|
32 | ]; |
||
33 | } |
||
34 | |||
35 | 1 | return ['submit' => 'add_user']; |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * @return array |
||
40 | */ |
||
41 | 5 | public function fields() |
|
42 | { |
||
43 | $fields = [ |
||
44 | 'firstname' => [ |
||
45 | 'type' => 'text', |
||
46 | 'label' => 'first_name', |
||
47 | 5 | ], |
|
48 | 'lastname' => [ |
||
49 | 'type' => 'text', |
||
50 | 'label' => 'last_name', |
||
51 | ], |
||
52 | 'email' => [ |
||
53 | 'type' => 'text', |
||
54 | 'label' => 'email', |
||
55 | ], |
||
56 | 'private' => [ |
||
57 | 5 | 'type' => 'select', |
|
58 | 5 | 'label' => 'visibility', |
|
59 | 'options' => [ |
||
60 | 5 | UserModel::PRIVATE_YES => trans('tinyissue.private'), |
|
61 | 5 | UserModel::PRIVATE_NO => trans('tinyissue.public'), |
|
62 | ], |
||
63 | ], |
||
64 | |||
65 | ]; |
||
66 | |||
67 | 5 | $fields += $this->innerFields(); |
|
68 | |||
69 | 5 | return $fields; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * Return password fields. |
||
74 | * |
||
75 | * @return array |
||
76 | */ |
||
77 | 4 | protected function passwordFields() |
|
78 | { |
||
79 | 4 | $fields = []; |
|
80 | 4 | $fields['only_complete_if_changing_password'] = [ |
|
81 | 'type' => 'legend', |
||
82 | ]; |
||
83 | 4 | $fields['password'] = [ |
|
84 | 'type' => 'password', |
||
85 | 'label' => 'new_password', |
||
86 | ]; |
||
87 | 4 | $fields['password_confirmation'] = [ |
|
88 | 'type' => 'password', |
||
89 | 'label' => 'confirm', |
||
90 | ]; |
||
91 | |||
92 | 4 | return $fields; |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * For sub-classes to add extra fields or remove fields. |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | 2 | protected function innerFields() |
|
101 | { |
||
102 | $fields = [ |
||
103 | 'extended_user_settings' => [ |
||
104 | 'type' => 'legend', |
||
105 | 2 | ], |
|
106 | 'role_id' => [ |
||
107 | 2 | 'type' => 'select', |
|
108 | 2 | 'label' => 'role', |
|
109 | 2 | 'options' => Role::dropdown(), |
|
110 | ], |
||
111 | 'status' => [ |
||
112 | 2 | 'type' => 'select', |
|
113 | 2 | 'label' => 'Status', |
|
114 | 2 | 'options' => UserModel::getStatuses(), |
|
115 | ], |
||
116 | ]; |
||
117 | |||
118 | 2 | if ($this->isEditing()) { |
|
119 | 1 | $fields += $this->passwordFields(); |
|
120 | } |
||
121 | |||
122 | 2 | return $fields; |
|
123 | } |
||
124 | |||
125 | /** |
||
126 | * @return array |
||
127 | */ |
||
128 | 5 | public function rules() |
|
129 | { |
||
130 | $rules = [ |
||
131 | 5 | 'firstname' => 'required|max:50', |
|
132 | 'lastname' => 'required|max:50', |
||
133 | 'email' => 'required|email', |
||
134 | ]; |
||
135 | |||
136 | 5 | if ($this->isEditing()) { |
|
137 | 4 | $rules['email'] .= '|unique:users,email,' . $this->getModel()->id; |
|
138 | 4 | $rules['password'] = 'confirmed'; |
|
139 | } else { |
||
140 | 1 | $rules['email'] .= '|unique:users,email'; |
|
141 | } |
||
142 | |||
143 | 5 | return $rules; |
|
144 | } |
||
145 | |||
146 | /** |
||
147 | * @return string |
||
148 | */ |
||
149 | 1 | public function getRedirectUrl() |
|
157 | } |
||
158 |