1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Base calendar right panel file. |
4
|
|
|
* |
5
|
|
|
* @package Model |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce S.A. |
8
|
|
|
* @license YetiForce Public License 6.5 (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
|
|
|
|
30
|
|
|
switch ($roleInstance->get('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(); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
break; |
39
|
|
|
case 1: |
40
|
|
|
case 2: |
41
|
|
|
default: |
42
|
|
|
$users[$currentUser->getId()] = $currentUser->getName(); |
|
|
|
|
43
|
|
|
break; |
44
|
|
|
} |
45
|
|
|
if (!empty($users) && $favoriteUsers = self::getFavoriteUsers($moduleName)) { |
46
|
|
|
uksort($users, |
47
|
|
|
fn ($a, $b) => (int) (!isset($favoriteUsers[$a]) && isset($favoriteUsers[$b]))); |
48
|
|
|
} |
49
|
|
|
return $users; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get groups. |
54
|
|
|
* |
55
|
|
|
* @param string $moduleName |
56
|
|
|
* |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public static function getGroupsList(string $moduleName): array |
60
|
|
|
{ |
61
|
|
|
$currentUser = Users_Record_Model::getCurrentUserModel(); |
62
|
|
|
$roleInstance = Settings_Roles_Record_Model::getInstanceById($currentUser->get('roleid')); |
63
|
|
|
switch ($roleInstance->get('clendarallorecords')) { |
64
|
|
|
case 1: |
65
|
|
|
$groups = []; |
66
|
|
|
break; |
67
|
|
|
case 2: |
68
|
|
|
$groups = \App\Fields\Owner::getInstance(false, $currentUser)->getAccessibleGroups(); |
|
|
|
|
69
|
|
|
break; |
70
|
|
|
case 3: |
71
|
|
|
if (App\Config::performance('SEARCH_SHOW_OWNER_ONLY_IN_LIST') && !\App\Config::module($moduleName, 'DISABLED_SHOW_OWNER_ONLY_IN_LIST', false)) { |
72
|
|
|
$usersAndGroup = \App\Fields\Owner::getInstance($moduleName, $currentUser)->getUsersAndGroupForModuleList(); |
73
|
|
|
$groups = $usersAndGroup['group']; |
74
|
|
|
} else { |
75
|
|
|
$groups = \App\Fields\Owner::getInstance(false, $currentUser)->getAccessibleGroups(); |
76
|
|
|
} |
77
|
|
|
break; |
78
|
|
|
default: |
79
|
|
|
break; |
80
|
|
|
} |
81
|
|
|
return $groups; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get calendar types. |
86
|
|
|
* |
87
|
|
|
* @param string $moduleName |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public static function getCalendarTypes(string $moduleName): array |
92
|
|
|
{ |
93
|
|
|
return Vtiger_Calendar_Model::getInstance($moduleName)->getCalendarTypes(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Return user favorite users. |
98
|
|
|
* |
99
|
|
|
* @param string $moduleName |
100
|
|
|
* |
101
|
|
|
* @return int[] |
102
|
|
|
*/ |
103
|
|
|
public static function getFavoriteUsers(string $moduleName): array |
104
|
|
|
{ |
105
|
|
|
$userId = \App\User::getCurrentUserId(); |
106
|
|
|
if (\App\Cache::has('FavoriteUsers', $userId)) { |
107
|
|
|
$users = \App\Cache::get('FavoriteUsers', $userId); |
108
|
|
|
} else { |
109
|
|
|
$users = (new \App\Db\Query())->select(['fav_id', 'id']) |
110
|
|
|
->from('u_#__users_pinned') |
111
|
|
|
->where(['user_id' => $userId, 'tabid' => \App\Module::getModuleId($moduleName)]) |
112
|
|
|
->createCommand() |
113
|
|
|
->queryAllByGroup(); |
114
|
|
|
\App\Cache::save('FavoriteUsers', $userId, $users, \App\Cache::LONG); |
115
|
|
|
} |
116
|
|
|
return $users; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|