1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
8
|
|
|
* @link https://vistart.name/ |
9
|
|
|
* @copyright Copyright (c) 2016 vistart |
10
|
|
|
* @license https://vistart.name/license/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace vistart\Models\traits; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Description of MessageQueryTrait |
17
|
|
|
* |
18
|
|
|
* @author vistart <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
trait MessageQueryTrait |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
public function unread() |
24
|
|
|
{ |
25
|
|
|
$model = $this->noInitModel; |
|
|
|
|
26
|
|
|
$raAttribute = $model->readAtAttribute; |
27
|
|
|
if (!is_string($raAttribute)) { |
28
|
|
|
return $this; |
29
|
|
|
} |
30
|
|
|
return $this->andWhere([$this->$raAttribute => $model->initDatetime()]); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function read() |
34
|
|
|
{ |
35
|
|
|
$model = $this->noInitModel; |
36
|
|
|
$raAttribute = $model->readAtAttribute; |
37
|
|
|
if (!is_string($raAttribute)) { |
38
|
|
|
return $this; |
39
|
|
|
} |
40
|
|
|
return $this->andWhere(['!=', $this->$raAttribute, $model->initDatetime()]); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function unreceived() |
44
|
|
|
{ |
45
|
|
|
$model = $this->noInitModel; |
46
|
|
|
$raAttribute = $model->receivedAtAttribute; |
47
|
|
|
if (!is_string($raAttribute)) { |
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
return $this->andWhere([$this->$raAttribute => $model->initDatetime()]); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function received() |
54
|
|
|
{ |
55
|
|
|
$model = $this->noInitModel; |
56
|
|
|
$raAttribute = $model->receivedAttribute; |
57
|
|
|
if (!is_string($raAttribute)) { |
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
return $this->andWhere(['!=', $this->$raAttribute, $model->initDatetime()]); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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: