Passed
Pull Request — master (#18)
by Michael
02:01
created

LinksHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateWeights() 0 24 2
A __construct() 0 5 1
1
<?php namespace XoopsModules\Mymenus;
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         http://www.gnu.org/licenses/gpl-2.0.html GNU Public License
16
 * @package         Mymenus
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 */
20
21
use XoopsModules\Mymenus;
22
23
defined('XOOPS_ROOT_PATH') || die('Restricted access');
24
25
//require  dirname(__DIR__) . '/include/common.php';
26
27
28
/**
29
 * Class LinksHandler
30
 */
31
class LinksHandler extends \XoopsPersistableObjectHandler
0 ignored issues
show
Bug introduced by
The type XoopsPersistableObjectHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
{
33
    /**
34
     * @var Mymenus\Helper
35
     * @access private
36
     */
37
    private $helper;
38
39
    /**
40
     * @param null|\XoopsDatabase $db
41
     */
42
    public function __construct(\XoopsDatabase $db = null)
0 ignored issues
show
Bug introduced by
The type XoopsDatabase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
    {
44
        parent::__construct($db, 'mymenus_links', Links::class, 'id', 'title');
45
        /** @var \XoopsModules\Mymenus\Helper $this->helper */
46
        $this->helper = \XoopsModules\Mymenus\Helper::getInstance();
47
    }
48
49
    /**
50
     * @param $obj
51
     */
52
    public function updateWeights($obj)
53
    {
54
        $sql = 'UPDATE ' . $this->table . ' SET weight = weight+1';
55
        $sql .= ' WHERE';
56
        $sql .= ' weight >= ' . $obj->getVar('weight');
57
        $sql .= ' AND';
58
        $sql .= ' id <> ' . $obj->getVar('id');
59
        //$sql .= " AND pid = " . $obj->getVar('pid');
60
        $sql .= ' AND';
61
        $sql .= ' mid = ' . $obj->getVar('mid');
62
        $this->db->queryF($sql);
63
64
        $sql = 'SELECT id FROM ' . $this->table;
65
        $sql .= ' WHERE mid = ' . $obj->getVar('mid');
66
        //$sql .= " AND pid = " . $obj->getVar('pid');
67
        $sql    .= ' ORDER BY weight ASC';
68
        $result = $this->db->query($sql);
69
        $i      = 1;  //lets start at 1 please!
70
        while (false !== (list($id) = $this->db->fetchRow($result))) {
71
            $sql = 'UPDATE ' . $this->table;
72
            $sql .= " SET weight = {$i}";
73
            $sql .= " WHERE id = {$id}";
74
            $this->db->queryF($sql);
75
            ++$i;
76
        }
77
    }
78
}
79