|
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\Base\AbstractGroupRole; |
|
14
|
|
|
use Phalcon\Validation\Validator\PresenceOf; |
|
15
|
|
|
use Phalcon\Validation\Validator\Uniqueness; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class GroupRole |
|
19
|
|
|
* |
|
20
|
|
|
* @property Group $Group |
|
21
|
|
|
* @property Role $Role |
|
22
|
|
|
* @property Group $GroupEntity |
|
23
|
|
|
* @property Role $RoleEntity |
|
24
|
|
|
* |
|
25
|
|
|
* @method Group getGroup($params = null) |
|
26
|
|
|
* @method Role getRole($params = null) |
|
27
|
|
|
* @method Group getGroupEntity($params = null) |
|
28
|
|
|
* @method Role getRoleEntity($params = null) |
|
29
|
|
|
* |
|
30
|
|
|
* @package Zemit\Models |
|
31
|
|
|
*/ |
|
32
|
|
|
class GroupRole extends AbstractGroupRole |
|
33
|
|
|
{ |
|
34
|
|
|
protected $deleted = self::NO; |
|
35
|
|
|
protected $position = self::NO; |
|
36
|
|
|
|
|
37
|
|
|
public function initialize() |
|
38
|
|
|
{ |
|
39
|
|
|
parent::initialize(); |
|
40
|
|
|
|
|
41
|
|
|
$this->hasOne('groupId', Group::class, 'id', ['alias' => 'GroupEntity']); |
|
42
|
|
|
$this->hasOne('roleId', Role::class, 'id', ['alias' => 'RoleEntity']); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function validation() |
|
46
|
|
|
{ |
|
47
|
|
|
$validator = $this->genericValidation(); |
|
48
|
|
|
|
|
49
|
|
|
$validator->add('groupId', new PresenceOf(['message' => $this->_('required')])); |
|
50
|
|
|
$validator->add('roleId', new PresenceOf(['message' => $this->_('required')])); |
|
51
|
|
|
$validator->add(['groupId', 'roleId'], new Uniqueness(['message' => $this->_('not-unique')])); |
|
52
|
|
|
|
|
53
|
|
|
return $this->validate($validator); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|