Completed
Push — develop ( 86c33f...64265e )
by Mohamed
07:18
created

CrudTrait::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
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\Model\Traits\Project\Note;
13
14
use Illuminate\Database\Eloquent;
15
use Illuminate\Database\Eloquent\Relations;
16
use Tinyissue\Model;
17
18
/**
19
 * CrudTrait is trait class containing the methods for adding/editing/deleting the Project\Note model.
20
 *
21
 * @author Mohamed Alsharaf <[email protected]>
22
 *
23
 * @property int                  $project_id
24
 * @property int                  $created_by
25
 * @property string               $body
26
 * @property Model\Project        $project
27
 * @property Model\User           $createdBy
28
 *
29
 * @method   Relations\BelongsTo  belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
30
 * @method   Eloquent\Model       save()
31
 * @method   Relations\HasOne     activity()
32
 */
33
trait CrudTrait
34
{
35
    /**
36
     * Create a new note.
37
     *
38
     * @param array $input
39
     *
40
     * @return $this
41
     */
42 2
    public function createNote(array $input)
43
    {
44 2
        $this->body       = $input['note_body'];
45 2
        $this->project_id = $this->project->id;
46 2
        $this->created_by = $this->createdBy->id;
47 2
        $this->save();
48
49
        // Add to user's activity log
50 2
        $this->activity()->save(new Model\User\Activity([
51 2
            'type_id'   => Model\Activity::TYPE_NOTE,
52 2
            'parent_id' => $this->project->id,
53 2
            'user_id'   => $this->createdBy->id,
54
        ]));
55
56 2
        return $this;
57
    }
58
59
    /**
60
     * Delete a note.
61
     *
62
     * @return bool|null
63
     *
64
     * @throws \Exception
65
     */
66 1
    public function delete()
67
    {
68 1
        $this->activity()->delete();
69
70 1
        return parent::delete();
71
    }
72
}
73