1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
8
|
|
|
* @link https://vistart.me/ |
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
10
|
|
|
* @license https://vistart.me/license/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace rhosocial\organization; |
14
|
|
|
|
15
|
|
|
use rhosocial\organization\queries\DepartmentQuery; |
16
|
|
|
use yii\behaviors\AttributeBehavior; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Department. |
20
|
|
|
* The department can open sub-departments. |
21
|
|
|
* A departments can not exist alone, only subordinate to an organization. |
22
|
|
|
* It can move from one department or organization to another department or |
23
|
|
|
* organization, but the subordinate relationship can not be a circle. |
24
|
|
|
* |
25
|
|
|
* Each department should have at least one member, and members have at least |
26
|
|
|
* one administrator, who can manage the daily affairs of the department, but can |
27
|
|
|
* not manage the sub-department or sub-organization's affairs, as he/she may not |
28
|
|
|
* be the administrator of sub-one. |
29
|
|
|
* |
30
|
|
|
* @version 1.0 |
31
|
|
|
* @author vistart <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
class Department extends BaseOrganization |
34
|
|
|
{ |
35
|
|
|
public $parentAttribute = 'parent'; |
36
|
|
|
|
37
|
1 |
|
public function init() |
38
|
|
|
{ |
39
|
1 |
|
if (!is_string($this->queryClass)) { |
40
|
1 |
|
$this->queryClass = DepartmentQuery::class; |
41
|
|
|
} |
42
|
1 |
|
parent::init(); |
43
|
1 |
|
} |
44
|
|
|
|
45
|
1 |
|
protected function typeAttributeBehavior() |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
[ |
49
|
|
|
'class' => AttributeBehavior::class, |
50
|
|
|
'attributes' => [ |
51
|
1 |
|
self::EVENT_BEFORE_INSERT => 'type', |
52
|
1 |
|
self::EVENT_BEFORE_UPDATE => 'type', |
53
|
|
|
], |
54
|
1 |
|
'value' => self::TYPE_DEPARTMENT, |
55
|
|
|
] |
56
|
1 |
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* The default value of `type` attribute is `ORGANIZATION`(1). |
61
|
|
|
* @return array Rules associated with `type` attribute. |
62
|
|
|
*/ |
63
|
1 |
|
protected function getTypeRules() |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
1 |
|
['type', 'default', 'value' => self::TYPE_DEPARTMENT], |
67
|
|
|
['type', 'required'], |
68
|
1 |
|
['type', 'in', 'range' => [self::TYPE_DEPARTMENT]], |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
75
|
1 |
|
public static function find() |
76
|
|
|
{ |
77
|
1 |
|
return parent::find()->andWhere(['type' => self::TYPE_DEPARTMENT]); |
78
|
|
|
} |
79
|
|
|
} |