1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* page module |
14
|
|
|
* |
15
|
|
|
* @copyright XOOPS Project https://xoops.org/ |
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
17
|
|
|
* @package page |
18
|
|
|
* @since 2.6.0 |
19
|
|
|
* @author DuGris (aka Laurent JEN) |
20
|
|
|
* @author John Mordo (jlm69) |
21
|
|
|
* @version $Id$ |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
use Xoops\Core\Kernel\Handlers\XoopsGroupPermHandler; |
25
|
|
|
|
26
|
|
|
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class AlumniGroupPermHandler |
30
|
|
|
*/ |
31
|
|
|
class AlumniGroupPermHandler extends XoopsGroupPermHandler |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Check permission |
35
|
|
|
* |
36
|
|
|
* @param string $gperm_name |
37
|
|
|
* @param int $gperm_itemid |
38
|
|
|
* @param array|int $gperm_groupid |
39
|
|
|
* @param int $gperm_modid |
40
|
|
|
* @param bool $trueifadmin |
41
|
|
|
* |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
|
|
public function checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid = 1, $trueifadmin = true) |
45
|
|
|
{ |
46
|
|
|
return parent::checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid, $trueifadmin); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param $cid |
51
|
|
|
* @param array $groups |
52
|
|
|
*/ |
53
|
|
|
public function updatePerms($cid, $groups = []) |
54
|
|
|
{ |
55
|
|
|
$module_id = Alumni::getInstance()->getModule()->getVar('mid'); |
56
|
|
|
|
57
|
|
|
$groups_exists = parent::getGroupIds('alumni_view', $cid, $module_id); |
58
|
|
|
$groups_exists = array_values($groups_exists); |
59
|
|
|
$groups_delete = array_diff(array_values($groups_exists), $groups); |
60
|
|
|
$groups_add = array_diff($groups, array_values($groups_exists)); |
61
|
|
|
|
62
|
|
|
$groups1_exists = parent::getGroupIds('alumni_submit', $cid, $module_id); |
63
|
|
|
$groups1_exists = array_values($groups1_exists); |
64
|
|
|
$groups1_delete = array_diff(array_values($groups1_exists), $groups); |
65
|
|
|
$groups1_add = array_diff($groups, array_values($groups1_exists)); |
66
|
|
|
|
67
|
|
|
$groups2_exists = parent::getGroupIds('alumni_premium', $cid, $module_id); |
68
|
|
|
$groups2_exists = array_values($groups2_exists); |
69
|
|
|
$groups2_delete = array_diff(array_values($groups2_exists), $groups); |
70
|
|
|
$groups2_add = array_diff($groups, array_values($groups2_exists)); |
71
|
|
|
|
72
|
|
|
// delete alumni_view |
73
|
|
View Code Duplication |
if (0 != count($groups_delete)) { |
|
|
|
|
74
|
|
|
$criteria = $criteria = new CriteriaCompo(); |
75
|
|
|
$criteria->add(new Criteria('gperm_itemid', $cid)); |
76
|
|
|
$criteria->add(new Criteria('gperm_modid', $module_id)); |
77
|
|
|
$criteria->add(new Criteria('gperm_name', 'alumni_view', '=')); |
78
|
|
|
$criteria->add(new Criteria('gperm_groupid', '(' . implode(', ', $groups_delete) . ')', 'IN')); |
79
|
|
|
if (parent::deleteAll($criteria)) { |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// delete alumni_view |
84
|
|
View Code Duplication |
if (0 != count($groups1_delete)) { |
|
|
|
|
85
|
|
|
$criteria = $criteria = new CriteriaCompo(); |
86
|
|
|
$criteria->add(new Criteria('gperm_itemid', $cid)); |
87
|
|
|
$criteria->add(new Criteria('gperm_modid', $module_id)); |
88
|
|
|
$criteria->add(new Criteria('gperm_name', 'alumni_submit', '=')); |
89
|
|
|
$criteria->add(new Criteria('gperm_groupid', '(' . implode(', ', $groups1_delete) . ')', 'IN')); |
90
|
|
|
if (parent::deleteAll($criteria)) { |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// delete alumni_view |
95
|
|
View Code Duplication |
if (0 != count($groups2_delete)) { |
|
|
|
|
96
|
|
|
$criteria = $criteria = new CriteriaCompo(); |
97
|
|
|
$criteria->add(new Criteria('gperm_itemid', $cid)); |
98
|
|
|
$criteria->add(new Criteria('gperm_modid', $module_id)); |
99
|
|
|
$criteria->add(new Criteria('gperm_name', 'alumni_premium', '=')); |
100
|
|
|
$criteria->add(new Criteria('gperm_groupid', '(' . implode(', ', $groups2_delete) . ')', 'IN')); |
101
|
|
|
if (parent::deleteAll($criteria)) { |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
// Add alumni_view |
106
|
|
|
if (0 != count($groups_add)) { |
107
|
|
|
foreach ($groups_add as $group_id) { |
108
|
|
|
parent::addRight('alumni_view', $cid, $group_id, $module_id); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
// Add alumni_submit |
113
|
|
|
if (0 != count($groups1_add)) { |
114
|
|
|
foreach ($groups1_add as $group_id) { |
115
|
|
|
parent::addRight('alumni_submit', $cid, $group_id, $module_id); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
// Add alumni_submit |
120
|
|
|
if (0 != count($groups2_add)) { |
121
|
|
|
foreach ($groups2_add as $group_id) { |
122
|
|
|
parent::addRight('alumni_premium', $cid, $group_id, $module_id); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.