Passed
Push — master ( 9b6cf0...d3c4d5 )
by Georgi
05:20
created

HomePage::init()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.9332
1
<?php
2
3
namespace Epesi\Core\HomePage\Database\Models;
4
5
use Epesi\Core\Data\Model;
6
use Epesi\Core\HomePage\HomePageSettings;
7
use Spatie\Permission\Models\Role;
8
9
class HomePage extends Model
10
{
11
	public $table = 'home_pages';
12
	
13
	public $caption = 'Home Page';
14
	
15
	public $title_field = 'path';
16
	
17
	function init() {
18
		parent::init();
19
		
20
		$this->addFields([
21
				['path', 'caption' => __('Page'), 'values' => HomePageSettings::getAvailableHomePages()],
22
				['role', 'caption' => __('Role'), 'enum' => Role::get()->pluck('name')->all()],
23
				'priority',
24
		]);
25
		
26
		$this->setOrder('priority');
27
28
		$this->addHook('beforeInsert', function($model, & $data) {
29
			$data['priority'] = $data['priority']?: $this->action('fx', ['max', 'priority'])->getOne() + 1;
30
		});
31
		
32
		$this->getAction('edit')->enabled = function($model) {
33
			return $model->id == 22; 
34
			};
35
	}
36
}
37