CustomtagHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php namespace XoopsModules\Smartobject;
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project https://xoops.org/
15
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package
17
 * @since
18
 * @author     XOOPS Development Team
19
 */
20
21
use XoopsModules\Smartobject;
22
23
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
24
25
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
26
27
28
/**
29
 * Class SmartobjectCustomtagHandler
30
 */
31
class CustomtagHandler extends Smartobject\PersistableObjectHandler
32
{
33
    public $objects = false;
34
35
    /**
36
     * SmartobjectCustomtagHandler constructor.
37
     * @param \XoopsDatabase $db
38
     */
39
    public function __construct(\XoopsDatabase $db)
40
    {
41
        parent::__construct($db, Customtag::class, 'customtagid', 'name', 'description', 'smartobject');
42
        $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC);
43
    }
44
45
    /**
46
     * @return array|bool
47
     */
48
    public function getCustomtagsByName()
49
    {
50
        if (!$this->objects) {
51
            global $xoopsConfig;
52
53
            $ret = [];
54
55
            $criteria = new \CriteriaCompo();
56
57
            $criteria_language = new \CriteriaCompo();
58
            $criteria_language->add(new \Criteria('language', $xoopsConfig['language']));
59
            $criteria_language->add(new \Criteria('language', 'all'), 'OR');
60
            $criteria->add($criteria_language);
61
62
            $smartobjectPermissionsHandler = new PermissionHandler($this);
63
            $granted_ids                   = $smartobjectPermissionsHandler->getGrantedItems('view');
64
65
            if ($granted_ids && count($granted_ids) > 0) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $granted_ids of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
66
                $criteria->add(new \Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN'));
67
                $customtagsObj =& $this->getObjects($criteria, true);
68
                foreach ($customtagsObj as $customtagObj) {
69
                    $ret[$customtagObj->getVar('name')] = $customtagObj;
70
                }
71
            }
72
            $this->objects = $ret;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ret of type array is incompatible with the declared type boolean of property $objects.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
73
        }
74
75
        return $this->objects;
76
    }
77
}
78