Passed
Push — developer ( e0199d...a3edbd )
by Mariusz
63:10 queued 29:14
created

Updates::getTitle()   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 0
1
<?php
2
/**
3
 * The file contains: widget of Updates type.
4
 *
5
 * @package 	Widget
6
 *
7
 * @copyright	YetiForce Sp. z o.o.
8
 * @license		YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author		Radosław Skrzypczak <[email protected]>
10
 */
11
12
namespace YF\Modules\Base\Widget;
13
14
/**
15
 * Updates type widget class.
16
 */
17
class Updates extends \App\BaseModel
18
{
19
	/** @var string Widget type. */
20
	protected $type = 'Updates';
21
22
	/** @var string Module name. */
23
	protected $moduleName;
24
25
	/** @var int Source record ID. */
26
	protected $recordId;
27
28
	/** @var int Page number. */
29
	protected $page = 1;
30
31
	/** @var bool More pages. */
32
	protected $isMorePages;
33
34
	/** @var array Scripts. */
35
	public $scripts = [];
36
37
	/** @var int Limit. */
38
	public $limit = 5;
39
40
	/** @var \YF\Modules\Base\Model\RecordHistory Model of history record. */
41
	protected $historyModel;
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
	 * Gets widget ID.
55
	 *
56
	 * @return int
57
	 */
58
	public function getId()
59
	{
60
		return $this->get('id');
61
	}
62
63
	/**
64
	 * Gets widget type.
65
	 *
66
	 * @return string
67
	 */
68
	public function getType(): string
69
	{
70
		return $this->type;
71
	}
72
73
	/**
74
	 * Gets module name.
75
	 *
76
	 * @return string
77
	 */
78
	public function getModuleName(): string
79
	{
80
		return $this->moduleName;
81
	}
82
83
	/**
84
	 * Gets widget name.
85
	 *
86
	 * @return string
87
	 */
88
	public function getTitle(): string
89
	{
90
		return $this->get('name');
91
	}
92
93
	/**
94
	 * Sets record ID.
95
	 *
96
	 * @param int $recordId
97
	 *
98
	 * @return self
99
	 */
100
	public function setRecordId(int $recordId): self
101
	{
102
		$this->recordId = $recordId;
103
104
		return $this;
105
	}
106
107
	/**
108
	 * Get URL address.
109
	 *
110
	 * @return string
111
	 */
112
	public function getUrl(): string
113
	{
114
		return "index.php?module={$this->moduleName}&view=Widget&record={$this->recordId}&mode=getContent&widgetId={$this->getId()}";
115
	}
116
117
	/**
118
	 * Set page number.
119
	 *
120
	 * @param int $page
121
	 *
122
	 * @return $this
123
	 */
124
	public function setPage(int $page): self
125
	{
126
		$this->page = $page;
127
		return $this;
128
	}
129
130
	/**
131
	 * Get page number.
132
	 *
133
	 * @return int
134
	 */
135
	public function getPage(): int
136
	{
137
		return $this->page;
138
	}
139
140
	/**
141
	 * Gets history model.
142
	 *
143
	 * @return \YF\Modules\Base\Model\RecordHistory
144
	 */
145
	public function getHistoryModel(): \YF\Modules\Base\Model\RecordHistory
146
	{
147
		if (null === $this->historyModel) {
148
			$this->historyModel = \YF\Modules\Base\Model\RecordHistory::getInstanceById($this->getModuleName(), $this->recordId)->setLimit($this->limit)->setPage($this->page);
149
		}
150
		return $this->historyModel;
151
	}
152
153
	/**
154
	 * Check if is more pages.
155
	 *
156
	 * @return bool
157
	 */
158
	public function isMorePages(): bool
159
	{
160
		return $this->historyModel->isMorePages;
161
	}
162
163
	/**
164
	 * Gets template path for widget.
165
	 *
166
	 * @return string
167
	 */
168
	public function getTemplatePath(): string
169
	{
170
		return 'Widget/RelatedModule.tpl';
171
	}
172
173
	/**
174
	 * Gets template path for widget content.
175
	 *
176
	 * @return string
177
	 */
178
	public function getTemplateContentPath(): string
179
	{
180
		return "Widget/{$this->type}Content.tpl";
181
	}
182
183
	/**
184
	 * Set scripts.
185
	 *
186
	 * @param array $scripts
187
	 */
188
	public function setScriptsObject($scripts)
189
	{
190
		return $this->scripts = $scripts;
191
	}
192
193
	/**
194
	 * Gets scripts.
195
	 *
196
	 * @return array
197
	 */
198 View Code Duplication
	public function getScripts(): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
199
	{
200
		return [
201
			['layouts/' . \App\Viewer::getLayoutName() . "/modules/{$this->moduleName}/resources/Widget/{$this->type}.js", true],
202
			['layouts/' . \App\Viewer::getLayoutName() . "/modules/Base/resources/Widget/{$this->type}.js", true]
203
		];
204
	}
205
}
206