|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
|
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
|
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
|
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
|
8
|
|
|
* @link https://vistart.me/ |
|
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
|
10
|
|
|
* @license https://vistart.me/license/ |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace rhosocial\base\models\queries; |
|
14
|
|
|
|
|
15
|
|
|
use MongoDB\BSON\Binary; |
|
16
|
|
|
use rhosocial\base\models\models\BaseUserModel; |
|
17
|
|
|
use rhosocial\base\models\traits\BlameableQueryTrait; |
|
18
|
|
|
use Yii; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Description of BaseMongoBlameableQuery |
|
22
|
|
|
* |
|
23
|
|
|
* @version 1.0 |
|
24
|
|
|
* @author vistart <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class BaseMongoBlameableQuery extends BaseMongoEntityQuery |
|
27
|
|
|
{ |
|
28
|
|
|
use BlameableQueryTrait; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Specify creator(s). |
|
32
|
|
|
* @param string|array $guid |
|
33
|
|
|
* @return $this |
|
34
|
|
|
*/ |
|
35
|
9 |
|
public function createdBy($guid) |
|
36
|
|
|
{ |
|
37
|
9 |
|
$model = $this->noInitModel; |
|
38
|
9 |
|
if (!is_string($model->createdByAttribute)) { |
|
|
|
|
|
|
39
|
|
|
return $this; |
|
40
|
|
|
} |
|
41
|
9 |
|
if ($guid instanceof BaseUserModel) { |
|
42
|
3 |
|
$guid = $guid->getGUID(); |
|
43
|
|
|
} |
|
44
|
9 |
|
return $this->andWhere([$model->createdByAttribute => new Binary($guid, Binary::TYPE_UUID)]); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Specify last updater(s). |
|
49
|
|
|
* @param string|array $guid |
|
50
|
|
|
* @return $this |
|
51
|
|
|
*/ |
|
52
|
4 |
|
public function updatedBy($guid) |
|
53
|
|
|
{ |
|
54
|
4 |
|
$model = $this->noInitModel; |
|
55
|
4 |
|
if (!is_string($model->updatedByAttribute)) { |
|
|
|
|
|
|
56
|
1 |
|
return $this; |
|
57
|
|
|
} |
|
58
|
3 |
|
if ($guid instanceof BaseUserModel) { |
|
59
|
3 |
|
$guid = $guid->getGUID(); |
|
60
|
|
|
} |
|
61
|
3 |
|
return $this->andWhere([$model->updatedByAttribute => new Binary($guid, Binary::TYPE_UUID)]); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Attach current identity to createdBy condition. |
|
66
|
|
|
* @param BaseUserModel $identity |
|
67
|
|
|
* @return $this |
|
68
|
|
|
*/ |
|
69
|
6 |
|
public function byIdentity($identity = null) |
|
70
|
|
|
{ |
|
71
|
6 |
|
if (!$identity) { |
|
72
|
1 |
|
$identity = Yii::$app->user->identity; |
|
73
|
|
|
} |
|
74
|
6 |
|
if (method_exists($identity, 'canGetProperty') && !$identity->canGetProperty('guid')) { |
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
6 |
|
return $this->createdBy($identity->getGUID()); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.