Passed
Push — master ( 84b849...226629 )
by Andreas
10:54
created

midgard_admin_asgard_copytree::_is_collapsed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package midgard.admin.asgard
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
/**
10
 * Copy/delete tree branch viewer
11
 *
12
 * @package midgard.admin.asgard
13
 */
14
class midgard_admin_asgard_copytree extends midgard_admin_asgard_navigation
15
{
16
    /**
17
     * Switch to determine if the whole tree should be copied
18
     */
19
    public bool $copy_tree = false;
20
21
    /**
22
     * Switch to determine the visibility of inputs
23
     */
24
    public bool  $inputs = true;
25
26
    /**
27
     * Choose the target type
28
     *
29
     * @var string
30
     */
31
    public $input_type;
32
33
    /**
34
     * Choose the target name for the form
35
     *
36
     * @var string
37
     */
38
    public $input_name;
39
40
    /**
41
     * Show the link to view the object
42
     */
43
    public bool $view_link = false;
44
45
    /**
46
     * Show the link to view the object
47
     */
48
    public bool $edit_link = false;
49
50
    public string $page_prefix = '';
51
52 2
    public function __construct(midcom_core_dbaobject $object, array &$request_data)
53
    {
54 2
        parent::__construct($object, $request_data);
55 2
        $this->page_prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
56
    }
57
58
    protected function _draw_element(object $object, string $label, int $level, bool $autoexpand = false)
59
    {
60
        $ref = midcom_helper_reflector_tree::get($object);
61
        $span_class = '';
62
        $css_class = $this->get_css_classes($object, $ref->mgdschema_class);
63
        $this->shown_objects[$object->guid] = true;
64
65
        echo "<li class=\"{$css_class}\">\n";
66
67
        if ($this->inputs) {
68
            $checked = ($this->copy_tree) ? ' checked="checked"' : '';
69
            // This value is used for compiling the exclusion list: if the object is found from this list, but not from the selection list,
70
            // it means that the selection did not include the object GUID
71
            echo "<input type=\"hidden\" name=\"all_objects[]\" value=\"{$object->guid}\" />\n";
72
73
            echo "<label for=\"item_{$object->guid}\">\n";
74
            echo "<input id=\"item_{$object->guid}\" type=\"{$this->input_type}\" name=\"{$this->input_name}\" value=\"{$object->guid}\"{$checked} />\n";
75
        }
76
77
        $label = htmlspecialchars($ref->get_object_label($object)) ?: "#{$object->id}";
0 ignored issues
show
Bug introduced by
It seems like $ref->get_object_label($object) can also be of type null; however, parameter $string of htmlspecialchars() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

77
        $label = htmlspecialchars(/** @scrutinizer ignore-type */ $ref->get_object_label($object)) ?: "#{$object->id}";
Loading history...
78
        $icon = $ref->get_object_icon($object);
79
        echo "<span class=\"title{$span_class}\" title=\"" . sprintf($this->_l10n->get('%s (%s)'), $label, $ref->get_class_label()) . "\">{$icon}{$label}</span>\n";
80
81
        // Show the link to the object
82
        if ($this->view_link) {
83
            echo "<a href=\"{$this->page_prefix}__mfa/asgard/object/view/{$object->guid}/\" class=\"thickbox\" target=\"_blank\" title=\"" . $this->_l10n_midcom->get('view') . "\">\n";
84
            echo "<i class=\"fa fa-eye\"></i>\n";
85
            echo "</a>\n";
86
        }
87
88
        // Show the link to the object
89
        if ($this->edit_link) {
90
            echo "<a href=\"{$this->page_prefix}__mfa/asgard/object/edit/{$object->guid}/\" target='_blank' title=\"" . $this->_l10n_midcom->get('edit') . "\">\n";
91
            echo "<i class=\"fa fa-pencil\"> </i>\n";
92
            echo "</a>\n";
93
        }
94
95
        if ($this->inputs) {
96
            echo "</label>\n";
97
        }
98
99
        // List the child elements
100
        $this->_list_child_elements($object, $level + 1);
101
102
        echo "</li>\n";
103
    }
104
105
    protected function _is_collapsed(string $type, int $total) : bool
106
    {
107
        if ($this->inputs) {
108
            return false;
109
        }
110
        return parent::_is_collapsed($type, $total);
111
    }
112
113
    /**
114
     * Draw the tree selector
115
     */
116 2
    public function draw()
117
    {
118 2
        if (!$this->input_type) {
119 2
            $this->input_type = 'checkbox';
120
        }
121
122 2
        if (!$this->input_name) {
123 2
            if ($this->input_type === 'checkbox') {
124 2
                $this->input_name = 'selected[]';
125
            } else {
126
                $this->input_name = 'target';
127
            }
128
        }
129
130 2
        $root_object = $this->_object;
131 2
        $this->_list_child_elements($root_object);
132
    }
133
}
134