Completed
Push — master ( ab09db...eef690 )
by Nazar
04:19
created

Controller::index()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 18
rs 9.2
cc 4
eloc 14
nc 4
nop 0
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\admin;
10
use
11
	h,
12
	cs\Config,
13
	cs\Language,
14
	cs\Page,
15
	cs\modules\Blogs\Posts,
16
	cs\modules\Blogs\Sections;
17
use function
18
	cs\modules\Blogs\get_posts_rows;
19
20
class Controller {
21
	static function index () {
22
		if (!isset($_POST['mode'])) {
23
			return;
24
		}
25
		$L        = Language::prefix('blogs_');
26
		$Page     = Page::instance();
27
		$Posts    = Posts::instance();
28
		$Sections = Sections::instance();
0 ignored issues
show
Unused Code introduced by
$Sections is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
29
		switch ($_POST['mode']) {
30
			case 'delete_post':
31
				if ($Posts->del($_POST['id'])) {
32
					$Page->success($L->changes_saved);
33
				} else {
34
					$Page->warning($L->changes_save_error);
35
				}
36
				break;
37
		}
38
	}
39
	static function general () {
40
		$L = Language::prefix('blogs_');
41
		Page::instance()
42
			->title($L->general)
43
			->content(
44
				h::cs_blogs_admin_general()
45
			);
46
	}
47
	static function browse_sections () {
48
		$L = Language::prefix('blogs_');
49
		Page::instance()
50
			->title($L->browse_sections)
51
			->content(
52
				h::cs_blogs_admin_sections_list()
53
			);
54
	}
55
	/**
56
	 * @param \cs\Request $Request
57
	 */
58
	static function browse_posts ($Request) {
59
		$Config = Config::instance();
60
		$L      = Language::prefix('blogs_');
61
		$page   = isset($Request->route[1]) ? (int)$Request->route[1] : 1;
62
		$page   = $page > 0 ? $page : 1;
63
		$total  = Posts::instance()->get_total_count();
64
		Page::instance()
65
			->title($L->browse_posts)
66
			->content(
67
				h::{'table.cs-table[center][list]'}(
68
					h::{'tr th'}(
69
						[
70
							$L->post_title,
71
							[
72
								'style' => 'width: 30%'
73
							]
74
						],
75
						[
76
							$L->post_sections,
77
							[
78
								'style' => 'width: 25%'
79
							]
80
						],
81
						[
82
							$L->post_tags,
83
							[
84
								'style' => 'width: 20%'
85
							]
86
						],
87
						[
88
							$L->author_date,
89
							[
90
								'style' => 'width: 15%'
91
							]
92
						],
93
						$L->action
94
					).
95
					h::{'tr| td'}(
96
						get_posts_rows($page)
97
					)
98
				).
99
				(
100
				$total ? h::{'.cs-block-margin.cs-text-center.cs-margin nav[is=cs-nav-pagination]'}(
101
					pages(
102
						$page,
103
						ceil($total / $Config->module('Blogs')->posts_per_page),
104
						function ($page) {
105
							return $page == 1 ? 'admin/Blogs/browse_posts' : "admin/Blogs/browse_posts/$page";
106
						}
107
					)
108
				) : ''
109
				)
110
			);
111
	}
112
	/**
113
	 * @param \cs\Request $Request
114
	 */
115
	static function delete_post ($Request) {
116
		$post = Posts::instance()->get($Request->route[1]);
117
		$L    = Language::prefix('blogs_');
118
		Page::instance()
119
			->title($L->deletion_of_post($post['title']))
120
			->content(
121
				h::{'form[is=cs-form][action=admin/Blogs/browse_posts]'}(
122
					h::{'h2.cs-text-center'}(
123
						$L->sure_to_delete_post($post['title'])
124
					).
125
					h::p(
126
						h::{'button[is=cs-button][type=submit][name=mode][value=delete_post]'}($L->yes).
127
						h::{'button[is=cs-button]'}(
128
							$L->cancel,
129
							[
130
								'type'    => 'button',
131
								'onclick' => 'history.go(-1);'
132
							]
133
						)
134
					).
135
					h::{'input[type=hidden][name=id]'}(
136
						[
137
							'value' => $post['id']
138
						]
139
					)
140
				)
141
			);
142
	}
143
	/**
144
	 * @param \cs\Request $Request
145
	 */
146
	static function delete_section ($Request) {
147
		$section = Sections::instance()->get($Request->route[1]);
148
		$L       = Language::prefix('blogs_');
149
		Page::instance()
150
			->title($L->deletion_of_posts_section($section['title']))
151
			->content(
152
				h::{'form[is=cs-form][action=admin/Blogs/browse_sections]'}(
153
					h::{'h2.cs-text-center'}(
154
						$L->sure_to_delete_posts_section($section['title'])
155
					).
156
					h::p(
157
						h::{'button[is=cs-button][type=submit][name=mode][value=delete_section]'}($L->yes).
158
						h::{'button[is=cs-button]'}(
159
							$L->cancel,
160
							[
161
								'type'    => 'button',
162
								'onclick' => 'history.go(-1);'
163
							]
164
						)
165
					).
166
					h::{'input[type=hidden][name=id]'}(
167
						[
168
							'value' => $section['id']
169
						]
170
					)
171
				)
172
			);
173
	}
174
}
175