LocationHandler::getAll()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 4
1
<?php
2
3
namespace XoopsModules\Extcal;
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
 * @copyright    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @package      extcal
19
 * @since
20
 * @author       XOOPS Development Team,
21
 */
22
23
//Kraven 30
24
25
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
26
27
/**
28
 * Class LocationHandler.
29
 */
30
class LocationHandler extends ExtcalPersistableObjectHandler
31
{
32
    /**
33
     * @param \XoopsDatabase|null $db
34
     */
35
    public function __construct(\XoopsDatabase $db = null)
36
    {
37
        if (null === $db) {
38
            $db = \XoopsDatabaseFactory::getDatabaseConnection();
39
        }
40
        parent::__construct($db, 'extcal_location', Location::class, 'id', 'nom');
0 ignored issues
show
Bug introduced by
'nom' of type string is incompatible with the type boolean expected by parameter $idenfierName of XoopsModules\Extcal\Extc...tHandler::__construct(). ( Ignorable by Annotation )

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

40
        parent::__construct($db, 'extcal_location', Location::class, 'id', /** @scrutinizer ignore-type */ 'nom');
Loading history...
41
    }
42
43
    /**
44
     * @param      $locationId
45
     * @param bool $skipPerm
46
     *
47
     * @return bool
48
     */
49
    public function getLocation($locationId, $skipPerm = false)
50
    {
51
        $user = $GLOBALS['xoopsUser'];
52
53
        $criteriaCompo = new \CriteriaCompo();
54
        $criteriaCompo->add(new \Criteria('id', $locationId));
55
56
        if (!$skipPerm) {
57
            $this->addCatPermCriteria($criteriaCompo, $user);
0 ignored issues
show
Bug introduced by
The method addCatPermCriteria() does not exist on XoopsModules\Extcal\LocationHandler. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

57
            $this->/** @scrutinizer ignore-call */ 
58
                   addCatPermCriteria($criteriaCompo, $user);
Loading history...
58
        }
59
        $ret = $this->getObjects($criteriaCompo);
60
        return $ret[0] ?? false;
61
    }
62
63
    /**
64
     * @param \CriteriaElement|null $criteria
65
     * @param null                  $fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
66
     * @param bool                  $asObject
67
     * @param bool                  $id_as_key
68
     *
69
     * @return array
70
     */
71
    public function &getAll(
72
        \CriteriaElement $criteria = null,
73
        $fields = null,
74
        $asObject = true,
75
        $id_as_key = true
76
    ) //getAll($criteria = null, $asObject = false)
77
    {
78
        $rst = $this->getObjects($criteria, $asObject);
79
        if ($asObject) {
80
            return $rst;
81
        }
82
83
        $ret = $this->objectToArray($rst);
84
85
        return $ret;
86
    }
87
}
88