Passed
Push — developer ( a01779...c62298 )
by Mariusz
172:20 queued 137:05
created

DetailView::setRecordModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
0 ignored issues
show
Documentation introduced by
Should the return type not be \self?

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.

Loading history...
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
0 ignored issues
show
Documentation introduced by
Should the type for parameter $recordModel not be Record?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
54
	 *
55
	 * @return void
56
	 */
57
	public function setRecordModel(Record $recordModel): void
58
	{
59
		$this->record = $recordModel;
0 ignored issues
show
Documentation Bug introduced by
It seems like $recordModel of type object<YF\Modules\Base\Model\Record> is incompatible with the declared type object<YF\Modules\Base\M...ules\Base\Model\Record> of property $record.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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