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\AbstractGroup; |
14
|
|
|
use Phalcon\Validation\Validator\PresenceOf; |
15
|
|
|
use Phalcon\Validation\Validator\StringLength\Max; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Group |
19
|
|
|
* |
20
|
|
|
* @property UserGroup[] $UserNode |
21
|
|
|
* @property User[] $UserList |
22
|
|
|
* @property GroupRole[] $RoleNode |
23
|
|
|
* @property Role[] $RoleList |
24
|
|
|
* @property GroupType[] $TypeNode |
25
|
|
|
* @property Type[] $TypeList |
26
|
|
|
* |
27
|
|
|
* @method UserGroup[] getUserNode($params = null) |
28
|
|
|
* @method User[] getUserList($params = null) |
29
|
|
|
* @method GroupRole[] getRoleNode($params = null) |
30
|
|
|
* @method Role[] getRoleList($params = null) |
31
|
|
|
* @method GroupType[] getTypeNode($params = null) |
32
|
|
|
* @method Type[] getTypeList($params = null) |
33
|
|
|
* |
34
|
|
|
* @package Zemit\Models |
35
|
|
|
*/ |
36
|
|
|
class Group extends AbstractGroup |
37
|
|
|
{ |
38
|
|
|
protected $deleted = self::NO; |
39
|
|
|
protected $position = self::NO; |
40
|
|
|
|
41
|
|
|
public function initialize() |
42
|
|
|
{ |
43
|
|
|
parent::initialize(); |
44
|
|
|
|
45
|
|
|
// User relationship |
46
|
|
|
$this->hasMany('id', UserGroup::class, 'groupId', ['alias' => 'UserNode']); |
47
|
|
|
$this->hasManyToMany('id', UserGroup::Class, 'groupId', |
|
|
|
|
48
|
|
|
'userId', User::class, 'id', ['alias' => 'UserList']); |
49
|
|
|
|
50
|
|
|
// Role relationship |
51
|
|
|
$this->hasMany('id', GroupRole::class, 'groupId', ['alias' => 'RoleNode']); |
52
|
|
|
$this->hasManyToMany('id', GroupRole::class, 'groupId', |
53
|
|
|
'roleId', Role::class, 'id', ['alias' => 'RoleList']); |
54
|
|
|
|
55
|
|
|
// Type relationship |
56
|
|
|
$this->hasMany('id', GroupType::class, 'groupId', ['alias' => 'TypeNode']); |
57
|
|
|
$this->hasManyToMany('id', GroupType::class, 'groupId', |
58
|
|
|
'typeId', Type::class, 'id', ['alias' => 'TypeList']); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function beforeValidation() |
62
|
|
|
{ |
63
|
|
|
if (!$this->index) { |
64
|
|
|
$this->setIndex($this->getLabelFr()); |
65
|
|
|
} |
66
|
|
|
if (!$this->labelEn) { |
67
|
|
|
$this->setLabelEn($this->getLabelFr()); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function validation() |
72
|
|
|
{ |
73
|
|
|
$validator = $this->genericValidation(); |
74
|
|
|
|
75
|
|
|
$validator->add('index', new Max(['max' => 50, 'message' => $this->_('index') .': '. $this->_('length-exceeded')])); |
76
|
|
|
$validator->add('index', new PresenceOf(['message' => $this->_('index') .': '. $this->_('required')])); |
77
|
|
|
|
78
|
|
|
$validator->add('labelFr', new PresenceOf(['message' => $this->_('label-fr') .': '. $this->_('required')])); |
79
|
|
|
$validator->add('labelFr', new Max(['max' => 100, 'message' => $this->_('label-fr') .': '. $this->_('length-exceeded')])); |
80
|
|
|
|
81
|
|
|
$validator->add('labelEn', new PresenceOf(['message' => $this->_('label-en') .': '. $this->_('required')])); |
82
|
|
|
$validator->add('labelFr', new Max(['max' => 100, 'message' => $this->_('label-en') .': '. $this->_('length-exceeded')])); |
83
|
|
|
|
84
|
|
|
return $this->validate($validator); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|