|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Conditions\RecordFields; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Owner condition record field class. |
|
7
|
|
|
* |
|
8
|
|
|
* @package UIType |
|
9
|
|
|
* |
|
10
|
|
|
* @copyright YetiForce S.A. |
|
11
|
|
|
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com) |
|
12
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class OwnerField extends BaseField |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Is watching record operator. |
|
18
|
|
|
* |
|
19
|
|
|
* @return array |
|
20
|
|
|
*/ |
|
21
|
|
|
public function operatorWr() |
|
22
|
|
|
{ |
|
23
|
|
|
return \Vtiger_Watchdog_Model::getInstanceById($this->recordModel->getId(), $this->recordModel->getModuleName())->isWatchingRecord(); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Users who belong to the same group as the currently logged in user. |
|
28
|
|
|
* |
|
29
|
|
|
* @return bool |
|
30
|
|
|
*/ |
|
31
|
|
|
public function operatorOgrU(): bool |
|
32
|
|
|
{ |
|
33
|
|
|
$groups = \App\Fields\Owner::getInstance($this->recordModel->getModuleName())->getGroups(false, 'private'); |
|
34
|
|
|
$usersByGroup = []; |
|
35
|
|
|
if ($groups) { |
|
36
|
|
|
foreach (array_keys($groups) as $idGroup) { |
|
37
|
|
|
$usersByGroup = (new \App\Db\Query())->select(['userid'])->from(["condition_groups_{$idGroup}_" . \App\Layout::getUniqueId() => \App\PrivilegeUtil::getQueryToUsersByGroup((int) $idGroup)])->column(); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
return in_array($this->getValue(), $usersByGroup); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Is not watching record operator. |
|
45
|
|
|
* |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
public function operatorNwr() |
|
49
|
|
|
{ |
|
50
|
|
|
return !\Vtiger_Watchdog_Model::getInstanceById($this->recordModel->getId(), $this->recordModel->getModuleName())->isWatchingRecord(); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** {@inheritdoc} */ |
|
54
|
|
|
public function operatorE() |
|
55
|
|
|
{ |
|
56
|
|
|
if (!\is_array($this->value)) { |
|
57
|
|
|
$this->value = explode('##', $this->value); |
|
58
|
|
|
} |
|
59
|
|
|
$result = false; |
|
60
|
|
|
foreach ($this->value as $value) { |
|
61
|
|
|
if (\in_array($this->getValue(), $this->getMemberValue($value))) { |
|
62
|
|
|
$result = true; |
|
63
|
|
|
break; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
return $result; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** {@inheritdoc} */ |
|
70
|
|
|
public function operatorN() |
|
71
|
|
|
{ |
|
72
|
|
|
if (!\is_array($this->value)) { |
|
73
|
|
|
$this->value = explode('##', $this->value); |
|
74
|
|
|
} |
|
75
|
|
|
$result = true; |
|
76
|
|
|
foreach ($this->value as $value) { |
|
77
|
|
|
if (\in_array($this->getValue(), $this->getMemberValue($value))) { |
|
78
|
|
|
$result = false; |
|
79
|
|
|
break; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
return $result; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Gets conditions for member. |
|
87
|
|
|
* |
|
88
|
|
|
* @param int|string $member |
|
89
|
|
|
* |
|
90
|
|
|
* @return int[] |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getMemberValue($member): array |
|
93
|
|
|
{ |
|
94
|
|
|
if (is_numeric($member)) { |
|
95
|
|
|
return [$member]; |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
[$type, $id] = explode(':', $member); |
|
98
|
|
|
switch ($type) { |
|
99
|
|
|
case \App\PrivilegeUtil::MEMBER_TYPE_GROUPS: |
|
100
|
|
|
$value = (new \App\Db\Query())->select(['userid'])->from(["condition_{$type}_{$id}_" . \App\Layout::getUniqueId() => \App\PrivilegeUtil::getQueryToUsersByGroup((int) $id)])->column(); |
|
101
|
|
|
break; |
|
102
|
|
|
case \App\PrivilegeUtil::MEMBER_TYPE_ROLES: |
|
103
|
|
|
$value = \App\PrivilegeUtil::getQueryToUsersByRole($id)->column(); |
|
104
|
|
|
break; |
|
105
|
|
|
case \App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES: |
|
106
|
|
|
$value = \App\PrivilegeUtil::getQueryToUsersByRoleAndSubordinate($id)->column(); |
|
107
|
|
|
break; |
|
108
|
|
|
default: |
|
109
|
|
|
$value = [-1]; |
|
110
|
|
|
break; |
|
111
|
|
|
} |
|
112
|
|
|
return $value; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|