HomePageSettings   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 48
rs 10
c 6
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A access() 0 3 2
A body() 0 39 2
1
<?php
2
3
namespace Epesi\Core\HomePage;
4
5
use Epesi\Core\System\Modules\ModuleView;
6
use Illuminate\Support\Facades\Auth;
7
use Epesi\Core\Layout\View\ActionBar;
8
use atk4\ui\GridPlugin\Filter;
0 ignored issues
show
Bug introduced by
The type atk4\ui\GridPlugin\Filter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use atk4\ui\Crud;
10
11
class HomePageSettings extends ModuleView
12
{
13
	protected $label = 'Home Page Administration';
14
	
15
	public static function access()
16
	{
17
		return Auth::user()->can('modify system settings') && Model\HomePage::list();
18
	}
19
	
20
	public function body()
21
	{
22
		ActionBar::addItemButton('back')->link(url('view/system'));
23
24
		$grid = $this->add([
25
				Crud::class,
26
		          'menu' => ActionBar::instance(),
27
// 		        'model' => HomePage::create(),
28
				'displayFields' => ['path', 'role'],
29
				'editFields' => ['path', 'role'],
30
				'notifyDefault' => ['jsNotify', 'content' => __('Data is saved!'), 'color' => 'green'],
31
				'paginator' => false,
32
// 		        'plugins' => [
33
// 		                'quickSearch' => true,//['path', 'role'],
34
// 		                'paginator' => false
35
// 		        ]
36
		]);
37
		
38
		$grid->setModel(Model\HomePage::create());
0 ignored issues
show
Bug introduced by
The method setModel() does not exist on atk4\ui\AbstractView. It seems like you code against a sub-type of atk4\ui\AbstractView such as atk4\ui\View. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
		$grid->/** @scrutinizer ignore-call */ 
39
         setModel(Model\HomePage::create());
Loading history...
39
		
40
// 		$grid->model->getField('path')->ui['filter'] = [
41
// 				'values' => ['aa', 'bb'],
42
// 				'callback' => function($plugin, $value) {
43
// 					$plugin->owner->model->addCondition('path', 'view/dashboard');
44
// 				}
45
// 		];
46
47
// 		$grid->add(Filter::class);
48
49
// 		$grid->getElement('filter')->form->addField('test', ['CheckBox', 'ui' => ['filter' => ['callback' => function($filter, $key, $value){$filter->owner->model->addCondition('path', null);}]]]);
50
51
// 		$plugin->extendList('path');
52
53
		$grid->addDragHandler()->onReorder(function ($order) {
0 ignored issues
show
Bug introduced by
The method addDragHandler() does not exist on atk4\ui\AbstractView. It seems like you code against a sub-type of atk4\ui\AbstractView such as atk4\ui\Grid. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
		$grid->/** @scrutinizer ignore-call */ 
54
         addDragHandler()->onReorder(function ($order) {
Loading history...
54
			foreach (Model\HomePage::create() as $homepage) {
55
				$homepage->save(['priority' => array_search($homepage['id'], $order)]);
56
			}
57
			
58
			return $this->notifySuccess(__('Homepages reordered!'));
59
		});
60
	}
61
}
62