Passed
Push — developer ( 6cca19...a1733f )
by Radosław
47:59 queued 12:43
created

Comments::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 Comments 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
 * Comments type widget class.
16
 */
17
class Comments extends RelatedModule
18
{
19
	/** @var string Widget type. */
20
	protected $type = 'Comments';
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
	/**
41
	 * Constructor.
42
	 *
43
	 * @param string $moduleName
44
	 */
45
	public function __construct(string $moduleName)
46
	{
47
		$this->moduleName = $moduleName;
48
	}
49
50
	/**
51
	 * Gets widget ID.
52
	 *
53
	 * @return int
54
	 */
55
	public function getId()
56
	{
57
		return $this->get('id');
58
	}
59
60
	/**
61
	 * Gets widget type.
62
	 *
63
	 * @return string
64
	 */
65
	public function getType(): string
66
	{
67
		return $this->type;
68
	}
69
70
	/**
71
	 * Gets module name.
72
	 *
73
	 * @return string
74
	 */
75
	public function getModuleName(): string
76
	{
77
		return $this->moduleName;
78
	}
79
80
	/**
81
	 * Gets widget name.
82
	 *
83
	 * @return string
84
	 */
85
	public function getTitle(): string
86
	{
87
		return $this->get('name');
88
	}
89
90
	/**
91
	 * Sets record ID.
92
	 *
93
	 * @param int $recordId
94
	 *
95
	 * @return $this
96
	 */
97
	public function setRecordId(int $recordId)
98
	{
99
		$this->recordId = $recordId;
100
101
		return $this;
102
	}
103
104
	/**
105
	 * Get URL address.
106
	 *
107
	 * @return string
108
	 */
109
	public function getUrl(): string
110
	{
111
		return "index.php?module={$this->moduleName}&view=Widget&record={$this->recordId}&mode=getContent&widgetId={$this->getId()}";
112
	}
113
114
	/**
115
	 * Set page number.
116
	 *
117
	 * @param int $page
118
	 *
119
	 * @return $this
120
	 */
121
	public function setPage(int $page)
122
	{
123
		$this->page = $page;
124
		return $this;
125
	}
126
127
	/**
128
	 * Get page number.
129
	 *
130
	 * @return int
131
	 */
132
	public function getPage(): int
133
	{
134
		return $this->page;
135
	}
136
137
	/**
138
	 * Gets fields from related module.
139
	 *
140
	 * @return array
141
	 */
142
	public function getFields(): array
143
	{
144
		return ['parent_comments', 'createdtime', 'modifiedtime', 'related_to', 'id',
145
			'assigned_user_id', 'commentcontent', 'creator', 'customer', 'reasontoedit', 'userid', 'parents'];
146
	}
147
148
	/**
149
	 * Gets related module name.
150
	 *
151
	 * @return string
152
	 */
153
	public function getRelatedModuleName(): string
154
	{
155
		return 'ModComments';
156
	}
157
158
	/**
159
	 * Check if is more pages.
160
	 *
161
	 * @return bool
162
	 */
163
	public function isMorePages(): bool
164
	{
165
		return $this->isMorePages;
166
	}
167
168
	/**
169
	 * Load data.
170
	 *
171
	 * @return $this
172
	 */
173
	public function loadData()
174
	{
175
		$relatedListModel = \YF\Modules\ModComments\Model\RelatedList::getInstance($this->getModuleName())
176
			->setRecordId($this->recordId)
177
			->setFields($this->getFields());
178
		$relatedListModel->loadRecordsList();
179
		$this->entries = $relatedListModel->getRecordsTree();
180
		$this->headers = array_intersect_key($relatedListModel->getHeaders(), array_flip($this->getFields()));
181
		$this->isMorePages = $relatedListModel->isMorePages();
182
		return $this;
183
	}
184
185
	/**
186
	 * Gets template path for widget.
187
	 *
188
	 * @return string
189
	 */
190
	public function getTemplatePath(): string
191
	{
192
		return 'Widget/RelatedModule.tpl';
193
	}
194
195
	/**
196
	 * Gets template path for widget content.
197
	 *
198
	 * @return string
199
	 */
200
	public function getTemplateContentPath(): string
201
	{
202
		return "Widget/{$this->type}Content.tpl";
203
	}
204
205
	/**
206
	 * Set scripts.
207
	 *
208
	 * @param array $scripts
209
	 */
210
	public function setScriptsObject($scripts)
211
	{
212
		return $this->scripts = $scripts;
213
	}
214
215
	/**
216
	 * Gets scripts.
217
	 *
218
	 * @return array
219
	 */
220
	public function getScripts(): array
221
	{
222
		return [
223
			['layouts/' . \App\Viewer::getLayoutName() . "/modules/{$this->moduleName}/resources/Widget/{$this->type}.js", true],
224
			['layouts/' . \App\Viewer::getLayoutName() . "/modules/Base/resources/Widget/{$this->type}.js", true]
225
		];
226
	}
227
}
228