ObjectTree   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeSelBoxOptionsArray() 0 14 5
A makeSelBox() 0 9 2
1
<?php
2
3
namespace XoopsModules\Wfdownloads;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * WfdownloadsObjectTree
17
 *
18
 * @copyright   XOOPS Project (https://xoops.org)
19
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
20
 * @author      lucio <[email protected]>
21
 * @package     Wfdownloads
22
 * @since       3.23
23
 */
24
25
use XoopsModules\Wfdownloads;
26
27
//xoops_load('XoopsObjectTree');
28
require_once XOOPS_ROOT_PATH . '/class/tree.php';
29
30
/**
31
 * Form element that ...
32
 */
33
class ObjectTree extends \XoopsObjectTree
34
{
35
    /**
36
     * Make options for a select box from
37
     *
38
     * @param string $fieldName    Name of the member variable from the node objects that should be used as the title for the options.
39
     * @param int    $key          ID of the object to display as the root of select options
40
     * @param string $optionsArray (reference to a string when called from outside) Result from previous recursions
41
     * @param string $prefix_orig  String to indent items at deeper levels
42
     * @param string $prefix_curr  String to indent the current item
43
     *
44
     * @return string
45
     * @access private
46
     */
47
    public function makeSelBoxOptionsArray($fieldName, $key, &$optionsArray, $prefix_orig, $prefix_curr = '')
48
    {
49
        if ($key > 0) {
50
            $value                = $this->tree[$key]['obj']->getVar($this->_myId);
0 ignored issues
show
Bug Best Practice introduced by
The property _myId does not exist on XoopsModules\Wfdownloads\ObjectTree. Since you implemented __get, consider adding a @property annotation.
Loading history...
51
            $optionsArray[$value] = $prefix_curr . $this->tree[$key]['obj']->getVar($fieldName);
52
            $prefix_curr          .= $prefix_orig;
53
        }
54
        if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) {
55
            foreach ($this->tree[$key]['child'] as $childkey) {
56
                $this->makeSelBoxOptionsArray($fieldName, $childkey, $optionsArray, $prefix_orig, $prefix_curr);
57
            }
58
        }
59
60
        return $optionsArray;
61
    }
62
63
    /**
64
     * Make a select box with options from the tree
65
     *
66
     * @param string $name
67
     * @param string $fieldName       Name of the member variable from the node objects that should be used as the title for the options.
68
     * @param string $prefix          String to indent deeper levels
69
     * @param string $selected
70
     * @param bool   $addEmptyOption  Set TRUE to add an empty option with value "0" at the top of the hierarchy
71
     * @param int    $key             ID of the object to display as the root of select options
72
     *
73
     * @param string $extra
74
     * @return string $optionsArray   Associative array of value->name pairs, useful for <a href='psi_element://XoopsFormSelect'>XoopsFormSelect</a>->addOptionArray method
75
     *                                addOptionArray method
76
     */
77
    public function makeSelBox($name, $fieldName, $prefix = '-', $selected = '', $addEmptyOption = false, $key = 0, $extra = '')
78
        //    public function makeSelBox($fieldName, $prefix = '-', $addEmptyOption = false, $key = 0)
79
    {
80
        $optionsArray = [];
81
        if ($addEmptyOption) {
82
            $optionsArray[0] = '';
83
        }
84
85
        return $this->makeSelBoxOptionsArray($fieldName, $key, $optionsArray, $prefix);
0 ignored issues
show
Bug introduced by
$optionsArray of type array is incompatible with the type string expected by parameter $optionsArray of XoopsModules\Wfdownloads...akeSelBoxOptionsArray(). ( Ignorable by Annotation )

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

85
        return $this->makeSelBoxOptionsArray($fieldName, $key, /** @scrutinizer ignore-type */ $optionsArray, $prefix);
Loading history...
86
    }
87
}
88