Completed
Push — master ( 097ad2...6ae33d )
by Michael
12s
created

AboutPageHandler::getTrees()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 19
nc 2
nop 3
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 26 and the first side effect is on line 21.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * About
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
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
 * @copyright      The XOOPS Co.Ltd. http://www.xoops.com.cn
13
 * @copyright      XOOPS Project (https://xoops.org)
14
 * @license        GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package        about
16
 * @since          1.0.0
17
 * @author         Mengjue Shao <[email protected]>
18
 * @author         Susheng Yang <[email protected]>
19
 */
20
21
defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
22
23
/**
24
 * Class AboutPage
25
 */
26
class AboutPage extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
27
{
28
    /**
29
     * AboutPage constructor.
30
     */
31
    public function __construct()
32
    {
33
        $this->initVar('page_id', XOBJ_DTYPE_INT, null, false);
34
        $this->initVar('page_pid', XOBJ_DTYPE_INT, 0);
35
        $this->initVar('page_title', XOBJ_DTYPE_TXTBOX, '');
36
        $this->initVar('page_menu_title', XOBJ_DTYPE_TXTBOX, '');
37
        $this->initVar('page_image', XOBJ_DTYPE_TXTBOX, '');
38
        $this->initVar('page_text', XOBJ_DTYPE_TXTBOX, '');
39
        $this->initVar('page_author', XOBJ_DTYPE_TXTBOX, '');
40
        $this->initVar('page_pushtime', XOBJ_DTYPE_INT);
41
        $this->initVar('page_blank', XOBJ_DTYPE_INT, 0);
42
        $this->initVar('page_menu_status', XOBJ_DTYPE_INT, 0);
43
        $this->initVar('page_type', XOBJ_DTYPE_INT, 0);
44
        $this->initVar('page_status', XOBJ_DTYPE_INT, 0);
45
        $this->initVar('page_order', XOBJ_DTYPE_INT, 0);
46
        //$this->initVar('page_url', XOBJ_DTYPE_TXTBOX,"");
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
        $this->initVar('page_index', XOBJ_DTYPE_INT, 0);
48
        $this->initVar('page_tpl', XOBJ_DTYPE_TXTBOX, '');
49
        $this->initVar('dohtml', XOBJ_DTYPE_INT, 1);
50
        $this->initVar('dosmiley', XOBJ_DTYPE_INT, 0);
51
        $this->initVar('doxcode', XOBJ_DTYPE_INT, 0);
52
        $this->initVar('doimage', XOBJ_DTYPE_INT, 0);
53
        $this->initVar('dobr', XOBJ_DTYPE_INT, 0);
54
    }
55
}
56
57
/**
58
 * Class AboutPageHandler
59
 */
60
class AboutPageHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
61
{
62
    /**
63
     * AboutPageHandler constructor.
64
     * @param null|XoopsDatabase $db
65
     */
66
    public function __construct(XoopsDatabase $db)
67
    {
68
        parent::__construct($db, 'about_page', 'AboutPage', 'page_id', 'page_title');
69
    }
70
71
    /**
72
     * @param  int    $pid
73
     * @param  string $prefix
74
     * @param  array  $tags
75
     * @return array
76
     */
77
    public function &getTrees($pid = 0, $prefix = '--', $tags = array())
78
    {
79
        $pid = (int)$pid;
80
        if (!is_array($tags) || count($tags) == 0) {
81
            $tags = array(
82
                'page_id',
83
                'page_pid',
84
                'page_title',
85
                'page_title',
86
                'page_menu_title',
87
                'page_status',
88
                'page_order'
89
            );
90
        }
91
        $criteria = new CriteriaCompo();
92
        $criteria->setSort('page_order');
93
        $criteria->order = 'ASC';
94
        $page_tree = $this->getAll($criteria, $tags);
95
        require_once __DIR__ . '/tree.php';
96
        $tree       = new AboutTree($page_tree);
97
        $page_array = $tree->makeTree($prefix, $pid, $tags);
98
99
        return $page_array;
100
    }
101
102
    /**
103
     * @param  array $pages
104
     * @param  int   $key
105
     * @param  int   $level
106
     * @return array|bool
107
     */
108 View Code Duplication
    public function &menuTree($pages = array(), $key = 0, $level = 1)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
    {
110
        if (!is_array($pages) || 0 === count($pages)) {
111
            return false;
112
        }
113
        $menu = array();
114
115
        foreach ($pages as $k => $v) {
116
            if ($v['page_pid'] == $key) {
117
                $menu[$k]          = $v;
118
                $menu[$k]['level'] = $level;
119
                $child             = $this->menuTree($pages, $k, $level + 1);
120
                if (!empty($child)) {
121
                    $menu[$k]['child'] = $child;
122
                }
123
            }
124
        }
125
126
        return $menu;
127
    }
128
129
    /**
130
     * @param  array $pages
131
     * @param  int   $key
132
     * @return array|bool
133
     */
134 View Code Duplication
    public function getBread($pages = array(), $key = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
135
    {
136
        if (!is_array($pages) || 0 === count($pages)) {
137
            return false;
138
        }
139
        $bread = array();
140
141
        if (isset($pages[$key])) {
142
            $current = $pages[$key];
143
            $bread   = array($current['page_id'] => $current['page_menu_title']);
144
            if ($current['page_pid'] > 0) {
145
                $p_brend = $this->getBread($pages, $current['page_pid']);
146
                if (!empty($p_brend)) {
147
                    foreach ($p_brend as $k => $v) {
148
                        $bread[$k] = $v;
149
                    }
150
                }
151
            }
152
        }
153
154
        return $bread;
155
    }
156
}
157