|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Gitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin 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
|
|
|
# == Schema Information |
|
13
|
|
|
# |
|
14
|
|
|
# Table name: moments |
|
15
|
|
|
# |
|
16
|
|
|
# id :integer not null, primary key |
|
17
|
|
|
# target_type :string(255) |
|
18
|
|
|
# target_id :integer |
|
19
|
|
|
# title :string(255) |
|
20
|
|
|
# data :text |
|
21
|
|
|
# project_id :integer |
|
22
|
|
|
# created_at :timestamp |
|
23
|
|
|
# updated_at :timestamp |
|
24
|
|
|
# action :integer |
|
25
|
|
|
# author_id :integer |
|
26
|
|
|
# |
|
27
|
|
|
|
|
28
|
|
|
namespace Gitamin\Models; |
|
29
|
|
|
|
|
30
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
31
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
32
|
|
|
|
|
33
|
|
|
class Moment extends Model |
|
34
|
|
|
{ |
|
35
|
|
|
const CREATED = 1; |
|
36
|
|
|
const UPDATED = 2; |
|
37
|
|
|
const CLOSED = 3; |
|
38
|
|
|
const REOPENED = 4; |
|
39
|
|
|
const PUSHED = 5; |
|
40
|
|
|
const COMMENTED = 6; |
|
41
|
|
|
const MERGED = 7; |
|
42
|
|
|
const JOINED = 8; # User joined project |
|
43
|
|
|
const LEFT = 9; # User left project |
|
44
|
|
|
const DESTROYED = 10; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Finds all rencent moments. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $query |
|
50
|
|
|
* |
|
51
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
|
52
|
|
|
*/ |
|
53
|
|
|
public function scopeRecent(Builder $query) |
|
54
|
|
|
{ |
|
55
|
|
|
return $query->orderBy('id', 'desc'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Finds all code push moments. |
|
60
|
|
|
* |
|
61
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $query |
|
62
|
|
|
* |
|
63
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
|
64
|
|
|
*/ |
|
65
|
|
|
public function scopeCodePush(Builder $query) |
|
66
|
|
|
{ |
|
67
|
|
|
return $query->where('action', '=', self::PUSHED); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Moments can belong to an author. |
|
72
|
|
|
* |
|
73
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
74
|
|
|
*/ |
|
75
|
|
|
public function author() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->belongsTo(User::class, 'author_id', 'id'); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|