Completed
Push — master ( 7e4a95...8da695 )
by Nazar
04:15
created

Controller::admin_pages_delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package   Static Pages
4
 * @category  modules
5
 * @author    Nazar Mokrynskyi <[email protected]>
6
 * @copyright Copyright (c) 2016, Nazar Mokrynskyi
7
 * @license   MIT License, see license.txt
8
 */
9
namespace cs\modules\Static_pages\api;
10
use
11
	cs\ExitException,
12
	cs\modules\Static_pages\Pages,
13
	cs\modules\Static_pages\Categories;
14
15
class Controller {
16
	/**
17
	 * @param \cs\Request $Request
18
	 *
19
	 * @return array
20
	 *
21
	 * @throws ExitException
22
	 */
23
	public static function admin_categories___get ($Request) {
24
		$id         = $Request->route_ids(0);
25
		$Categories = Categories::instance();
26
		if ($id) {
27
			$data = $Categories->get($id);
28
			if (!$data) {
29
				throw new ExitException(404);
30
			}
31
			return $data;
32
		}
33
		return $Categories->get_all();
34
	}
35
	/**
36
	 * @param \cs\Request $Request
37
	 *
38
	 * @throws ExitException
39
	 */
40
	public static function admin_categories___delete ($Request) {
41
		if (!Categories::instance()->del($Request->route_ids(0))) {
42
			throw new ExitException(500);
43
		}
44
	}
45
	/**
46
	 * @param \cs\Request $Request
47
	 *
48
	 * @return array
49
	 *
50
	 * @throws ExitException
51
	 */
52
	public static function admin_categories_pages_get ($Request) {
53
		$category = $Request->route_ids(0);
54
		if ($category === null) {
55
			throw new ExitException(400);
56
		}
57
		$Pages = Pages::instance();
58
		return $Pages->get($Pages->get_for_category($category));
59
	}
60
	/**
61
	 * @param \cs\Request $Request
62
	 *
63
	 * @throws ExitException
64
	 */
65
	public static function admin_pages_delete ($Request) {
66
		if (!Pages::instance()->del($Request->route_ids(0))) {
67
			throw new ExitException(500);
68
		}
69
	}
70
}
71