1 | <?php |
||
24 | abstract class BaseMongoMessageModel extends BaseMongoBlameableModel |
||
25 | { |
||
26 | use MessageTrait; |
||
27 | |||
28 | public $updatedAtAttribute = false; |
||
29 | public $updatedByAttribute = false; |
||
30 | public $expiredAt = 604800; // 7 days. |
||
31 | |||
32 | 13 | public function init() |
|
43 | |||
44 | /** |
||
45 | * Get recipient. |
||
46 | * @return BaseUserQuery |
||
47 | */ |
||
48 | 2 | public function getRecipient() |
|
49 | { |
||
50 | 2 | if (!is_string($this->otherGuidAttribute) || empty($this->otherGuidAttribute)) { |
|
51 | 1 | throw new \yii\base\InvalidConfigException('Recipient GUID Attribute Not Specified.'); |
|
52 | } |
||
53 | 1 | $hostClass = $this->hostClass; |
|
54 | 1 | $model = $hostClass::buildNoInitModel(); |
|
55 | 1 | return $this->hasOne($hostClass::className(), [$model->guidAttribute => 'otherAttribute']); |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Get updated_by attribute. |
||
60 | * @return string|null |
||
61 | */ |
||
62 | 1 | public function getOtherAttribute() |
|
63 | { |
||
64 | 1 | $otherGuidAttribute = $this->otherGuidAttribute; |
|
65 | 1 | return (!is_string($otherGuidAttribute) || empty($otherGuidAttribute)) ? null : $this->$otherGuidAttribute->getData(); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Set recipient. |
||
70 | * @param BaseUserModel $user |
||
71 | * @return string |
||
72 | */ |
||
73 | 13 | public function setRecipient($user) |
|
74 | { |
||
75 | 13 | if (!is_string($this->otherGuidAttribute) || empty($this->otherGuidAttribute)) { |
|
76 | 1 | throw new \yii\base\InvalidConfigException('Recipient GUID Attribute Not Specified.'); |
|
77 | } |
||
78 | 13 | if ($user instanceof BaseUserModel) { |
|
79 | 13 | $user = $user->getGUID(); |
|
80 | } |
||
81 | 13 | $otherGuidAttribute = $this->otherGuidAttribute; |
|
82 | 13 | return $this->$otherGuidAttribute = new Binary($user, Binary::TYPE_UUID); |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * Get mutual attributes rules. |
||
87 | * @return array |
||
88 | */ |
||
89 | 13 | public function getMutualRules() |
|
99 | } |