|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Company basic file. |
|
4
|
|
|
* |
|
5
|
|
|
* @package App |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright YetiForce S.A. |
|
8
|
|
|
* @license YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com) |
|
9
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
|
10
|
|
|
* @author Radosław Skrzypczak <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace App; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Company basic class. |
|
17
|
|
|
*/ |
|
18
|
|
|
class Company extends Base |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var string Edit view URL */ |
|
21
|
|
|
public const EDIT_VIEW_URL = 'index.php?parent=Settings&module=Companies&view=Edit'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Classification of enterprises due to their size. |
|
25
|
|
|
* |
|
26
|
|
|
* @var int[] |
|
27
|
|
|
*/ |
|
28
|
|
|
public static array $sizes = [ |
|
29
|
|
|
'Micro' => 20, |
|
30
|
|
|
'Small' => 50, |
|
31
|
|
|
'Medium' => 250, |
|
32
|
|
|
'Large' => 1000, |
|
33
|
|
|
'Corporation' => 0, |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Function to get the instance of the Company model. |
|
38
|
|
|
* |
|
39
|
|
|
* @throws \App\Exceptions\DbException |
|
40
|
|
|
* |
|
41
|
|
|
* @return array|bool |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function getCompany() |
|
44
|
|
|
{ |
|
45
|
|
|
if (Cache::staticHas('CompanyGet', '')) { |
|
46
|
|
|
return Cache::staticGet('CompanyGet', ''); |
|
47
|
|
|
} |
|
48
|
|
|
$row = (new Db\Query())->from('s_#__companies')->one(Db::getInstance('admin')); |
|
49
|
|
|
if (!$row) { |
|
50
|
|
|
throw new Exceptions\DbException('LBL_RECORD_NOT_FOUND'); |
|
51
|
|
|
} |
|
52
|
|
|
Cache::staticSave('CompanyGet', '', $row, Cache::LONG); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
return $row; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get company size. |
|
59
|
|
|
* |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
public static function getSize(): string |
|
63
|
|
|
{ |
|
64
|
|
|
$count = User::getNumberOfUsers(); |
|
65
|
|
|
$return = 'Micro'; |
|
66
|
|
|
$last = 0; |
|
67
|
|
|
foreach (self::$sizes as $size => $value) { |
|
68
|
|
|
if (0 !== $value && $count <= $value && $count > $last) { |
|
69
|
|
|
return $size; |
|
70
|
|
|
} |
|
71
|
|
|
if (0 === $value && $count > 1000) { |
|
72
|
|
|
$return = $size; |
|
73
|
|
|
} |
|
74
|
|
|
$last = $value; |
|
75
|
|
|
} |
|
76
|
|
|
return $return; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Compare company size. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $package |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public static function compareSize(string $package): bool |
|
87
|
|
|
{ |
|
88
|
|
|
$size = self::$sizes[$package] ?? ''; |
|
89
|
|
|
if (0 === $size) { |
|
90
|
|
|
return true; |
|
91
|
|
|
} |
|
92
|
|
|
return $size >= User::getNumberOfUsers(); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.