1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Copyright (C) 2024 Rafael San José <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This program is free software; you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
8
|
|
|
* any later version. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Dolibarr\Core\Model; |
20
|
|
|
|
21
|
|
|
use Carbon\Carbon; |
22
|
|
|
use Dolibarr\Core\Base\Model; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class Const |
26
|
|
|
* |
27
|
|
|
* @property int $rowid |
28
|
|
|
* @property string $name |
29
|
|
|
* @property int $entity |
30
|
|
|
* @property string $value |
31
|
|
|
* @property string|null $type |
32
|
|
|
* @property int $visible |
33
|
|
|
* @property string|null $note |
34
|
|
|
* @property Carbon|null $tms |
35
|
|
|
*/ |
36
|
|
|
class Constant extends Model |
37
|
|
|
{ |
38
|
|
|
public $timestamps = false; |
39
|
|
|
protected $table = 'const'; |
40
|
|
|
protected $primaryKey = 'rowid'; |
41
|
|
|
protected $casts = [ |
42
|
|
|
'entity' => 'int', |
43
|
|
|
'visible' => 'int', |
44
|
|
|
'tms' => 'datetime' |
45
|
|
|
]; |
46
|
|
|
protected $fillable = [ |
47
|
|
|
'name', |
48
|
|
|
'entity', |
49
|
|
|
'value', |
50
|
|
|
'type', |
51
|
|
|
'visible', |
52
|
|
|
'note', |
53
|
|
|
'tms' |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
public static function getConstants() |
57
|
|
|
{ |
58
|
|
|
global $conf, $user; // Suponiendo que estás usando variables globales |
59
|
|
|
|
60
|
|
|
// Construir la consulta |
61
|
|
|
$query = Constant::select('rowid') |
62
|
|
|
->selectRaw(static::decrypt('name') . ' AS name') |
63
|
|
|
->selectRaw(static::decrypt('value') . ' AS value') |
64
|
|
|
->addSelect('type', 'note', 'entity'); |
65
|
|
|
|
66
|
|
|
// Condiciones basadas en el modo multicompany |
67
|
|
|
if (!isModEnabled('multicompany')) { |
68
|
|
|
// Si no está habilitado el modo multicompany |
69
|
|
|
$query->whereIn('entity', [0, $conf->entity]); |
70
|
|
|
} else { |
71
|
|
|
// Si está habilitado el modo multicompany |
72
|
|
|
if ($user->entity) { |
73
|
|
|
// Si el usuario tiene una entidad, restringir la consulta |
74
|
|
|
$query->whereIn('entity', explode(',', $user->entity . ',' . $conf->entity)); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// Ordenar los resultados |
79
|
|
|
$query->orderBy('entity') |
80
|
|
|
->orderBy('name', 'ASC'); |
81
|
|
|
|
82
|
|
|
// Obtener los resultados |
83
|
|
|
return $query->get(); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|