1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Zemit Framework. |
4
|
|
|
* |
5
|
|
|
* (c) Zemit Team <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Zemit\Models; |
12
|
|
|
|
13
|
|
|
use Zemit\Models\Abstracts\AbstractUserRole; |
14
|
|
|
use Phalcon\Filter\Validation\Validator\PresenceOf; |
15
|
|
|
use Phalcon\Filter\Validation\Validator\Uniqueness; |
16
|
|
|
use Zemit\Models\Interfaces\UserRoleInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @property User $UserEntity |
20
|
|
|
* @property Role $RoleEntity |
21
|
|
|
* |
22
|
|
|
* @method User getUserEntity(?array $params = null) |
23
|
|
|
* @method Role getRoleEntity(?array $params = null) |
24
|
|
|
*/ |
25
|
|
|
class UserRole extends AbstractUserRole implements UserRoleInterface |
26
|
|
|
{ |
27
|
|
|
protected $deleted = self::NO; |
28
|
|
|
protected $position = self::NO; |
29
|
|
|
|
30
|
2 |
|
public function initialize(): void |
31
|
|
|
{ |
32
|
2 |
|
parent::initialize(); |
33
|
|
|
|
34
|
2 |
|
$this->hasOne('userId', User::class, 'id', ['alias' => 'UserEntity']); |
35
|
2 |
|
$this->hasOne('roleId', Role::class, 'id', ['alias' => 'RoleEntity']); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function validation(): bool |
39
|
|
|
{ |
40
|
|
|
$validator = $this->genericValidation(); |
41
|
|
|
|
42
|
|
|
$validator->add('userId', new PresenceOf(['message' => $this->_('required')])); |
43
|
|
|
$validator->add('roleId', new PresenceOf(['message' => $this->_('required')])); |
44
|
|
|
$validator->add(['userId', 'roleId'], new Uniqueness(['message' => $this->_('not-unique')])); |
45
|
|
|
|
46
|
|
|
return $this->validate($validator); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|