Test Failed
Push — main ( ac1aa2...91ffd3 )
by Rafael
51:29
created

Menu::loadTopMenu()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 12
rs 9.9666
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 DoliCore\Model;
20
21
use DoliCore\Base\Model;
22
23
class Menu extends Model
24
{
25
    /**
26
     * Indicates whether the automatic record creation and update fields are to be used.
27
     *
28
     * @var bool
29
     */
30
    public $timestamps = true;
31
32
    /**
33
     * Name of the table associated with the model. By default, it is the plural model name in
34
     * snakecase format: 'mailing_unsubscribes'.
35
     *
36
     * @var string
37
     */
38
    protected $table = 'menu';
39
40
    /**
41
     * List of fields that will be autocompleted with 'null' during the registration of a new record.
42
     *
43
     * @var string[]
44
     */
45
    protected $fillable = ['module', 'leftmenu', 'fk_mainmenu', 'fk_leftmenu', 'target', 'prefix', 'langs', 'level', 'perms', 'enabled'];
46
47
    public static function loadTopMenu($entity, $userType = 0)
48
    {
49
        $entities = [0, (int) $entity];
50
        $types = [(int) $userType, 2];
51
52
        return static::where('type', 'top')
53
            ->whereIn('entity', $entities)
54
            ->whereIn('usertype', $types)
55
            ->orderBy('type', 'DESC')
56
            ->orderBy('position')
57
            ->orderBy('rowid')
58
            ->get();
59
    }
60
61
    public static function loadSideMenu($entity, $userType = 0)
62
    {
63
        $entities = [0, (int) $entity];
64
        $types = [(int) $userType, 2];
65
66
        return static::where('type', 'left')
67
            ->whereIn('entity', $entities)
68
            ->whereIn('usertype', $types)
69
            ->orderBy('type', 'DESC')
70
            ->orderBy('position')
71
            ->orderBy('rowid')
72
            ->get();
73
    }
74
}
75