Permissionshandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 1
f 1
1
<?php
2
3
namespace XoopsModules\Mymodule3;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * My Module 3 module for xoops
17
 *
18
 * @copyright     2020 XOOPS Project (https://xooops.org)
19
 * @license        GPL 2.0 or later
20
 * @package        mymodule3
21
 * @since          1.0
22
 * @min_xoops      2.5.9
23
 * @author         TDM XOOPS - Email:<[email protected]> - Website:<http://xoops.org>
24
 */
25
26
use XoopsModules\Mymodule3;
27
28
defined('XOOPS_ROOT_PATH') || die('Restricted access');
29
30
/**
31
 * Class Object Permissionshandler
32
 */
33
class Permissionshandler extends \XoopsPersistableObjectHandler
34
{
35
	/**
36
	 * Constructor 
37
	 *
38
	 * @param null
39
	 */
40
	public function __construct()
41
	{
42
	}
43
44
	/**
45
	 * @public function permGlobalApprove
46
	 * returns right for global approve
47
	 *
48
	 * @param null
49
	 * @return bool
50
	 */
51
	public function getPermGlobalApprove()
52
	{
53
		global $xoopsUser, $xoopsModule;
54
		$currentuid = 0;
55
		if (isset($xoopsUser) && is_object($xoopsUser)) {
56
			if ($xoopsUser->isAdmin($xoopsModule->mid())) {
57
				return true;
58
			}
59
			$currentuid = $xoopsUser->uid();
60
		}
61
		$grouppermHandler = xoops_getHandler('groupperm');
62
		$mid = $xoopsModule->mid();
63
		$memberHandler = xoops_getHandler('member');
64
		if (0 == $currentuid) {
65
			$my_group_ids = [XOOPS_GROUP_ANONYMOUS];
66
		} else {
67
			$my_group_ids = $memberHandler->getGroupsByUser($currentuid);;
0 ignored issues
show
Bug introduced by
The method getGroupsByUser() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsMembershipHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
			/** @scrutinizer ignore-call */ 
68
   $my_group_ids = $memberHandler->getGroupsByUser($currentuid);;
Loading history...
68
		}
69
		if ($grouppermHandler->checkRight('mymodule3_ac', 4, $my_group_ids, $mid)) {
0 ignored issues
show
Bug introduced by
The method checkRight() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
		if ($grouppermHandler->/** @scrutinizer ignore-call */ checkRight('mymodule3_ac', 4, $my_group_ids, $mid)) {
Loading history...
70
			return true;
71
		}
72
		return false;
73
	}
74
75
	/**
76
	 * @public function permGlobalSubmit
77
	 * returns right for global submit
78
	 *
79
	 * @param null
80
	 * @return bool
81
	 */
82
	public function getPermGlobalSubmit()
83
	{
84
		global $xoopsUser, $xoopsModule;
85
		$currentuid = 0;
86
		if (isset($xoopsUser) && is_object($xoopsUser)) {
87
			if ($xoopsUser->isAdmin($xoopsModule->mid())) {
88
				return true;
89
			}
90
			$currentuid = $xoopsUser->uid();
91
		}
92
		$grouppermHandler = xoops_getHandler('groupperm');
93
		$mid = $xoopsModule->mid();
94
		$memberHandler = xoops_getHandler('member');
95
		if (0 == $currentuid) {
96
			$my_group_ids = [XOOPS_GROUP_ANONYMOUS];
97
		} else {
98
			$my_group_ids = $memberHandler->getGroupsByUser($currentuid);;
99
		}
100
		if ($this->getGlobalApprove()) {
0 ignored issues
show
Bug introduced by
The method getGlobalApprove() does not exist on XoopsModules\Mymodule3\Permissionshandler. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

100
		if ($this->/** @scrutinizer ignore-call */ getGlobalApprove()) {
Loading history...
101
			return true;
102
		}
103
		if ($grouppermHandler->checkRight('mymodule3_ac', 8, $my_group_ids, $mid)) {
104
			return true;
105
		}
106
		return false;
107
	}
108
109
	/**
110
	 * @public function permGlobalView
111
	 * returns right for global view
112
	 *
113
	 * @param null
114
	 * @return bool
115
	 */
116
	public function getPermGlobalView()
117
	{
118
		global $xoopsUser, $xoopsModule;
119
		$currentuid = 0;
120
		if (isset($xoopsUser) && is_object($xoopsUser)) {
121
			if ($xoopsUser->isAdmin($xoopsModule->mid())) {
122
				return true;
123
			}
124
			$currentuid = $xoopsUser->uid();
125
		}
126
		$grouppermHandler = xoops_getHandler('groupperm');
127
		$mid = $xoopsModule->mid();
128
		$memberHandler = xoops_getHandler('member');
129
		if (0 == $currentuid) {
130
			$my_group_ids = [XOOPS_GROUP_ANONYMOUS];
131
		} else {
132
			$my_group_ids = $memberHandler->getGroupsByUser($currentuid);;
133
		}
134
		if ($this->getGlobalApprove()) {
135
			return true;
136
		}
137
		if ($this->getGlobalSubmit()) {
0 ignored issues
show
Bug introduced by
The method getGlobalSubmit() does not exist on XoopsModules\Mymodule3\Permissionshandler. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

137
		if ($this->/** @scrutinizer ignore-call */ getGlobalSubmit()) {
Loading history...
138
			return true;
139
		}
140
		if ($grouppermHandler->checkRight('mymodule3_ac', 16, $my_group_ids, $mid)) {
141
			return true;
142
		}
143
		return false;
144
	}
145
}
146