Passed
Push — master ( 1601bb...5d0926 )
by Georgi
03:38
created

HomePageSettings::getAvailableHomePages()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 12
rs 10
1
<?php
2
3
namespace Epesi\Core\HomePage;
4
5
use Epesi\Core\System\Integration\Modules\ModuleView;
6
use Illuminate\Support\Facades\Auth;
7
use Epesi\Core\HomePage\Database\Models\HomePage;
8
use Epesi\Core\Layout\Seeds\ActionBar;
9
10
class HomePageSettings extends ModuleView
11
{
12
	protected $label = 'Home Page Administration';
13
	
14
	public static function access()
15
	{
16
		return Auth::user()->can('modify system settings') && HomePage::list();
17
	}
18
	
19
	public function body()
20
	{
21
		ActionBar::addButton('back')->link(url('view/system'));
22
23
		$grid = $this->add([
24
				'CRUD',
25
				'displayFields' => ['path', 'role'],
26
				'editFields' => ['path', 'role'],
27
				'notifyDefault' => ['jsNotify', 'content' => __('Data is saved!'), 'color' => 'green'],
28
				'paginator' => false
29
		]);
30
		
31
		$grid->setModel(HomePage::create());
32
33
		$grid->addDragHandler()->onReorder(function ($order) {
0 ignored issues
show
Bug introduced by
The method addDragHandler() does not exist on atk4\ui\View. It seems like you code against a sub-type of atk4\ui\View 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

33
		$grid->/** @scrutinizer ignore-call */ 
34
         addDragHandler()->onReorder(function ($order) {
Loading history...
34
			$result = true;
35
			foreach (HomePage::create() as $homepage) {
36
				$homepage['priority'] = array_search($homepage['id'], $order);
37
				
38
				$result &= $homepage->save();
39
			}
40
			
41
			return $result? $this->notify(__('Homepages reordered!')): $this->notifyError(__('Error saving order!'));
42
		});
43
	}
44
}
45