SettingsView   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A body() 0 8 2
A edit() 0 20 1
1
<?php
2
3
namespace Epesi\Core\System\User\Settings;
4
5
use Epesi\Core\System\Modules\ModuleView;
6
use Epesi\Core\System\User\Settings\Integration\Joints\UserSettingsJoint;
7
use Epesi\Core\System\View\Form;
8
use Epesi\Core\Layout\View\ActionBar;
9
use Epesi\Core\System\User\Settings\Database\Models\UserSetting;
10
use atk4\ui\View;
11
12
class SettingsView extends ModuleView
13
{
14
	protected $label = 'User Settings';
15
	
16
	public function body()
17
	{
18
		$layout = View::addTo($this)->addStyle('max-width:800px;margin:auto;');
19
		\atk4\ui\Header::addTo($layout, [__('User Settings')]);
20
		$segment = View::addTo($layout, ['ui' => 'segment']);
21
		
22
		foreach (UserSettingsJoint::collect() as $joint) {
23
			$segment->add($joint->button());
24
		}
25
	}
26
	
27
	public function edit($jointClass)
28
	{
29
		$joint = new $jointClass();
30
		
31
		$this->location($joint->label());
32
		
33
		$form = $this->add(new Form());
34
		$form->addElements($joint->elements());
0 ignored issues
show
Bug introduced by
The method addElements() does not exist on atk4\ui\AbstractView. It seems like you code against a sub-type of atk4\ui\AbstractView such as Epesi\Core\System\View\Form. ( Ignorable by Annotation )

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

34
		$form->/** @scrutinizer ignore-call */ 
35
         addElements($joint->elements());
Loading history...
35
		$form->confirmLeave();
0 ignored issues
show
Bug introduced by
The method confirmLeave() does not exist on atk4\ui\AbstractView. It seems like you code against a sub-type of atk4\ui\AbstractView such as Epesi\Core\System\View\Form. ( Ignorable by Annotation )

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

35
		$form->/** @scrutinizer ignore-call */ 
36
         confirmLeave();
Loading history...
36
		$form->model->setMulti(UserSetting::getGroup($joint->group()));
37
38
		$form->validate(function(Form $form) use ($joint) {
0 ignored issues
show
Bug introduced by
The method validate() does not exist on atk4\ui\AbstractView. It seems like you code against a sub-type of atk4\ui\AbstractView such as atk4\ui\Form\Control\Multiline or Epesi\Core\System\View\Form. ( Ignorable by Annotation )

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

38
		$form->/** @scrutinizer ignore-call */ 
39
         validate(function(Form $form) use ($joint) {
Loading history...
39
			UserSetting::putGroup($joint->group(), $form->model->get());
40
			
41
			return $form->notify(__('Settings saved!'));
42
		});
43
		
44
		ActionBar::addItemButton('back');
45
			
46
		ActionBar::addItemButton('save')->on('click', $form->submit());
0 ignored issues
show
Bug introduced by
The method submit() does not exist on atk4\ui\AbstractView. It seems like you code against a sub-type of atk4\ui\AbstractView such as Epesi\Core\System\View\Form. ( Ignorable by Annotation )

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

46
		ActionBar::addItemButton('save')->on('click', $form->/** @scrutinizer ignore-call */ submit());
Loading history...
47
	}
48
}
49