1 | <?php |
||||
2 | declare(strict_types=1); |
||||
3 | |||||
4 | namespace Gewaer\Models; |
||||
5 | |||||
6 | use Gewaer\Traits\PermissionsTrait; |
||||
7 | use Gewaer\Exception\ModelException; |
||||
8 | |||||
9 | class Users extends \Baka\Auth\Models\Users |
||||
10 | { |
||||
11 | use PermissionsTrait; |
||||
12 | |||||
13 | public $roles_id; |
||||
14 | |||||
15 | /** |
||||
16 | * Initialize method for model. |
||||
17 | */ |
||||
18 | 5 | public function initialize() |
|||
19 | { |
||||
20 | 5 | parent::initialize(); |
|||
21 | |||||
22 | 5 | $this->setSource('users'); |
|||
23 | |||||
24 | 5 | $this->hasOne( |
|||
25 | 5 | 'id', |
|||
26 | 5 | 'Gewaer\Models\UserRoles', |
|||
27 | 5 | 'users_id', |
|||
28 | 5 | ['alias' => 'permission'] |
|||
29 | ); |
||||
30 | |||||
31 | 5 | $this->hasMany( |
|||
32 | 5 | 'id', |
|||
33 | 5 | 'Gewaer\Models\UserRoles', |
|||
34 | 5 | 'users_id', |
|||
35 | 5 | ['alias' => 'permissions'] |
|||
36 | ); |
||||
37 | 5 | } |
|||
38 | |||||
39 | /** |
||||
40 | * Returns table name mapped in the model. |
||||
41 | * |
||||
42 | * @return string |
||||
43 | */ |
||||
44 | 4 | public function getSource(): string |
|||
45 | { |
||||
46 | 4 | return 'users'; |
|||
47 | } |
||||
48 | |||||
49 | /** |
||||
50 | * Get the User key for redis |
||||
51 | * |
||||
52 | * @return string |
||||
53 | */ |
||||
54 | public function getKey(): string |
||||
55 | { |
||||
56 | return $this->id; |
||||
57 | } |
||||
58 | |||||
59 | /** |
||||
60 | * What to do after the creation of a new users |
||||
61 | * - Assign default role |
||||
62 | * |
||||
63 | * @return void |
||||
64 | */ |
||||
65 | public function afterCreate() |
||||
66 | { |
||||
67 | parent::afterCreate(); |
||||
68 | |||||
69 | //Assign admin role to the system if we dont get a specify role |
||||
70 | if (empty($this->roles_id)) { |
||||
71 | $role = Roles::findFirstByName('Admins'); |
||||
1 ignored issue
–
show
Bug
introduced
by
![]() |
|||||
72 | $this->roles_id = $role->getId(); |
||||
73 | $this->update(); |
||||
74 | |||||
75 | $userRoles = new UserRoles(); |
||||
76 | $userRoles->users_id = $this->getId(); |
||||
77 | $userRoles->roles_id = $role->getId(); |
||||
78 | $userRoles->apps_id = $this->di->getConfig()->app->id; |
||||
2 ignored issues
–
show
The method
getConfig() does not exist on Phalcon\Mvc\Model\Resultset .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() The property
di does not exist on Gewaer\Models\Users . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
79 | $userRoles->company_id = $this->default_company; |
||||
80 | if (!$userRoles->save()) { |
||||
81 | throw new ModelException((string) current($userRoles->getMessages())); |
||||
82 | } |
||||
83 | } |
||||
84 | } |
||||
85 | } |
||||
86 |