|
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\Message\Queue; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Eloquent; |
|
15
|
|
|
use Illuminate\Database\Eloquent\Relations; |
|
16
|
|
|
use Tinyissue\Model\Message; |
|
17
|
|
|
use Tinyissue\Model\Project\Issue; |
|
18
|
|
|
use Tinyissue\Model\Tag; |
|
19
|
|
|
use Tinyissue\Model\User; |
|
20
|
|
|
use Tinyissue\Model\Message\Queue; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* QueryTrait is trait class containing the database queries methods for the message queue model. |
|
24
|
|
|
* |
|
25
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
26
|
|
|
* |
|
27
|
|
|
* @method Relations\BelongsToMany tags() |
|
28
|
|
|
*/ |
|
29
|
|
|
trait QueryTrait |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Check whether an issue has registered add new issue in the queue. |
|
33
|
|
|
* |
|
34
|
|
|
* @param Model $model |
|
35
|
|
|
* @param User $user |
|
36
|
|
|
* |
|
37
|
|
|
* @return bool |
|
38
|
|
|
*/ |
|
39
|
|
|
public function isModelCreatedByUser(Model $model, User $user) |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->where('event', '=', $this->getAddEventNameFromModel($model)) |
|
|
|
|
|
|
42
|
|
|
->where('model_id', '=', $model->id) |
|
43
|
|
|
->where('model_type', '=', get_class($model)) |
|
44
|
|
|
->where('change_by_id', '=', $user->id) |
|
45
|
|
|
->first(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Get the latest messages queue. |
|
50
|
|
|
* |
|
51
|
|
|
* @return mixed |
|
52
|
|
|
*/ |
|
53
|
4 |
|
public function latestMessages() |
|
54
|
|
|
{ |
|
55
|
4 |
|
return $this->with('changeBy', 'model')->orderBy('created_at', 'DESC')->orderBy('id', 'DESC'); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.