|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Tinyissue package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
|
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 Tinyissue\Repository\Project\Note; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent; |
|
15
|
|
|
use Tinyissue\Contracts\Repository\Project\Note\UpdaterRepository as NoteUpdater; |
|
16
|
|
|
use Tinyissue\Model; |
|
17
|
|
|
use Tinyissue\Model\Project; |
|
18
|
|
|
use Tinyissue\Model\User; |
|
19
|
|
|
use Tinyissue\Repository\RepositoryUpdater; |
|
20
|
|
|
|
|
21
|
|
|
class UpdaterRepository extends RepositoryUpdater implements NoteUpdater |
|
22
|
|
|
{ |
|
23
|
|
|
public function __construct(Project\Note $model) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->model = $model; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Create a new note. |
|
30
|
|
|
* |
|
31
|
|
|
* @param array $input |
|
32
|
|
|
* |
|
33
|
|
|
* @return $this |
|
34
|
|
|
*/ |
|
35
|
|
|
public function create(array $input) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->model->body = $input['note_body']; |
|
38
|
|
|
$this->model->project_id = $this->project->id; |
|
|
|
|
|
|
39
|
|
|
$this->model->created_by = $this->createdBy->id; |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
// Add event on successful save |
|
42
|
|
|
Model\Project\Note::saved(function (Model\Project\Note $note) { |
|
43
|
|
|
$this->queueAdd($note, $note->createdBy); |
|
|
|
|
|
|
44
|
|
|
}); |
|
45
|
|
|
|
|
46
|
|
|
$this->model->save(); |
|
47
|
|
|
|
|
48
|
|
|
// Add to user's activity log |
|
49
|
|
|
// @todo abstract this? |
|
50
|
|
|
$this->model->activity()->save(new Model\User\Activity([ |
|
51
|
|
|
'type_id' => Model\Activity::TYPE_NOTE, |
|
52
|
|
|
'parent_id' => $this->model->project->id, |
|
53
|
|
|
'user_id' => $this->model->createdBy->id, |
|
54
|
|
|
])); |
|
55
|
|
|
|
|
56
|
|
|
return $this; |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Update the note body. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $body |
|
63
|
|
|
* @param Model\User $user |
|
64
|
|
|
* |
|
65
|
|
|
* @return Eloquent\Model |
|
66
|
|
|
*/ |
|
67
|
|
|
public function updateBody($body, Model\User $user) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->model->body = $body; |
|
70
|
|
|
|
|
71
|
|
|
// Add event on successful save |
|
72
|
|
|
Model\Project\Note::saved(function (Model\Project\Note $note) use ($user) { |
|
73
|
|
|
$this->queueUpdate($note, $user); |
|
|
|
|
|
|
74
|
|
|
}); |
|
75
|
|
|
|
|
76
|
|
|
return $this->model->save(); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Delete a note. |
|
81
|
|
|
* |
|
82
|
|
|
* @return bool|null |
|
83
|
|
|
* |
|
84
|
|
|
* @throws \Exception |
|
85
|
|
|
*/ |
|
86
|
|
|
public function delete() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->model->activity()->delete(); |
|
89
|
|
|
|
|
90
|
|
|
// Add event on successful delete |
|
91
|
|
|
Model\Project\Note::deleted(function (Model\Project\Note $note) { |
|
92
|
|
|
$this->queueDelete($note, $this->getLoggedUser()); |
|
|
|
|
|
|
93
|
|
|
}); |
|
94
|
|
|
|
|
95
|
|
|
return $this->model->delete(); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: