-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathUI5Model.php
More file actions
155 lines (133 loc) · 5.51 KB
/
UI5Model.php
File metadata and controls
155 lines (133 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
namespace exface\UI5Facade;
use exface\Core\Interfaces\WidgetInterface;
use exface\Core\Interfaces\DataSheets\DataPointerInterface;
use exface\UI5Facade\Facades\Interfaces\UI5ModelInterface;
use exface\Core\Interfaces\Widgets\iShowSingleAttribute;
use exface\Core\Interfaces\Widgets\iShowDataColumn;
use exface\Core\Interfaces\Widgets\PrefillModelInterface;
use exface\Core\Widgets\Parts\PrefillModel;
use exface\Core\CommonLogic\DataSheets\DataColumn;
class UI5Model extends PrefillModel implements UI5ModelInterface
{
private $name = null;
private $viewName = null;
/**
*
* @param WidgetInterface $widget
* @param string $viewName
* @param string $modelName
*/
public function __construct(WidgetInterface $widget, string $viewName, string $modelName = '')
{
parent::__construct($widget);
$this->viewName = $viewName;
$this->name = $modelName;
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ModelInterface::getName()
*/
public function getName() : string
{
return $this->name;
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ModelInterface::getViewName()
*/
public function getViewName() : string
{
return $this->viewName;
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ModelInterface::getBindingPath()
*/
public function getBindingPath(WidgetInterface $widget, string $bindingName) : string
{
$boundColumn = $this->getBindingDataColumn($widget, $bindingName);
return $boundColumn === null ? '' : '/' . $boundColumn->getName();
}
protected function getBindingDataColumn(WidgetInterface $widget, string $bindingName) : ?DataColumn
{
$binding = $this->getBinding($widget, $bindingName);
if ($binding === null) {
return null;
}
if ($binding instanceof DataPointerInterface) {
return $binding->getColumn();
}
return null;
}
/**
*
* {@inheritDoc}
* @see \exface\UI5Facade\Facades\Interfaces\UI5ModelInterface::hasBindingConflict()
*/
public function hasBindingConflict(WidgetInterface $widget, string $bindingName) : bool
{
// If there is a binding for the given widget and property, don't bother
if ($this->hasBinding($widget, $bindingName)) {
return false;
}
// If the given widget is not showing a single attribute,
// it's really strange (what to bind???) - so treat that as a potential conflict :)
if (! ($widget instanceof iShowSingleAttribute)) {
return true;
}
// Same goes for the case, that the widget is not showing a data column
if (! ($widget instanceof iShowDataColumn)) {
return true;
}
// See if the widget has a data column at all. If not, it will not produce a conflict!
$widgetColumnName = $widget->getDataColumnName();
if ($widgetColumnName === null) {
return false;
}
// Iterate through existing bindings looking for those with the same
// binding name and path, but a different meaning
foreach ($this->getBoundWidgetIds() as $widgetId) {
// If it's the same widget id, there cannot be any conflicts.
if ($widgetId === $widget->getId()) {
continue;
}
// If the binding is empty, there is no conflict either
$bindingPointerWithSameName = $this->getBindingsForWidgetId($widgetId)[$bindingName] ?? null;
if ($bindingPointerWithSameName === null) {
continue;
}
$bindingWidget = $widget->getPage()->getWidget($widgetId);
// If the other binding's widget is not showing a single attribute,
// it's really strange - so treat that as a potential conflict :)
if (! ($bindingWidget instanceof iShowSingleAttribute)) {
return true;
}
// Same goes for the case, that the other widget is not showing a single data column
if (! ($bindingWidget instanceof iShowDataColumn)) {
return true;
}
// Now check if the resulting binding path is the same and if the
// meaning (e.g. attribute) might be different
$boundColumn = $bindingPointerWithSameName->getColumn();
$bindingColumnName = $boundColumn === null ? null : $boundColumn->getName();
// Conflicts may arise if the data column name is the same for different widgets
// showing semantically different things
if ($bindingColumnName === $widgetColumnName) {
// If both can be bound to an attribute, but at least one is not, AND both have
// the same data column name - it's OK, the same value is meant.
if ((! $bindingWidget->isBoundToAttribute() || ! $widget->isBoundToAttribute())) {
continue;
}
// If both are bound to the same data column BUT the attributes are different, it's a conflict!
if (! $bindingWidget->getAttribute()->is($widget->getAttribute())) {
return true;
}
}
}
return false;
}
}