Passed
Push — developer ( 5a8c12...cfd609 )
by Radosław
32:36
created

Record::getChildrenUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * ModComments record model file.
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    Radosław Skrzypczak <[email protected]>
10
 */
11
12
namespace YF\Modules\ModComments\Model;
13
14
/**
15
 * ModComments record model class.
16
 */
17
class Record extends \YF\Modules\Base\Model\Record
18
{
19
	/** @var array Sub-comments */
20
	private $children = [];
21
22
	/**
23
	 * Get commentator name.
24
	 *
25
	 * @return string
26
	 */
27
	public function getCommentatorName(): string
28
	{
29
		$name = $this->get('assigned_user_id');
30
		if ($customer = $this->get('customer')) {
31
			$name = $customer['value'];
32
		}
33
		return $name ?: '';
34
	}
35
36
	/**
37
	 * Gets sub-comments.
38
	 *
39
	 * @return array
40
	 */
41
	public function getChildren(): array
42
	{
43
		return $this->children;
44
	}
45
46
	/**
47
	 * Sets sub-comment.
48
	 *
49
	 * @param \YF\Modules\Base\Model\Record $recordModel
50
	 *
51
	 * @return $this
52
	 */
53
	public function setChild(\YF\Modules\Base\Model\Record $recordModel)
54
	{
55
		$this->children[$recordModel->getId()] = $recordModel;
56
		return $this;
57
	}
58
59
	/**
60
	 * Get URL address.
61
	 *
62
	 * @return string
63
	 */
64
	public function getChildrenUrl(): string
65
	{
66
		$url = '';
67
		if ($parent = $this->get('related_to')) {
68
			$url = "index.php?module={$this->moduleName}&view=Comment&record={$this->getId()}&mode=getChildren&sourceId={$parent['record']}&sourceModule={$parent['referenceModule']}";
69
		}
70
		return $url;
71
	}
72
}
73