|
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
|
|
|
* @var boolean |
|
20
|
|
|
*/ |
|
21
|
|
|
public $copy_tree = false; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Switch to determine the visibility of inputs |
|
25
|
|
|
* |
|
26
|
|
|
* @var boolean |
|
27
|
|
|
*/ |
|
28
|
|
|
public $inputs = true; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Choose the target type |
|
32
|
|
|
* |
|
33
|
|
|
* @var String |
|
34
|
|
|
*/ |
|
35
|
|
|
public $input_type; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Choose the target name for the form |
|
39
|
|
|
* |
|
40
|
|
|
* @var String |
|
41
|
|
|
*/ |
|
42
|
|
|
public $input_name; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Show the link to view the object |
|
46
|
|
|
* |
|
47
|
|
|
* @var boolean |
|
48
|
|
|
*/ |
|
49
|
|
|
public $view_link = false; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Show the link to view the object |
|
53
|
|
|
* |
|
54
|
|
|
* @var boolean |
|
55
|
|
|
*/ |
|
56
|
|
|
public $edit_link = false; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Page prefix |
|
60
|
|
|
* |
|
61
|
|
|
* @var String |
|
62
|
|
|
*/ |
|
63
|
|
|
public $page_prefix = ''; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Constructor, connect to the parent class constructor. |
|
67
|
|
|
* |
|
68
|
|
|
* @param mixed $object |
|
69
|
|
|
* @param array $request_data |
|
70
|
|
|
*/ |
|
71
|
2 |
|
public function __construct($object, &$request_data) |
|
72
|
|
|
{ |
|
73
|
2 |
|
parent::__construct($object, $request_data); |
|
74
|
2 |
|
$this->page_prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX); |
|
|
|
|
|
|
75
|
2 |
|
} |
|
76
|
|
|
|
|
77
|
1 |
|
protected function _draw_element($object, string $label, int $level, bool $autoexpand = false) |
|
78
|
|
|
{ |
|
79
|
1 |
|
$ref = midcom_helper_reflector_tree::get($object); |
|
80
|
1 |
|
$span_class = ''; |
|
81
|
1 |
|
$css_class = $this->get_css_classes($object, $ref->mgdschema_class); |
|
|
|
|
|
|
82
|
1 |
|
$this->shown_objects[$object->guid] = true; |
|
83
|
|
|
|
|
84
|
1 |
|
echo "<li class=\"{$css_class}\">\n"; |
|
85
|
|
|
|
|
86
|
1 |
|
$label = htmlspecialchars($ref->get_object_label($object)); |
|
87
|
1 |
|
$icon = $ref->get_object_icon($object); |
|
88
|
1 |
|
if (empty($label)) { |
|
89
|
|
|
$label = "#{$object->id}"; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
1 |
|
$checked = ($this->copy_tree) ? ' checked="checked"' : ''; |
|
93
|
|
|
|
|
94
|
1 |
|
if ($this->inputs) { |
|
95
|
|
|
// This value is used for compiling the exclusion list: if the object is found from this list, but not from the selection list, |
|
96
|
|
|
// it means that the selection did not include the object GUID |
|
97
|
1 |
|
echo "<input type=\"hidden\" name=\"all_objects[]\" value=\"{$object->guid}\" />\n"; |
|
98
|
|
|
|
|
99
|
1 |
|
echo "<label for=\"item_{$object->guid}\">\n"; |
|
100
|
1 |
|
echo "<input id=\"item_{$object->guid}\" type=\"{$this->input_type}\" name=\"{$this->input_name}\" value=\"{$object->guid}\"{$checked} />\n"; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
1 |
|
echo "<span class=\"title{$span_class}\" title=\"" . sprintf($this->_l10n->get('%s (%s)'), $label, $ref->get_class_label()) . "\">{$icon}{$label}</span>\n"; |
|
104
|
|
|
|
|
105
|
|
|
// Show the link to the object |
|
106
|
1 |
|
if ($this->view_link) { |
|
107
|
1 |
|
echo "<a href=\"{$this->page_prefix}__mfa/asgard/object/view/{$object->guid}/\" class=\"thickbox\" target=\"_blank\" title=\"" . $this->_l10n->get('view object') . "\">\n"; |
|
108
|
1 |
|
echo "<i class=\"fa fa-eye\"></i>\n"; |
|
109
|
1 |
|
echo "</a>\n"; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
// Show the link to the object |
|
113
|
1 |
|
if ($this->edit_link) { |
|
114
|
|
|
echo "<a href=\"{$this->page_prefix}__mfa/asgard/object/edit/{$object->guid}/\" target='_blank' title=\"" . $this->_l10n->get('edit object') . "\">\n"; |
|
115
|
|
|
echo "<i class=\"fa fa-pencil\"> </i>\n"; |
|
116
|
|
|
echo "</a>\n"; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
1 |
|
if ($this->inputs) { |
|
120
|
1 |
|
echo "</label>\n"; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
// List the child elements |
|
124
|
1 |
|
$this->_list_child_elements($object, $level + 1); |
|
125
|
|
|
|
|
126
|
1 |
|
echo "</li>\n"; |
|
127
|
1 |
|
} |
|
128
|
|
|
|
|
129
|
1 |
|
protected function _is_collapsed($type, $total) : bool |
|
130
|
|
|
{ |
|
131
|
1 |
|
if ($this->inputs) { |
|
132
|
1 |
|
return false; |
|
133
|
|
|
} |
|
134
|
|
|
return parent::_is_collapsed($type, $total); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Draw the tree selector |
|
139
|
|
|
*/ |
|
140
|
2 |
|
public function draw() |
|
141
|
|
|
{ |
|
142
|
2 |
|
if (!$this->input_type) { |
|
143
|
2 |
|
$this->input_type = 'checkbox'; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
2 |
|
if (!$this->input_name) { |
|
147
|
2 |
|
if ($this->input_type === 'checkbox') { |
|
148
|
2 |
|
$this->input_name = 'selected[]'; |
|
149
|
|
|
} else { |
|
150
|
|
|
$this->input_name = 'target'; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
2 |
|
$root_object = $this->_object; |
|
155
|
2 |
|
$this->_list_child_elements($root_object); |
|
156
|
2 |
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.