Passed
Pull Request — developer (#15979)
by Arkadiusz
17:03
created

SharedOwnerField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A operatorOgrU() 0 16 5
1
<?php
2
3
namespace App\Conditions\RecordFields;
4
5
/**
6
 * Shared 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 SharedOwnerField extends BaseField
15
{
16
	/**
17
	 * Users who belong to the same group as the currently logged in user.
18
	 *
19
	 * @return bool
20
	 */
21
	public function operatorOgrU(): bool
22
	{
23
		$result = false;
24
		$groups = \App\Fields\Owner::getInstance($this->recordModel->getModuleName())->getGroups(false, 'private');
25
		$usersByGroup = [];
26
		if ($groups) {
27
			foreach (array_keys($groups)  as $idGroup) {
28
				$usersByGroup = (new \App\Db\Query())->select(['userid'])->from(["condition_groups_{$idGroup}_" . \App\Layout::getUniqueId() => \App\PrivilegeUtil::getQueryToUsersByGroup((int) $idGroup)])->column();
29
			}
30
		}
31
		foreach (explode(',', $this->getValue()) as $userValue) {
32
			if (in_array($userValue, $usersByGroup)) {
33
				$result = true;
34
			}
35
		}
36
		return $result;
37
	}
38
}
39