|
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\models; |
|
14
|
|
|
|
|
15
|
|
|
use vistart\Models\traits\BlameableTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Description of BaseMongoBlameableModel |
|
19
|
|
|
* |
|
20
|
|
|
* @author vistart <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class BaseMongoBlameableModel extends BaseMongoEntityModel |
|
23
|
|
|
{ |
|
24
|
|
|
use BlameableTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Initialize the blameable model. |
|
28
|
|
|
* If query class is not specified, [[BaseBlameableQuery]] will be taken. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function init() |
|
31
|
|
|
{ |
|
32
|
|
|
if (!is_string($this->queryClass)) { |
|
33
|
|
|
$this->queryClass = \vistart\Models\queries\BaseMongoBlameableQuery::className(); |
|
34
|
|
|
} |
|
35
|
|
|
if ($this->skipInit) { |
|
36
|
|
|
return; |
|
37
|
|
|
} |
|
38
|
|
|
$this->initBlameableEvents(); |
|
39
|
|
|
parent::init(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the query class with specified identity. |
|
44
|
|
|
* @param \vistart\Models\models\BaseUserModel $identity |
|
45
|
|
|
* @return \vistart\Models\queries\BaseBlameableQuery |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function findByIdentity($identity = null) |
|
48
|
|
|
{ |
|
49
|
|
|
return static::find()->byIdentity($identity); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Because every document has a `MongoId" class, this class is no longer needed GUID feature. |
|
54
|
|
|
* @var boolean determines whether enable the GUID features. |
|
55
|
|
|
*/ |
|
56
|
|
|
public $guidAttribute = false; |
|
57
|
|
|
public $idAttribute = '_id'; |
|
58
|
|
|
|
|
59
|
|
|
public function attributes() |
|
60
|
|
|
{ |
|
61
|
|
|
return [ |
|
62
|
|
|
'_id', |
|
63
|
|
|
$this->createdByAttribute, |
|
64
|
|
|
]; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|