ManageBlock::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Icybee package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Icybee\Modules\Users\Block;
13
14
use ICanBoogie\ActiveRecord\Query;
15
use Brickrouge\Document;
16
use Icybee\Block\ManageBlock\DateTimeColumn;
17
use Icybee\Modules\Users\User;
18
use Icybee\Modules\Users\Module;
19
20
class ManageBlock extends \Icybee\Block\ManageBlock
21
{
22
	static protected function add_assets(Document $document)
23
	{
24
		parent::add_assets($document);
25
26
		$document->css->add(\Icybee\Modules\Users\DIR . 'public/admin.css');
27
	}
28
29
	public function __construct($module, array $attributes = [])
30
	{
31
		parent::__construct($module, $attributes + [
32
33
			self::T_COLUMNS_ORDER => [ User::USERNAME, User::IS_ACTIVATED, User::EMAIL, 'roles', User::CREATED_AT, User::LOGGED_AT ],
34
			self::T_ORDER_BY => [ 'created_at', 'desc' ]
35
36
		]);
37
	}
38
39
	/**
40
	 * Adds the following columns:
41
	 *
42
	 * - `username`: An instance of {@link ManageBlock\UsernameColumn}.
43
	 * - `email`: An instance of {@link ManageBlock\EmailColumn}.
44
	 * - `roles`: An instance of {@link ManageBlock\RolesColumn}.
45
	 * - `created_at`: An instance of {@link \Icybee\Block\ManageBlock\DateTimeColumn}.
46
	 * - `logged_at`: An instance of {@link ManageBlock\LoggedAtColumn}.
47
	 * - `is_activated`: An instance of {@link ManageBlock\IsActivatedColumn}.
48
	 *
49
	 * @inheritdoc
50
	 */
51
	protected function get_available_columns()
52
	{
53
		return array_merge(parent::get_available_columns(), [
54
55
			User::USERNAME => ManageBlock\UsernameColumn::class,
56
			User::EMAIL => ManageBlock\EmailColumn::class,
57
			'roles' => ManageBlock\RolesColumn::class,
58
			User::CREATED_AT => DateTimeColumn::class,
59
			User::LOGGED_AT => ManageBlock\LoggedAtColumn::class,
60
			User::IS_ACTIVATED => ManageBlock\IsActivatedColumn::class
61
62
		]);
63
	}
64
65
	/**
66
	 * Filters records according to the constructor (the module that created the record).
67
	 *
68
	 * @inheritdoc
69
	 */
70
	protected function alter_query(Query $query, array $filters)
71
	{
72
		return parent::alter_query($query, $filters)
73
		->filter_by_constructor($this->module->id);
74
	}
75
76
	/**
77
	 * Adds the following jobs:
78
	 *
79
	 * - `activate`: Activate the selected records.
80
	 * - `deactivate`: Deactivate the selected records.
81
	 *
82
	 * @inheritdoc
83
	 */
84
	protected function get_available_jobs()
85
	{
86
		return array_merge(parent::get_available_jobs(), [
87
88
			Module::OPERATION_ACTIVATE => $this->t('activate.operation.title'),
89
			Module::OPERATION_DEACTIVATE => $this->t('deactivate.operation.title')
90
91
		]);
92
	}
93
}
94