XoopsObjectTree   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 15
eloc 36
dl 0
loc 141
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A makeTreeAsArray() 0 9 2
A __get() 0 11 2
A _recursiveMakeTreeAsArray() 0 10 5
A __construct() 0 3 1
A makeSelBox() 0 33 5
1
<?php
2
3
namespace XoopsModules\Oledrion;
4
5
/**
6
 * XOOPS tree class
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
16
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
17
 * @since               2.0.0
18
 * @author              Kazumi Ono (http://www.myweb.ne.jp/, http://jp.xoops.org/)
19
 */
20
defined('XOOPS_ROOT_PATH') || die('Restricted access');
21
22
require_once dirname(dirname(dirname(__DIR__))) . '/class/tree.php';
23
24
/**
25
 * A tree structures with {@link XoopsObject}s as nodes
26
 *
27
 * @author           Kazumi Ono     <[email protected]>
28
 */
29
class XoopsObjectTree extends \XoopsObjectTree
30
{
31
    /**
32
     * @param mixed      $objectArr
33
     * @param mixed      $myId
34
     * @param mixed      $parentId
35
     * @param null|mixed $rootId
36
     */
37
    //    protected $parentId;
38
    //    protected $myId;
39
    //    protected $rootId;
40
    //    protected $tree = [];
41
    //    protected $objects;
42
43
    /**
44
     * Constructor
45
     *
46
     * @param array  $objectArr Array of {@link XoopsObject}s
47
     * @param string $myId      field name of object ID
48
     * @param string $parentId  field name of parent object ID
49
     * @param string $rootId    field name of root object ID
50
     */
51
    public function __construct($objectArr, $myId, $parentId, $rootId = null)
52
    {
53
        parent::__construct($objectArr, $myId, $parentId, $rootId);
54
    }
55
56
    /**
57
     * Make a select box with options from the tree
58
     *
59
     * @param  string      $name           Name of the select box
60
     * @param  string      $fieldName      Name of the member variable from the
61
     *                                     node objects that should be used as the title for the options.
62
     * @param  string      $prefix         String to indent deeper levels
63
     * @param  string      $selected       Value to display as selected
64
     * @param  bool|string $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy
65
     * @param int          $key            ID of the object to display as the root of select options
66
     * @param  string      $additional
67
     * @return string      HTML select box
68
     *
69
     * @deprecated since 2.5.9, please use makeSelectElement()
70
     */
71
    public function makeSelBox(
72
        $name,
73
        $fieldName,
74
        $prefix = '-',
75
        $selected = '',
76
        $addEmptyOption = '',
77
        $key = 0,
78
        $additional = '')
79
    {
80
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
81
        trigger_error("makeSelBox() is deprecated since 2.5.9, please use makeSelectElement(), accessed from {$trace[0]['file']} line {$trace[0]['line']},");
82
83
        $ret2 = '<select name="' . $name . '" id="' . $name . '" ' . $additional . '>'; //mb needs to test
84
        if (false !== (bool)$addEmptyOption) {
85
            $ret2 .= '<option value="0"></option>';
86
        }
87
88
        $ret = "<select id='" . $name . "' name='" . $name . "'";
89
        if ('' !== $additional) {
90
            $ret .= $additional;
91
        }
92
        $ret .= '>';
93
        if ('' !== $addEmptyOption) {
94
            $tmpSelected = '';
95
            if (0 == $selected) {
96
                $tmpSelected = ' selected';
97
            }
98
            $ret .= '<option' . $tmpSelected . ' value="0">' . $addEmptyOption . '</option>';
99
        }
100
101
        $this->makeSelBoxOptions($fieldName, $selected, $key, $ret, $prefix);
0 ignored issues
show
Deprecated Code introduced by
The function XoopsObjectTree::makeSelBoxOptions() has been deprecated: since 2.5.9, please use makeSelectElement() functionality ( Ignorable by Annotation )

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

101
        /** @scrutinizer ignore-deprecated */ $this->makeSelBoxOptions($fieldName, $selected, $key, $ret, $prefix);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
102
103
        return $ret . '</select>';
104
    }
105
106
    /**
107
     * Magic __get method
108
     *
109
     * Some modules did not respect the leading underscore is private convention and broke
110
     * when code was modernized. This will keep them running for now.
111
     *
112
     * @param string $name  unknown variable name requested
113
     *                      currently only '_tree' is supported
114
     *
115
     * @return mixed value
116
     */
117
    public function __get($name)
118
    {
119
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
120
        if ('_tree' === $name) {
121
            trigger_error("XoopsObjectTree::\$_tree is deprecated, accessed from {$trace[0]['file']} line {$trace[0]['line']},");
122
123
            return $this->tree;
124
        }
125
        trigger_error('Undefined property: XoopsObjectTree::$' . $name . " in {$trace[0]['file']} line {$trace[0]['line']}, ", E_USER_NOTICE);
126
127
        return null;
128
    }
129
130
    /**
131
     * Internal function used by makeTreeAsArray
132
     * @param        $fieldName
133
     * @param        $key
134
     * @param        $ret
135
     * @param        $prefix_orig
136
     * @param string $prefix_curr
137
     */
138
    public function _recursiveMakeTreeAsArray($fieldName, $key, &$ret, $prefix_orig, $prefix_curr = '')
139
    {
140
        if ($key > 0) {
141
            $value       = $this->tree[$key]['obj']->getVar($this->myId);
142
            $ret[$value] = $prefix_curr . $this->tree[$key]['obj']->getVar($fieldName);
143
            $prefix_curr .= $prefix_orig;
144
        }
145
        if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
146
            foreach ($this->tree[$key]['child'] as $childkey) {
147
                $this->_recursiveMakeTreeAsArray($fieldName, $childkey, $ret, $prefix_orig, $prefix_curr);
148
            }
149
        }
150
    }
151
152
    /**
153
     * Identical function as makeSelBox but returns an array
154
     *
155
     * @param  string $fieldName Name of the member variable from the node objects that should be used as the title for the options.
156
     * @param  string $prefix    String to indent deeper levels
157
     * @param int     $key       ID of the object to display as the root of select options
158
     * @param  null   $empty
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $empty is correct as it would always require null to be passed?
Loading history...
159
     * @return array   key = object ID, value = $fieldName
160
     */
161
    public function makeTreeAsArray($fieldName, $prefix = '-', $key = 0, $empty = null)
162
    {
163
        $ret = [];
164
        if (null !== $empty) {
0 ignored issues
show
introduced by
The condition null !== $empty is always false.
Loading history...
165
            $ret[0] = $empty;
166
        }
167
        $this->_recursiveMakeTreeAsArray($fieldName, $key, $ret, $prefix);
168
169
        return $ret;
170
    }
171
}
172