|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Conditions\QueryFields; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Shared Owner Query 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
|
|
|
* @author Radosław Skrzypczak <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class SharedOwnerField extends BaseField |
|
16
|
|
|
{ |
|
17
|
|
|
/** {@inheritdoc} */ |
|
18
|
|
|
public function getColumnName(): string |
|
19
|
|
|
{ |
|
20
|
|
|
if ($this->fullColumnName) { |
|
21
|
|
|
return $this->fullColumnName; |
|
22
|
|
|
} |
|
23
|
|
|
if ($this->related) { |
|
|
|
|
|
|
24
|
|
|
$fieldModel = $this->queryGenerator->getModuleField($this->related['sourceField']); |
|
25
|
|
|
return $this->fullColumnName = "{$fieldModel->getTableName()}.{$fieldModel->getColumnName()}"; |
|
26
|
|
|
} |
|
27
|
|
|
$focus = $this->queryGenerator->getEntityModel(); |
|
28
|
|
|
return $this->fullColumnName = "{$focus->table_name}.{$focus->table_index}"; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Equals operator. |
|
33
|
|
|
* |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
|
|
public function operatorE(): array |
|
37
|
|
|
{ |
|
38
|
|
|
if (empty($this->value)) { |
|
39
|
|
|
return []; |
|
40
|
|
|
} |
|
41
|
|
|
return [$this->getColumnName() => (new \App\Db\Query())->select(['crmid'])->from('u_#__crmentity_showners')->where(['userid' => explode('##', $this->value)])]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Not equal operator. |
|
46
|
|
|
* |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
|
|
public function operatorN(): array |
|
50
|
|
|
{ |
|
51
|
|
|
if (empty($this->value)) { |
|
52
|
|
|
return []; |
|
53
|
|
|
} |
|
54
|
|
|
return ['NOT IN', $this->getColumnName(), (new \App\Db\Query())->select(['crmid'])->from('u_#__crmentity_showners')->where(['userid' => explode('##', $this->value)])]; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Currently logged user. |
|
59
|
|
|
* |
|
60
|
|
|
* @return array |
|
61
|
|
|
*/ |
|
62
|
|
|
public function operatorOm() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->value = \App\User::getCurrentUserId(); |
|
65
|
|
|
return $this->operatorE(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Currently logged-in user groups. |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
public function operatorOgr(): array |
|
74
|
|
|
{ |
|
75
|
|
|
$this->value = implode('##', array_keys(\App\Fields\Owner::getInstance($this->getModuleName())->getGroups(false, 'private'))); |
|
76
|
|
|
return $this->operatorE(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Users who belong to the same group as the currently logged in user. |
|
81
|
|
|
* |
|
82
|
|
|
* @return array |
|
83
|
|
|
*/ |
|
84
|
|
|
public function operatorOgrU(): array |
|
85
|
|
|
{ |
|
86
|
|
|
$groups = \App\Fields\Owner::getInstance($this->getModuleName())->getGroups(false, 'private'); |
|
87
|
|
|
if ($groups) { |
|
88
|
|
|
$condition = ['or']; |
|
89
|
|
|
foreach (array_keys($groups) as $idGroup) { |
|
90
|
|
|
$condition[] = [$this->getColumnName() => (new \App\Db\Query())->select(['crmid'])->from('u_#__crmentity_showners')->where(['u_#__crmentity_showners.userid' => (new \App\Db\Query())->select(['userid'])->from(["condition_groups_{$idGroup}_" . \App\Layout::getUniqueId() => \App\PrivilegeUtil::getQueryToUsersByGroup((int) $idGroup)])])]; |
|
91
|
|
|
} |
|
92
|
|
|
} else { |
|
93
|
|
|
$condition = [$this->getColumnName() => (new \yii\db\Expression('0=1'))]; |
|
94
|
|
|
} |
|
95
|
|
|
return $condition; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Contains operator. |
|
100
|
|
|
* |
|
101
|
|
|
* @return array |
|
102
|
|
|
*/ |
|
103
|
|
|
public function operatorC(): array |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->operatorE(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Is not empty operator. |
|
110
|
|
|
* |
|
111
|
|
|
* @return array |
|
112
|
|
|
*/ |
|
113
|
|
|
public function operatorNy(): array |
|
114
|
|
|
{ |
|
115
|
|
|
if ($this->related) { |
|
|
|
|
|
|
116
|
|
|
$fieldModel = $this->queryGenerator->getModuleField($this->related['sourceField']); |
|
117
|
|
|
$query = (new \App\Db\Query())->select(['crmid'])->from('u_#__crmentity_showners') |
|
118
|
|
|
->innerJoin($fieldModel->getTableName(), "u_#__crmentity_showners.crmid={$fieldModel->getTableName()}.{$fieldModel->getColumnName()}"); |
|
119
|
|
|
} else { |
|
120
|
|
|
$focus = $this->queryGenerator->getEntityModel(); |
|
121
|
|
|
$query = (new \App\Db\Query())->select(['crmid'])->from('u_#__crmentity_showners') |
|
122
|
|
|
->innerJoin($focus->table_name, "u_#__crmentity_showners.crmid={$focus->table_name}.{$focus->table_index}"); |
|
123
|
|
|
} |
|
124
|
|
|
return [$this->getColumnName() => $query]; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Is empty operator. |
|
129
|
|
|
* |
|
130
|
|
|
* @return array |
|
131
|
|
|
*/ |
|
132
|
|
|
public function operatorY(): array |
|
133
|
|
|
{ |
|
134
|
|
|
if ($this->related) { |
|
|
|
|
|
|
135
|
|
|
$fieldModel = $this->queryGenerator->getModuleField($this->related['sourceField']); |
|
136
|
|
|
$query = (new \App\Db\Query())->select(['crmid'])->from('u_#__crmentity_showners') |
|
137
|
|
|
->innerJoin($fieldModel->getTableName(), "u_#__crmentity_showners.crmid={$fieldModel->getTableName()}.{$fieldModel->getColumnName()}"); |
|
138
|
|
|
} else { |
|
139
|
|
|
$focus = $this->queryGenerator->getEntityModel(); |
|
140
|
|
|
$query = (new \App\Db\Query())->select(['crmid'])->from('u_#__crmentity_showners') |
|
141
|
|
|
->innerJoin($focus->table_name, "u_#__crmentity_showners.crmid={$focus->table_name}.{$focus->table_index}"); |
|
142
|
|
|
} |
|
143
|
|
|
return ['NOT IN', $this->getColumnName(), $query]; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.