1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Base file model for Detail View. |
4
|
|
|
* |
5
|
|
|
* @package Model |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce Sp. z o.o. |
8
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
9
|
|
|
* @author Tomasz Kur <[email protected]> |
10
|
|
|
* @author Radosław Skrzypczak <[email protected]> |
11
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace YF\Modules\Base\Model; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Base class model for Detail View. |
18
|
|
|
*/ |
19
|
|
|
class DetailView |
20
|
|
|
{ |
21
|
|
|
/** @var string Name of module. */ |
22
|
|
|
protected $moduleName; |
23
|
|
|
|
24
|
|
|
/** @var \YF\Modules\Base\Model\Record Record model. */ |
25
|
|
|
protected $record; |
26
|
|
|
|
27
|
|
|
/** @var Widget list */ |
28
|
|
|
protected $widgets; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Returns model for detail view. |
32
|
|
|
* |
33
|
|
|
* @param string $moduleName |
34
|
|
|
* |
35
|
|
|
* @return self |
|
|
|
|
36
|
|
|
*/ |
37
|
|
|
public static function getInstance(string $moduleName): self |
38
|
|
|
{ |
39
|
|
|
$handlerModule = \App\Loader::getModuleClassName($moduleName, 'Model', 'DetailView'); |
40
|
|
|
return new $handlerModule($moduleName); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Constructor. |
45
|
|
|
* |
46
|
|
|
* @param string $moduleName |
47
|
|
|
*/ |
48
|
|
|
public function __construct(string $moduleName) |
49
|
|
|
{ |
50
|
|
|
$this->moduleName = $moduleName; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Sets record model. |
55
|
|
|
* |
56
|
|
|
* @param \YF\Modules\Base\Model\Record $recordModel |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function setRecordModel(Record $recordModel): void |
61
|
|
|
{ |
62
|
|
|
$this->record = $recordModel; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get record model. |
67
|
|
|
* |
68
|
|
|
* @return \YF\Modules\Base\Model\Record |
69
|
|
|
*/ |
70
|
|
|
public function getRecordModel(): Record |
71
|
|
|
{ |
72
|
|
|
return $this->record; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get detail view header links. |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
public function getLinksHeader(): array |
81
|
|
|
{ |
82
|
|
|
$links = []; |
83
|
|
|
if (\YF\Modules\Base\Model\Module::isPermitted($this->moduleName, 'ExportPdf') && \App\Pdf::getTemplates($this->moduleName, $this->record->getId())) { |
84
|
|
|
$links[] = [ |
85
|
|
|
'label' => 'BTN_EXPORT_PDF', |
86
|
|
|
'moduleName' => $this->moduleName, |
87
|
|
|
'data' => ['url' => 'index.php?module=' . $this->moduleName . '&view=Pdf&&record=' . $this->record->getId()], |
88
|
|
|
'icon' => 'fas fa-file-pdf', |
89
|
|
|
'class' => 'btn-sm btn-dark js-show-modal js-pdf', |
90
|
|
|
'showLabel' => 1, |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
if ($this->record->isEditable()) { |
94
|
|
|
$links[] = [ |
95
|
|
|
'label' => 'BTN_EDIT', |
96
|
|
|
'moduleName' => $this->moduleName, |
97
|
|
|
'href' => $this->record->getEditViewUrl(), |
98
|
|
|
'icon' => 'fas fa-edit', |
99
|
|
|
'class' => 'btn-sm btn-success', |
100
|
|
|
'showLabel' => 1, |
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
if ($this->record->isInventory()) { |
104
|
|
|
$links[] = [ |
105
|
|
|
'label' => 'BTN_EDIT', |
106
|
|
|
'moduleName' => $this->moduleName, |
107
|
|
|
'href' => 'index.php?module=Products&view=ShoppingCart&reference_id=' . $this->record->getId() . '&reference_module=' . $this->moduleName, |
108
|
|
|
'icon' => 'fas fa-shopping-cart', |
109
|
|
|
'class' => 'btn-sm btn-success', |
110
|
|
|
'showLabel' => 1, |
111
|
|
|
]; |
112
|
|
|
} |
113
|
|
|
if ($this->record->isDeletable()) { |
114
|
|
|
$links[] = [ |
115
|
|
|
'label' => 'LBL_DELETE', |
116
|
|
|
'moduleName' => $this->moduleName, |
117
|
|
|
'data' => ['url' => $this->record->getDeleteUrl()], |
118
|
|
|
'icon' => 'fas fa-trash-alt', |
119
|
|
|
'class' => 'btn-sm btn-danger js-delete-record', |
120
|
|
|
'showLabel' => 1, |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
return $links; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Gets widgets. |
128
|
|
|
* |
129
|
|
|
* @return array |
130
|
|
|
*/ |
131
|
|
|
public function getWidgets(): array |
132
|
|
|
{ |
133
|
|
|
if (null === $this->widgets) { |
134
|
|
|
$this->widgets = []; |
|
|
|
|
135
|
|
|
foreach (\App\Widgets::getInstance($this->moduleName)->getAll() as $widgetObject) { |
136
|
|
|
$widgetObject->setRecordId($this->record->getId()); |
137
|
|
|
$this->widgets[$widgetObject->getId()] = $widgetObject; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
return $this->widgets; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.