Completed
Push — master ( 416cb1...222de5 )
by Anton
03:44
created

Informer::countEntries()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.2
cc 4
eloc 4
nc 3
nop 2
1
<?php
2
3
namespace Modules {
4
5
	use DB, Explorer;
6
7
	abstract class Informer {
8
9
		# Count table entries
10
11
		private static function countEntries(string $table_name, bool $false_on_error = false) {
12
13
			if (!(DB::select($table_name, 'COUNT(id) as count') && (DB::last()->rows === 1))) {
14
15
				return (!$false_on_error ? 0 : false);
16
			}
17
18
			# ------------------------
19
20
			return intval(DB::last()->row()['count']);
21
		}
22
23
		# Check if install file exists
24
25
		public static function checkInstallFile() {
26
27
			return Explorer::isFile(DIR_WWW . 'install.php');
28
		}
29
30
		# Check if debug mode forced
31
32
		public static function isDebugMode() {
33
34
			return Explorer::isFile(DIR_SYSTEM_DATA . '.debug');
35
		}
36
37
		# Check if demo mode forced
38
39
		public static function isDemoMode() {
40
41
			return Explorer::isFile(DIR_SYSTEM_DATA . '.demo');
42
		}
43
44
		# Get MySQL version
45
46
		public static function mysqlVersion() {
47
48
			if (!(DB::send("SELECT VERSION() as version") && DB::last()->status)) return false;
49
50
			return strval(DB::last()->row()['version']);
51
		}
52
53
		# Get pages count
54
55
		public static function countPages(bool $false_on_error = false) {
56
57
			return self::countEntries(TABLE_PAGES, $false_on_error);
58
		}
59
60
		# Get users count
61
62
		public static function countUsers(bool $false_on_error = false) {
63
64
			return self::countEntries(TABLE_USERS, $false_on_error);
65
		}
66
	}
67
}
68