Passed
Pull Request — developer (#15979)
by Arkadiusz
18:25
created

SharedOwnerField::operatorOgu()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 17
rs 9.6111
cc 5
nc 4
nop 0
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 operatorOgu(): bool
22
	{
23
		$result = false;
24
		$groups = \App\User::getCurrentUserModel()->getGroups();
25
		$usersByGroups = [];
26
		if ($groups) {
27
			foreach ($groups as $groupId) {
28
				$usersByGroups[] = (new \App\Db\Query())->select(['userid'])->from(["condition_groups_{$groupId}_" . \App\Layout::getUniqueId() => \App\PrivilegeUtil::getQueryToUsersByGroup((int) $groupId)])->column();
29
			}
30
			foreach ($usersByGroups as $usersByGroup) {
31
				if (array_intersect(explode(',', $this->getValue()), $usersByGroup)) {
32
					$result = true;
33
					break;
34
				}
35
			}
36
		}
37
		return $result;
38
	}
39
}
40