Completed
Push — master ( ccfeeb...7d9725 )
by Alexey
02:50 queued 46s
created

LastVisitBehavior::events()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace modules\users\behavior;
4
5
use Yii;
6
use yii\base\Behavior;
7
use yii\console\Controller;
8
9
/**
10
 * Class LastVisitBehavior
11
 * @package modules\users\behavior
12
 */
13
class LastVisitBehavior extends Behavior
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function events()
19
    {
20
        return [
21
            Controller::EVENT_AFTER_ACTION => 'afterAction'
22
        ];
23
    }
24
25
    /**
26
     * @return bool
27
     */
28
    public function afterAction()
29
    {
30
        if (!Yii::$app->user->isGuest) {
31
            /** @var \yii\web\IdentityInterface $model */
32
            $model = Yii::$app->user->identity;
33
            /** @var \yii\behaviors\TimestampBehavior $model Updates a timestamp attribute to the current timestamp. */
34
            $model->touch('last_visit');
35
        }
36
        return true;
37
    }
38
}
39