1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Jitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) Jitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jitamin\Bus\EventBuilder; |
13
|
|
|
|
14
|
|
|
use Jitamin\Bus\Event\GenericEvent; |
15
|
|
|
use Jitamin\Bus\Event\TaskFileEvent; |
16
|
|
|
use Jitamin\Model\TaskFileModel; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class TaskFileEventBuilder. |
20
|
|
|
*/ |
21
|
|
|
class TaskFileEventBuilder extends BaseEventBuilder |
22
|
|
|
{ |
23
|
|
|
protected $fileId = 0; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Set fileId. |
27
|
|
|
* |
28
|
|
|
* @param int $fileId |
29
|
|
|
* |
30
|
|
|
* @return $this |
31
|
|
|
*/ |
32
|
|
|
public function withFileId($fileId) |
33
|
|
|
{ |
34
|
|
|
$this->fileId = $fileId; |
35
|
|
|
|
36
|
|
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Build event data. |
41
|
|
|
* |
42
|
|
|
* @return GenericEvent|null |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function buildEvent() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$file = $this->taskFileModel->getById($this->fileId); |
|
|
|
|
47
|
|
|
|
48
|
|
|
if (empty($file)) { |
49
|
|
|
$this->logger->debug(__METHOD__.': File not found'); |
|
|
|
|
50
|
|
|
|
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return new TaskFileEvent([ |
55
|
|
|
'file' => $file, |
56
|
|
|
'task' => $this->taskFinderModel->getDetails($file['task_id']), |
|
|
|
|
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get event title with author. |
62
|
|
|
* |
63
|
|
|
* @param string $author |
64
|
|
|
* @param string $eventName |
65
|
|
|
* @param array $eventData |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function buildTitleWithAuthor($author, $eventName, array $eventData) |
70
|
|
|
{ |
71
|
|
|
if ($eventName === TaskFileModel::EVENT_CREATE) { |
72
|
|
|
return l('%s attached a file to the task #%d', $author, $eventData['task']['id']); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return ''; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get event title without author. |
80
|
|
|
* |
81
|
|
|
* @param string $eventName |
82
|
|
|
* @param array $eventData |
83
|
|
|
* |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function buildTitleWithoutAuthor($eventName, array $eventData) |
87
|
|
|
{ |
88
|
|
|
if ($eventName === TaskFileModel::EVENT_CREATE) { |
89
|
|
|
return l('New attachment on task #%d: %s', $eventData['file']['task_id'], $eventData['file']['name']); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return ''; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
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.