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
|
|
|
/** |
28
|
|
|
* Returns model for detail view. |
29
|
|
|
* |
30
|
|
|
* @param string $moduleName |
31
|
|
|
* |
32
|
|
|
* @return self |
|
|
|
|
33
|
|
|
*/ |
34
|
|
|
public static function getInstance(string $moduleName): self |
35
|
|
|
{ |
36
|
|
|
$handlerModule = \App\Loader::getModuleClassName($moduleName, 'Model', 'DetailView'); |
37
|
|
|
return new $handlerModule($moduleName); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Constructor. |
42
|
|
|
* |
43
|
|
|
* @param string $moduleName |
44
|
|
|
*/ |
45
|
|
|
public function __construct(string $moduleName) |
46
|
|
|
{ |
47
|
|
|
$this->moduleName = $moduleName; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Sets record model. |
52
|
|
|
* |
53
|
|
|
* @param YF\Modules\Base\Model\Record $recordModel |
|
|
|
|
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
public function setRecordModel(Record $recordModel): void |
58
|
|
|
{ |
59
|
|
|
$this->record = $recordModel; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get detail view header links. |
64
|
|
|
* |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function getLinksHeader(): array |
68
|
|
|
{ |
69
|
|
|
$links = []; |
70
|
|
|
if ($this->record->isPermitted('ExportPdf') && \App\Pdf::getTemplates($this->moduleName, $this->record->getId())) { |
71
|
|
|
$links[] = [ |
72
|
|
|
'label' => 'BTN_EXPORT_PDF', |
73
|
|
|
'moduleName' => $this->moduleName, |
74
|
|
|
'data' => ['url' => 'index.php?module=' . $this->moduleName . '&view=Pdf&&record=' . $this->record->getId()], |
75
|
|
|
'icon' => 'fas fa-file-pdf', |
76
|
|
|
'class' => 'btn-sm btn-dark js-show-modal js-pdf', |
77
|
|
|
'showLabel' => 1, |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
if ($this->record->isEditable()) { |
81
|
|
|
$links[] = [ |
82
|
|
|
'label' => 'BTN_EDIT', |
83
|
|
|
'moduleName' => $this->moduleName, |
84
|
|
|
'href' => $this->record->getEditViewUrl(), |
85
|
|
|
'icon' => 'fas fa-edit', |
86
|
|
|
'class' => 'btn-sm btn-success', |
87
|
|
|
'showLabel' => 1, |
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
if ($this->record->isInventory()) { |
91
|
|
|
$links[] = [ |
92
|
|
|
'label' => 'BTN_EDIT', |
93
|
|
|
'moduleName' => $this->moduleName, |
94
|
|
|
'href' => 'index.php?module=Products&view=ShoppingCart&reference_id=' . $this->record->getId() . '&reference_module=' . $this->moduleName, |
95
|
|
|
'icon' => 'fas fa-shopping-cart', |
96
|
|
|
'class' => 'btn-sm btn-success', |
97
|
|
|
'showLabel' => 1, |
98
|
|
|
]; |
99
|
|
|
} |
100
|
|
|
if ($this->record->isDeletable()) { |
101
|
|
|
$links[] = [ |
102
|
|
|
'label' => 'LBL_DELETE', |
103
|
|
|
'moduleName' => $this->moduleName, |
104
|
|
|
'data' => ['url' => $this->record->getDeleteUrl()], |
105
|
|
|
'icon' => 'fas fa-trash-alt', |
106
|
|
|
'class' => 'btn-sm btn-danger js-delete-record', |
107
|
|
|
'showLabel' => 1, |
108
|
|
|
]; |
109
|
|
|
} |
110
|
|
|
return $links; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
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.