Completed
Push — master ( 1c7fde...850e60 )
by Nazar
04:11
created

admin::admin___save_settings()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
/**
3
 * @package   Blogs
4
 * @category  modules
5
 * @author    Nazar Mokrynskyi <[email protected]>
6
 * @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi
7
 * @license   MIT License, see license.txt
8
 */
9
namespace cs\modules\Blogs\api\Controller;
10
use
11
	cs\Config,
12
	cs\ExitException;
13
14
trait admin {
15
	static function admin___get_settings () {
16
		$module_data = Config::instance()->module('Blogs');
17
		return [
18
			'posts_per_page'                => $module_data->posts_per_page,
19
			'max_sections'                  => $module_data->max_sections,
20
			'enable_comments'               => $module_data->enable_comments,
21
			'new_posts_only_from_admins'    => $module_data->new_posts_only_from_admins,
22
			'allow_iframes_without_content' => $module_data->allow_iframes_without_content
23
		];
24
	}
25
	/**
26
	 * @param \cs\Request $Request
27
	 *
28
	 * @throws ExitException
29
	 */
30
	static function admin___save_settings ($Request) {
31
		$data = $Request->data('posts_per_page', 'max_sections', 'enable_comments', 'new_posts_only_from_admins', 'allow_iframes_without_content');
32
		if (!$data) {
33
			throw new ExitException(400);
34
		}
35
		if (!Config::instance()->module('Blogs')->set($data)) {
36
			throw new ExitException(500);
37
		}
38
	}
39
}
40