|
1
|
|
|
<?php namespace XoopsModules\Extcal; |
|
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
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
14
|
|
|
* @license {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
|
15
|
|
|
* @package extcal |
|
16
|
|
|
* @since |
|
17
|
|
|
* @author XOOPS Development Team, |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
use XoopsModules\Extcal; |
|
21
|
|
|
|
|
22
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
// // require_once __DIR__ . '/ExtcalPersistableObjectHandler.php'; |
|
|
|
|
|
|
25
|
|
|
//require_once __DIR__ . '/perm.php'; |
|
26
|
|
|
//require_once __DIR__ . '/time.php'; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class CategoryHandler. |
|
31
|
|
|
*/ |
|
32
|
|
|
class CategoryHandler extends ExtcalPersistableObjectHandler |
|
33
|
|
|
{ |
|
34
|
|
|
public $_extcalPerm; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param $db |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(\XoopsDatabase $db) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->_extcalPerm = Extcal\Perm::getHandler(); |
|
42
|
|
|
// parent::__construct($db, 'extcal_cat', _EXTCAL_CLN_CAT, 'cat_id'); |
|
|
|
|
|
|
43
|
|
|
parent::__construct($db, 'extcal_cat', Category::class, 'cat_id'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param $data |
|
48
|
|
|
* |
|
49
|
|
|
* @return bool |
|
50
|
|
|
*/ |
|
51
|
|
|
public function createCat($data) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$cat = $this->create(); |
|
54
|
|
|
$cat->setVars($data); |
|
55
|
|
|
$this->insert($cat); |
|
56
|
|
|
|
|
57
|
|
|
$catId = $this->getInsertId(); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
// Retriving permission mask |
|
60
|
|
|
/** @var XoopsGroupPermHandler $groupPermissionHandler */ |
|
61
|
|
|
$groupPermissionHandler = xoops_getHandler('groupperm'); |
|
62
|
|
|
$moduleId = $GLOBALS['xoopsModule']->getVar('mid'); |
|
63
|
|
|
|
|
64
|
|
|
$criteria = new \CriteriaCompo(); |
|
65
|
|
|
$criteria->add( new \Criteria('gperm_name', 'extcal_perm_mask')); |
|
66
|
|
|
$criteria->add( new \Criteria('gperm_modid', $moduleId)); |
|
67
|
|
|
$permMask = $groupPermissionHandler->getObjects($criteria); |
|
68
|
|
|
|
|
69
|
|
|
// Retriving group list |
|
70
|
|
|
$memberHandler = xoops_getHandler('member'); |
|
71
|
|
|
$glist = $memberHandler->getGroupList(); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
// Applying permission mask |
|
74
|
|
|
foreach ($permMask as $perm) { |
|
75
|
|
View Code Duplication |
if (1 == $perm->getVar('gperm_itemid')) { |
|
|
|
|
|
|
76
|
|
|
$groupPermissionHandler->addRight('extcal_cat_view', $cat->getVar('cat_id'), $perm->getVar('gperm_groupid'), $moduleId); |
|
77
|
|
|
} |
|
78
|
|
View Code Duplication |
if (2 == $perm->getVar('gperm_itemid')) { |
|
|
|
|
|
|
79
|
|
|
$groupPermissionHandler->addRight('extcal_cat_submit', $cat->getVar('cat_id'), $perm->getVar('gperm_groupid'), $moduleId); |
|
80
|
|
|
} |
|
81
|
|
View Code Duplication |
if (4 == $perm->getVar('gperm_itemid')) { |
|
|
|
|
|
|
82
|
|
|
$groupPermissionHandler->addRight('extcal_cat_autoapprove', $cat->getVar('cat_id'), $perm->getVar('gperm_groupid'), $moduleId); |
|
83
|
|
|
} |
|
84
|
|
View Code Duplication |
if (8 == $perm->getVar('gperm_itemid')) { |
|
|
|
|
|
|
85
|
|
|
$groupPermissionHandler->addRight('extcal_cat_edit', $cat->getVar('cat_id'), $perm->getVar('gperm_groupid'), $moduleId); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return true; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param $catId |
|
94
|
|
|
* @param $data |
|
95
|
|
|
* |
|
96
|
|
|
* @return bool |
|
97
|
|
|
*/ |
|
98
|
|
|
public function modifyCat($catId, $data) |
|
99
|
|
|
{ |
|
100
|
|
|
$cat = $this->get($catId); |
|
101
|
|
|
$cat->setVars($data); |
|
102
|
|
|
|
|
103
|
|
|
return $this->insert($cat); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param $catId |
|
108
|
|
|
*/ |
|
109
|
|
|
public function deleteCat($catId) |
|
110
|
|
|
{ |
|
111
|
|
|
/* TODO : |
|
112
|
|
|
- Delete all events in this category |
|
113
|
|
|
*/ |
|
114
|
|
|
$this->deleteById($catId); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
// Return one cat selected by his id |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param $catId |
|
121
|
|
|
* @param bool $skipPerm |
|
122
|
|
|
* |
|
123
|
|
|
* @return bool |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getCat($catId, $skipPerm = false) |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
$criteriaCompo = new \CriteriaCompo(); |
|
128
|
|
|
$criteriaCompo->add( new \Criteria('cat_id', $catId)); |
|
129
|
|
|
if (!$skipPerm) { |
|
130
|
|
|
$this->_addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']); |
|
131
|
|
|
} |
|
132
|
|
|
$ret = $this->getObjects($criteriaCompo); |
|
133
|
|
|
if (isset($ret[0])) { |
|
134
|
|
|
return $ret[0]; |
|
135
|
|
|
} else { |
|
136
|
|
|
return false; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param $user |
|
142
|
|
|
* @param string $perm |
|
143
|
|
|
* |
|
144
|
|
|
* @return array |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getAllCat($user, $perm = 'extcal_cat_view') |
|
147
|
|
|
{ |
|
148
|
|
|
$criteriaCompo = new \CriteriaCompo(); |
|
149
|
|
|
if ('all' !== $perm) { |
|
150
|
|
|
$this->_addCatPermCriteria($criteriaCompo, $user, $perm); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
return $this->getObjects($criteriaCompo); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param $user |
|
158
|
|
|
* @param string $perm |
|
159
|
|
|
* |
|
160
|
|
|
* @return array |
|
161
|
|
|
*/ |
|
162
|
|
|
public function getAllCatById($user, $perm = 'all') |
|
163
|
|
|
{ |
|
164
|
|
|
$criteriaCompo = new \CriteriaCompo(); |
|
165
|
|
|
if ('all' !== $perm) { |
|
166
|
|
|
$this->_addCatPermCriteria($criteriaCompo, $user, $perm); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
$t = $this->objectToArray($this->getObjects($criteriaCompo)); |
|
170
|
|
|
$r = []; |
|
171
|
|
|
// while (list($k, $v) = each($t)) { |
|
|
|
|
|
|
172
|
|
|
foreach ($t as $k => $v) { |
|
173
|
|
|
$r[$v['cat_id']] = $v; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
return $r; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @param \CriteriaElement $criteria |
|
181
|
|
|
* @param $user |
|
182
|
|
|
* @param string $perm |
|
183
|
|
|
*/ |
|
184
|
|
View Code Duplication |
public function _addCatPermCriteria(\CriteriaElement $criteria, $user, $perm = 'extcal_cat_view') |
|
|
|
|
|
|
185
|
|
|
{ |
|
186
|
|
|
$authorizedAccessCats = $this->_extcalPerm->getAuthorizedCat($user, 'extcal_cat_view'); |
|
187
|
|
|
$count = count($authorizedAccessCats); |
|
188
|
|
|
if ($count > 0) { |
|
189
|
|
|
$in = '(' . $authorizedAccessCats[0]; |
|
190
|
|
|
array_shift($authorizedAccessCats); |
|
191
|
|
|
foreach ($authorizedAccessCats as $authorizedAccessCat) { |
|
192
|
|
|
$in .= ',' . $authorizedAccessCat; |
|
193
|
|
|
} |
|
194
|
|
|
$in .= ')'; |
|
195
|
|
|
$criteria->add( new \Criteria('cat_id', $in, 'IN')); |
|
196
|
|
|
} else { |
|
197
|
|
|
$criteria->add( new \Criteria('cat_id', '(0)', 'IN')); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* @param XoopsUser|string $xoopsUser |
|
203
|
|
|
* |
|
204
|
|
|
* @return bool |
|
205
|
|
|
*/ |
|
206
|
|
|
public function haveSubmitRight(&$xoopsUser) |
|
207
|
|
|
{ |
|
208
|
|
|
return count($this->_extcalPerm->getAuthorizedCat($xoopsUser, 'extcal_cat_submit')) > 0; |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.