Passed
Push — master ( 882d2a...8f67b7 )
by Michael
03:09
created

GroupFormCheckBox::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 4
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace XoopsModules\Newbb;
2
3
use XoopsModules\Newbb;
4
5
/**
6
 * TODO: synchronize cascade permissions for multi-level
7
 */
8
9
/**
10
 * Add category navigation to forum casscade structure
11
 * <ol>Special points:
12
 *    <li> Use negative values for category IDs to avoid conflict between category and forum
13
 *    <li> Disabled checkbox for categories to avoid unnecessary permission items for categories in forum permission table
14
 * </ol>
15
 *
16
 * Note: this is a __patchy__ solution. We should have a more extensible and flexible group permission management: not only for data architecture but also for management interface
17
 */
18
19
/**
20
 * Class GroupFormCheckBox
21
 * @package XoopsModules\Newbb
22
 */
23
class GroupFormCheckBox extends \XoopsGroupFormCheckBox
0 ignored issues
show
Bug introduced by
The type XoopsGroupFormCheckBox 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...
24
{
25
    /**
26
     * @param      $caption
27
     * @param      $name
28
     * @param      $groupId
29
     * @param null $values
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $values is correct as it would always require null to be passed?
Loading history...
30
     */
31
    public function __construct($caption, $name, $groupId, $values = null)
32
    {
33
        parent::__construct($caption, $name, $groupId, $values);
34
    }
35
36
    /**
37
     * @param string $tree
38
     * @param array  $option
39
     * @param string $prefix
40
     * @param array  $parentIds
41
     */
42
    public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = [])
43
    {
44
        if ($option['id'] > 0) {
45
            $tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="';
46
            foreach ($parentIds as $pid) {
47
                if ($pid <= 0) {
48
                    continue;
49
                }
50
                $parent_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $pid . ']';
51
                $tree       .= "var ele = xoopsGetElementById('" . $parent_ele . "'); if (ele.checked !== true) {ele.checked = this.checked;}";
52
            }
53
            foreach ($option['allchild'] as $cid) {
54
                $child_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $cid . ']';
55
                $tree      .= "var ele = xoopsGetElementById('" . $child_ele . "'); if (this.checked !== true) {ele.checked = false;}";
56
            }
57
            $tree .= '" value="1"';
58
            if (in_array($option['id'], $this->_value)) {
59
                $tree .= ' checked';
60
            }
61
            $tree .= ' />'
62
                     . $option['name']
63
                     . '<input type="hidden" name="'
64
                     . $this->getName()
65
                     . '[parents]['
66
                     . $option['id']
67
                     . ']" value="'
68
                     . implode(':', $parentIds)
69
                     . '" /><input type="hidden" name="'
70
                     . $this->getName()
71
                     . '[itemname]['
72
                     . $option['id']
73
                     . ']" value="'
74
                     . htmlspecialchars($option['name'], ENT_QUOTES | ENT_HTML5)
75
                     . "\" /><br>\n";
76
        } else {
77
            $tree .= $prefix . $option['name'] . '<input type="hidden" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . "]\" /><br>\n";
78
        }
79
        if (isset($option['children'])) {
80
            foreach ($option['children'] as $child) {
81
                if ($option['id'] > 0) {
82
                    //                  array_push($parentIds, $option['id']);
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...
83
                    $parentIds[] = $option['id'];
84
                }
85
                $this->_renderOptionTree($tree, $this->_optionTree[$child], $prefix . '&nbsp;-', $parentIds);
86
            }
87
        }
88
    }
89
}
90