Passed
Push — master ( 992e52...dc2c5c )
by Georgi
03:52
created

SettingsView::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 20
rs 9.9
1
<?php
2
3
namespace Epesi\Core\System\User\Settings;
4
5
use Epesi\Core\System\Integration\Modules\ModuleView;
6
use Epesi\Core\System\User\Settings\Integration\Joints\UserSettingsJoint;
7
use Epesi\Core\System\Seeds\Form;
8
use Epesi\Core\Layout\Seeds\ActionBar;
9
use Epesi\Core\System\User\Settings\Database\Models\UserSetting;
10
11
class SettingsView extends ModuleView
12
{
13
	protected $label = 'User Settings';
14
	
15
	public function body()
16
	{
17
		$layout = $this->add(['View'])->addStyle('max-width:800px;margin:auto;');
18
		$layout->add(['Header', __('User Settings')]);
19
		$segment = $layout->add(['View', ['ui' => 'segment']]);
20
		
21
		foreach (UserSettingsJoint::collect() as $joint) {
22
			$segment->add($joint->button());
23
		}
24
	}
25
	
26
	public function edit($jointClass)
27
	{
28
		$joint = new $jointClass();
29
		
30
		$this->location($joint->label());
31
		
32
		$form = $this->add(new Form())
33
			->addElements($joint->elements())
34
			->confirmLeave()
35
			->setValues(UserSetting::getGroup($joint->group()));
36
37
		$form->validate(function(Form $form) use ($joint) {
38
			UserSetting::putGroup($joint->group(), $form->getValues());
39
			
40
			return $form->notify(__('Settings saved!'));
41
		});
42
		
43
		ActionBar::addButton('back');
44
			
45
		ActionBar::addButton('save')->on('click', $form->submit());
46
	}
47
}
48