Completed
Push — master ( 3f8863...cecec9 )
by Justin
08:13 queued 05:15
created

PageListPage::listRequiredPermissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
/**
4
 * Copyright (c) 2018 Justin Kuenzel (jukusoft.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
20
/**
21
 * Project: RocketCMS
22
 * License: Apache 2.0 license
23
 * User: Justin
24
 * Date: 31.08.2018
25
 * Time: 22:40
26
 */
27
28
class PageListPage extends PageType {
29
30
	public function getContent(): string {
31
		$template = new DwooTemplate("pages/pagelist");
32
33
		$template->assign("no_edit_permissions", (boolean) (!PermissionChecker::current()->hasRight("an_edit_all_pages") && !PermissionChecker::current()->hasRight("can_edit_own_pages")));
34
35
		//set table columns
36
		$template->assign("columns", array(
37
			Translator::translate("ID"),
38
			Translator::translate("Alias"),
39
			Translator::translate("Title"),
40
			Translator::translate("Author"),
41
			Translator::translate("State"),
42
			Translator::translate("Actions")
43
		));
44
45
		$current_userID = User::current()->getID();
46
		$permission_can_edit_all_pages = PermissionChecker::current()->hasRight("can_edit_all_pages");
47
		$permission_can_edit_own_pages = PermissionChecker::current()->hasRight("can_edit_own_pages");
48
49
		$pages = array();
50
51
		//get all pages from database
52
		$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}pages` LEFT JOIN `{praefix}user` ON (`{praefix}pages`.`author` = `{praefix}user`.`userID`) WHERE `{praefix}pages`.`editable` = '1'; ");
53
54
		foreach ($rows as $row) {
55
			$is_author_online = $row['online'] == 1;
56
			$is_own_page = $row['author'] == $current_userID;
57
			$editable = $permission_can_edit_all_pages || ($permission_can_edit_own_pages && $is_own_page);
58
59
			$pages[] = array(
60
				'id' => $row['id'],
61
				'alias' => $row['alias'],
62
				'title' => Translator::translateTitle($row['title']),
63
				'author' => $row['username'],
64
				'state' => ($row['published'] == 1 ? "Published" : "Draft"),
65
				'actions' => "&nbsp;",
66
				'user_online' => (boolean) $is_author_online,
67
				'url' => DomainUtils::generateURL($row['alias']),
68
				'own_page' => (boolean) $is_own_page,
69
				'editable' => (boolean) $editable,
70
				'published' => $row['published'] == 1
71
			);
72
		}
73
74
		$template->assign("pagelist", $pages);
75
76
		return $template->getCode();
77
	}
78
79
	public function getFooterScripts(): string {
80
		return "<script>
81
		  $(function () {
82
			$('#pagetable').DataTable({
83
			  'paging'      : true,
84
			  'lengthChange': false,
85
			  'searching'   : true,
86
			  'ordering'    : true,
87
			  'info'        : true,
88
			  'autoWidth'   : false
89
			});
90
		  });
91
		</script>";
92
	}
93
94
	public function listRequiredPermissions(): array {
95
		return array("can_see_all_pages", "can_edit_all_pages");
96
	}
97
98
}
99
100
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
101