LocationHandler::getLocation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace XoopsModules\Oledrion;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
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.
13
*/
14
15
/**
16
 * oledrion
17
 *
18
 * @copyright   {@link https://xoops.org/ XOOPS Project}
19
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
20
 * @author      Hossein Azizabadi ([email protected])
21
 */
22
23
use XoopsModules\Oledrion;
24
25
/**
26
 * Class LocationHandler
27
 */
28
class LocationHandler extends OledrionPersistableObjectHandler
29
{
30
    /**
31
     * LocationHandler constructor.
32
     * @param \XoopsDatabase|null $db
33
     */
34
    public function __construct(\XoopsDatabase $db = null)
35
    {
36
        //                                        Table                   Classe              Id
37
        parent::__construct($db, 'oledrion_location', Location::class, 'location_id');
0 ignored issues
show
Bug introduced by
It seems like $db can also be of type null; however, parameter $db of XoopsModules\Oledrion\Ol...tHandler::__construct() does only seem to accept XoopsDatabase, maybe add an additional type check? ( Ignorable by Annotation )

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

37
        parent::__construct(/** @scrutinizer ignore-type */ $db, 'oledrion_location', Location::class, 'location_id');
Loading history...
38
    }
39
40
    /**
41
     * @param  Parameters $parameters
42
     * @return array
43
     */
44
    public function getAllLocation(Parameters $parameters)
45
    {
46
        $parameters = $parameters->extend(new Oledrion\Parameters([
47
                                                                      'start' => 0,
48
                                                                      'limit' => 0,
49
                                                                      'sort'  => 'location_id',
50
                                                                      'order' => 'ASC',
51
                                                                  ]));
52
        $critere    = new \Criteria('location_id', 0, '<>');
53
        $critere->setLimit($parameters['limit']);
54
        $critere->setStart($parameters['start']);
55
        $critere->setSort($parameters['sort']);
56
        $critere->setOrder($parameters['order']);
57
        $location = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $location is dead and can be removed.
Loading history...
58
        $location = $this->getObjects($critere);
59
60
        return $location;
61
    }
62
63
    /**
64
     * @param  Parameters $parameters
65
     * @return array
66
     */
67
    public function getAllPid(Parameters $parameters)
68
    {
69
        $parameters = $parameters->extend(new Oledrion\Parameters([
70
                                                                      'start' => 0,
71
                                                                      'limit' => 0,
72
                                                                      'sort'  => 'location_id',
73
                                                                      'order' => 'ASC',
74
                                                                  ]));
75
        $critere    = new \CriteriaCompo();
76
        $critere->add(new \Criteria('location_type', 'parent'));
77
        $critere->setLimit($parameters['limit']);
78
        $critere->setStart($parameters['start']);
79
        $critere->setSort($parameters['sort']);
80
        $critere->setOrder($parameters['order']);
81
        $pid = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $pid is dead and can be removed.
Loading history...
82
        $pid = $this->getObjects($critere);
83
84
        return $pid;
85
    }
86
87
    /**
88
     * @param $id
89
     * @return array
90
     */
91
    public function getLocation($id)
92
    {
93
        $critere = new \CriteriaCompo();
94
        $critere->add(new \Criteria('location_online', 1));
95
        $critere->add(new \Criteria('location_type', 'location'));
96
        $critere->add(new \Criteria('location_pid', $id));
97
        $location = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $location is dead and can be removed.
Loading history...
98
        $location = $this->getObjects($critere);
99
100
        return $location;
101
    }
102
103
    /**
104
     * @param $id
105
     * @return int
106
     */
107
    public function haveChild($id)
108
    {
109
        $critere = new \CriteriaCompo();
110
        $critere->add(new \Criteria('location_online', 1));
111
        $critere->add(new \Criteria('location_type', 'location'));
112
        $critere->add(new \Criteria('location_pid', $id));
113
        $location = $this->getCount($critere);
114
115
        return $location;
116
    }
117
}
118