1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
You may not change or alter any portion of this comment or credits |
5
|
|
|
of supporting developers from this source code or any supporting source code |
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Module: Equipment |
15
|
|
|
* |
16
|
|
|
* @category Module |
17
|
|
|
* @package equipment |
18
|
|
|
* @author XOOPS Development Team <[email protected]> - <http://xoops.org> |
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
20
|
|
|
* @license GPL 2.0 or later |
21
|
|
|
* @link https://xoops.org/ |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
use Xmf\Module\Helper\Permission; |
26
|
|
|
|
27
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
28
|
|
|
|
29
|
|
|
$permHelper = new Permission($moduleDirName); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class EquipmentEquipment |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
class EquipmentEquipment extends XoopsObject |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Constructor |
38
|
|
|
* |
39
|
|
|
* @param null |
40
|
|
|
*/ |
41
|
|
|
public function __construct() |
42
|
|
|
{ |
43
|
|
|
parent::__construct(); |
44
|
|
|
$this->initVar('id', XOBJ_DTYPE_INT); |
45
|
|
|
$this->initVar('owner', XOBJ_DTYPE_TXTBOX); |
46
|
|
|
$this->initVar('name', XOBJ_DTYPE_TXTBOX); |
47
|
|
|
$this->initVar('amount', XOBJ_DTYPE_INT); |
48
|
|
|
$this->initVar('total', XOBJ_DTYPE_INT); |
49
|
|
|
$this->initVar('image', XOBJ_DTYPE_TXTBOX); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get form |
54
|
|
|
* |
55
|
|
|
* @param null |
56
|
|
|
* @return EquipmentEquipmentForm |
57
|
|
|
*/ |
58
|
|
|
public function getForm() |
59
|
|
|
{ |
60
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/equipment/class/form/equipment.php'; |
61
|
|
|
|
62
|
|
|
$form = new EquipmentEquipmentForm($this); |
63
|
|
|
return $form; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return array|null |
68
|
|
|
*/ |
69
|
|
|
public function getGroupsRead() |
70
|
|
|
{ |
71
|
|
|
global $permHelper; |
72
|
|
|
//return $this->publisher->getHandler('permission')->getGrantedGroupsById('equipment_read', id); |
|
|
|
|
73
|
|
|
return $permHelper->getGroupsForItem('sbcolumns_read', $this->getVar('id')); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return array|null |
78
|
|
|
*/ |
79
|
|
|
public function getGroupsSubmit() |
80
|
|
|
{ |
81
|
|
|
global $permHelper; |
82
|
|
|
// return $this->publisher->getHandler('permission')->getGrantedGroupsById('equipment_submit', id); |
|
|
|
|
83
|
|
|
return $permHelper->getGroupsForItem('sbcolumns_submit', $this->getVar('id')); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return array|null |
88
|
|
|
*/ |
89
|
|
|
public function getGroupsModeration() |
90
|
|
|
{ |
91
|
|
|
global $permHelper; |
92
|
|
|
// return $this->publisher->getHandler('permission')->getGrantedGroupsById('equipment_moderation', id); |
|
|
|
|
93
|
|
|
return $permHelper->getGroupsForItem('sbcolumns_moderation', $this->getVar('id')); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Class EquipmentEquipmentHandler |
99
|
|
|
*/ |
100
|
|
|
class EquipmentEquipmentHandler extends XoopsPersistableObjectHandler |
101
|
|
|
{ |
102
|
|
|
/** |
103
|
|
|
* Constructor |
104
|
|
|
* @param null|XoopsDatabase $db |
105
|
|
|
*/ |
106
|
|
|
|
107
|
|
|
public function __construct(XoopsDatabase $db) |
108
|
|
|
{ |
109
|
|
|
parent::__construct($db, 'equipment_equipment', 'EquipmentEquipment', 'id', 'name'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
|
|
public function getDataJson() |
116
|
|
|
{ |
117
|
|
|
global $xoopsDB; |
118
|
|
|
$sql = sprintf('SELECT `name`, `owner`, `amount`, `id`, `image` FROM `%s`', $xoopsDB->prefix('equipment_equipment')); |
119
|
|
|
|
120
|
|
|
$json_data = EquipmentUtility::getQueryDataToJSON($sql); |
121
|
|
|
|
122
|
|
|
return $json_data; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
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.