Passed
Push — master ( 93b609...1da0d9 )
by Michael
37s
created

Tree   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A makeArrayTreeOptions() 0 10 5
A makeArrayTree() 0 6 1
1
<?php
2
3
namespace XoopsModules\Tdmdownloads;
4
5
/**
6
 * TDMDownload
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   Gregory Mage (Aka Mage)
16
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @author      Gregory Mage (Aka Mage)
18
 */
19
require_once $GLOBALS['xoops']->path('www/class/tree.php');
20
21
// xoops >2.5.9
22
23
/**
24
 * Class Tree
25
 * @package XoopsModules\Tdmdownloads
26
 */
27
class Tree extends \XoopsObjectTree
28
{
29
    /**
30
     * Tree constructor.
31
     * @param      $objectArr
32
     * @param      $myId
33
     * @param      $parentId
34
     * @param null $rootId
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $rootId is correct as it would always require null to be passed?
Loading history...
35
     */
36
    public function __construct(&$objectArr, $myId, $parentId, $rootId = null)
37
    {
38
        parent::__construct($objectArr, $myId, $parentId, $rootId);
39
    }
40
41
    /**
42
     * @param        $fieldName
43
     * @param        $key
44
     * @param        $ret
45
     * @param        $prefix_orig
46
     * @param string $prefix_curr
47
     */
48
    protected function makeArrayTreeOptions($fieldName, $key, &$ret, $prefix_orig, $prefix_curr = '')
49
    {
50
        if ($key > 0) {
51
            $value       = $this->tree[$key]['obj']->getVar($this->myId);
52
            $ret[$value] = $prefix_curr . $this->tree[$key]['obj']->getVar($fieldName);
53
            $prefix_curr .= $prefix_orig;
54
        }
55
        if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
56
            foreach ($this->tree[$key]['child'] as $childKey) {
57
                $this->makeArrayTreeOptions($fieldName, $childKey, $ret, $prefix_orig, $prefix_curr);
58
            }
59
        }
60
    }
61
62
    /**
63
     * @param        $fieldName
64
     * @param string $prefix
65
     * @param int    $key
66
     *
67
     * @return array
68
     */
69
    public function makeArrayTree($fieldName, $prefix = '-', $key = 0)
70
    {
71
        $ret = [];
72
        $this->makeArrayTreeOptions($fieldName, $key, $ret, $prefix);
73
74
        return $ret;
75
    }
76
}
77
/* xoops 2.5.8
78
class Tree extends XoopsObjectTree {
79
80
    protected function makeArrayTreeOptions($fieldName, $key, &$ret, $prefix_orig, $prefix_curr = '')
81
    {
82
        if ($key > 0) {
83
            $value = $this->_tree[$key]['obj']->getVar($this->_myId);
84
            $ret[$value] = $prefix_curr . $this->_tree[$key]['obj']->getVar($fieldName);
85
            $prefix_curr .= $prefix_orig;
86
        }
87
        if (isset($this->_tree[$key]['child']) && !empty($this->_tree[$key]['child'])) {
88
            foreach ($this->_tree[$key]['child'] as $childKey) {
89
                $this->makeArrayTreeOptions($fieldName, $childKey, $ret, $prefix_orig, $prefix_curr);
90
            }
91
        }
92
    }
93
94
    public function makeArrayTree($fieldName, $prefix = '-', $key = 0) {
95
        $ret = array();
96
        $this->makeArrayTreeOptions($fieldName, $key, $ret, $prefix);
97
98
        return $ret;
99
    }
100
}*/
101