Completed
Pull Request — master (#247)
by
unknown
09:38
created

Grid::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 22
rs 9.2
ccs 15
cts 15
cp 1
crap 1
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/skeleton
5
 */
6
7
/**
8
 * @namespace
9
 */
10
namespace Application\Users;
11
12
use Bluz\Db\Query\Select;
13
use Bluz\Grid\Source\SelectSource;
14
15
/**
16
 * @category Application
17
 * @package  Users
18
 */
19
class Grid extends \Bluz\Grid\Grid
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $uid = 'users';
25
26
    /**
27
     * init
28
     *
29
     * @return self
30
     */
31 1
    public function init()
32
    {
33
        // Create Select
34 1
        $select = new Select();
35 1
        $select->select('u.*, u.id as uid, GROUP_CONCAT( ar.`name` SEPARATOR ", " ) AS rolesList')
36 1
            ->from('users', 'u')
37 1
            ->leftJoin('u', 'acl_users_roles', 'aur', 'u.`id` = aur.`userId`')
38 1
            ->leftJoin('aur', 'acl_roles', 'ar', 'ar.`id` = aur.`roleId`')
39 1
            ->groupBy('u.id');
40
41
42
        // Setup adapter
43 1
        $adapter = new SelectSource();
44 1
        $adapter->setSource($select);
45
46 1
        $this->setAdapter($adapter);
47 1
        $this->setDefaultLimit(25);
48 1
        $this->addAlias('id', 'u.id');
49 1
        $this->setAllowOrders(['login', 'email', 'status', 'id']);
50 1
        $this->setAllowFilters(['login', 'email', 'status', 'id', 'roleId']);
51 1
        return $this;
52
    }
53
}
54