Passed
Push — master ( 05e7db...c14628 )
by vistart
04:22
created

IndexAction::run()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 39
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 29
nc 2
nop 1
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\organization\web\organization\controllers\my;
14
15
use rhosocial\user\User;
16
use Yii;
17
use yii\base\Action;
18
use yii\data\ActiveDataProvider;
19
20
/**
21
 * @version 1.0
22
 * @author vistart <[email protected]>
23
 */
24
class IndexAction extends Action
25
{
26
    const ORG_ONLY = '1';
27
    const ORG_ALL = '0';
28
    /**
29
     * 
30
     * @param string $orgOnly
31
     * @return string rendering result.
32
     */
33
    public function run($orgOnly = self::ORG_ALL)
34
    {
35
        $user = Yii::$app->user->identity;
36
        /* @var $user User */
37
        $query = ($orgOnly == self::ORG_ONLY) ? $user->getAtOrganizationsOnly() : $user->getAtOrganizations();
38
        $dataProvider = new ActiveDataProvider([
39
            'query' => $query,
40
            'pagination' => [
41
                'pageParam' => 'organization-page',
42
                'defaultPageSize' => 20,
43
                'pageSizeParam' => 'organization-per-page',
44
            ],
45
            'sort' => [
46
                'sortParam' => 'organization-sort',
47
                'attributes' => [
48
                    'id',
49
                    'parent' => [
50
                        'asc' => ['parent_guid' => SORT_ASC],
51
                        'desc' => ['parent_guid' => SORT_DESC],
52
                        'default' => SORT_ASC,
53
                        'label' => Yii::t('organization', 'Parent ID'),
54
                    ],
55
                    'createdAt' => [
56
                        'asc' => ['created_at' => SORT_ASC],
57
                        'desc' => ['created_at' => SORT_DESC],
58
                        'default' => SORT_ASC,
59
                        'label' => Yii::t('user', 'Creation Time'),
60
                    ],
61
                    'updatedAt' => [
62
                        'asc' => ['updated_at' => SORT_ASC],
63
                        'desc' => ['updated_at' => SORT_DESC],
64
                        'default' => SORT_ASC,
65
                        'label' => Yii::t('user', 'Last Updated Time'),
66
                    ],
67
                ],
68
            ],
69
        ]);
70
        return $this->controller->render('index', ['dataProvider' => $dataProvider, 'user' => $user, 'orgOnly' => $orgOnly == self::ORG_ONLY]);
71
    }
72
}
73