Passed
Push — master ( 01a84c...98164f )
by Paweł
03:03
created

UserController::actionTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 05.02.2018
6
 */
7
8
namespace app\commands;
9
10
11
use app\models\User;
12
use app\modules\admin\components\AccountStatsManager;
13
use app\modules\admin\models\Account;
14
use yii\console\Controller;
15
use yii\console\ExitCode;
16
use yii\console\widgets\Table;
17
use yii\helpers\Console;
18
19
class UserController extends Controller
20
{
21
22
    public function actionTest()
23
    {
24
        $manager = \Yii::createObject([
25
            'class' => AccountStatsManager::class,
26
            'account' => Account::findOne(755),
27
        ]);
28
29
        print_r($manager->lastMonthChange('followed_by'));
30
    }
31
32
    /**
33
     *
34
     * @param mixed $ident ID or Email
35
     * @return int
36
     * @throws \Throwable
37
     * @throws \yii\db\StaleObjectException
38
     */
39
    public function actionActivate($ident)
40
    {
41
        $user = User::findOne(is_numeric($ident) ? $ident : ['email' => $ident]);
42
        if ($user === null) {
43
            $this->stdout("User not found!\n", Console::FG_RED);
44
45
            return ExitCode::UNSPECIFIED_ERROR;
46
        }
47
        $user->active = 1;
48
        $user->update(false);
49
        $this->stdout("OK!\n");
50
51
        return ExitCode::OK;
52
    }
53
54
    public function actionIndex()
55
    {
56
        echo Table::widget([
57
            'headers' => [
58
                'ID',
59
                'Username',
60
                'Email',
61
                'Active',
62
            ],
63
            'rows' => User::find()
64
                ->select([
65
                    'id',
66
                    'username',
67
                    'email',
68
                    'active',
69
                ])
70
                ->orderBy('id DESC')
71
                ->asArray()
72
                ->all(),
73
        ]);
74
    }
75
}