Passed
Pull Request — developer (#15831)
by Arkadiusz
20:14
created

Vtiger_CalendarRightPanel_Model::getUsersList()   B

Complexity

Conditions 9
Paths 10

Size

Total Lines 27
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 27
rs 8.0555
c 0
b 0
f 0
cc 9
nc 10
nop 1
1
<?php
2
/**
3
 * Base calendar right panel file.
4
 *
5
 * @package Model
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Adrian Kon <[email protected]>
10
 * @author    Mariusz Krzaczkowski <[email protected]>
11
 */
12
13
/**
14
 * Base calendar right panel class.
15
 */
16
class Vtiger_CalendarRightPanel_Model
17
{
18
	/**
19
	 * Get users.
20
	 *
21
	 * @param string $moduleName
22
	 *
23
	 * @return array
24
	 */
25
	public static function getUsersList(string $moduleName): array
26
	{
27
		$currentUser = Users_Record_Model::getCurrentUserModel();
28
		$roleInstance = Settings_Roles_Record_Model::getInstanceById($currentUser->get('roleid'));
29
		$clendarallorecords = $roleInstance->get('clendarallorecords');
30
		switch ($clendarallorecords) {
31
			case 3:
32
				if (App\Config::performance('SEARCH_SHOW_OWNER_ONLY_IN_LIST') && !\App\Config::module($moduleName, 'DISABLED_SHOW_OWNER_ONLY_IN_LIST', false)) {
33
					$usersAndGroup = \App\Fields\Owner::getInstance($moduleName, $currentUser)->getUsersAndGroupForModuleList();
34
					$users = $usersAndGroup['users'];
35
				} else {
36
					$users = \App\Fields\Owner::getInstance(false, $currentUser)->getAccessibleUsers();
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $moduleName of App\Fields\Owner::getInstance(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
					$users = \App\Fields\Owner::getInstance(/** @scrutinizer ignore-type */ false, $currentUser)->getAccessibleUsers();
Loading history...
37
				}
38
				break;
39
			case 1:
40
			case 2:
41
			default:
42
				$users[$currentUser->getId()] = $currentUser->getName();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$users was never initialized. Although not strictly required by PHP, it is generally a good practice to add $users = array(); before regardless.
Loading history...
43
				break;
44
		}
45
		if (!empty($users) && $favouriteUsers = $currentUser->getFavouritesUsers()) {
46
			uksort($users,
47
				function ($a, $b) use ($favouriteUsers) {
48
					return (int) (!isset($favouriteUsers[$a]) && isset($favouriteUsers[$b]));
49
				});
50
		}
51
		return $users;
52
	}
53
54
	/**
55
	 * Get groups.
56
	 *
57
	 * @param string $moduleName
58
	 *
59
	 * @return array
60
	 */
61
	public static function getGroupsList(string $moduleName): array
62
	{
63
		$currentUser = Users_Record_Model::getCurrentUserModel();
64
		$roleInstance = Settings_Roles_Record_Model::getInstanceById($currentUser->get('roleid'));
65
		$clendarallorecords = $roleInstance->get('clendarallorecords');
66
		switch ($clendarallorecords) {
67
			case 1:
68
				$groups = [];
69
				break;
70
			case 2:
71
				$groups = \App\Fields\Owner::getInstance(false, $currentUser)->getAccessibleGroups();
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $moduleName of App\Fields\Owner::getInstance(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

71
				$groups = \App\Fields\Owner::getInstance(/** @scrutinizer ignore-type */ false, $currentUser)->getAccessibleGroups();
Loading history...
72
				break;
73
			case 3:
74
				if (App\Config::performance('SEARCH_SHOW_OWNER_ONLY_IN_LIST') && !\App\Config::module($moduleName, 'DISABLED_SHOW_OWNER_ONLY_IN_LIST', false)) {
75
					$usersAndGroup = \App\Fields\Owner::getInstance($moduleName, $currentUser)->getUsersAndGroupForModuleList();
76
					$groups = $usersAndGroup['group'];
77
				} else {
78
					$groups = \App\Fields\Owner::getInstance(false, $currentUser)->getAccessibleGroups();
79
				}
80
				break;
81
			default:
82
				break;
83
		}
84
		return $groups;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $groups does not seem to be defined for all execution paths leading up to this point.
Loading history...
85
	}
86
87
	/**
88
	 * Get calendar types.
89
	 *
90
	 * @param string $moduleName
91
	 *
92
	 * @return array
93
	 */
94
	public static function getCalendarTypes(string $moduleName): array
95
	{
96
		return Vtiger_Calendar_Model::getInstance($moduleName)->getCalendarTypes();
97
	}
98
}
99