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 EquipmentRentals |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
class EquipmentRentals 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('customerid', XOBJ_DTYPE_INT); |
46
|
|
|
$this->initVar('equipmentid', XOBJ_DTYPE_INT); |
47
|
|
|
$this->initVar('quantity', XOBJ_DTYPE_INT); |
48
|
|
|
$this->initVar('datefrom', XOBJ_DTYPE_TIMESTAMP); |
49
|
|
|
$this->initVar('dateto', XOBJ_DTYPE_TIMESTAMP); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get form |
54
|
|
|
* |
55
|
|
|
* @param null |
56
|
|
|
* @return EquipmentRentalsForm |
57
|
|
|
*/ |
58
|
|
|
public function getForm() |
59
|
|
|
{ |
60
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/equipment/class/form/rentals.php'; |
61
|
|
|
|
62
|
|
|
$form = new EquipmentRentalsForm($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('rentals_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('rentals_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('rentals_moderation', id); |
|
|
|
|
93
|
|
|
return $permHelper->getGroupsForItem('sbcolumns_moderation', $this->getVar('id')); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Class EquipmentRentalsHandler |
99
|
|
|
*/ |
100
|
|
|
class EquipmentRentalsHandler 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_rentals', 'EquipmentRentals', 'id', 'customerid'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
|
|
public function getDataJson() |
116
|
|
|
{ |
117
|
|
|
global $xoopsDB, $xoopsUser; |
118
|
|
|
|
119
|
|
|
// $borrow_sql = sprintf('SELECT `%1$s`.`amount`, `name`, `owner` |
|
|
|
|
120
|
|
|
// FROM `%1$s` |
121
|
|
|
// INNER JOIN `%2$s` ON `%1$s`.`id`=`%2$s`.`id` WHERE `%1$s`.`borrower`="%3$s"', $xoopsDB->prefix('equipment_rentals'), $xoopsDB->prefix('equipment_equipment'), $xoopsUser->uname()); |
122
|
|
|
|
123
|
|
|
$borrow_sql = 'SELECT r.quantity, e.name, c.first, c.last FROM ' . $xoopsDB->prefix('equipment_equipment') . ' AS e, ' . $xoopsDB->prefix('equipment_customer') . ' AS c, ' |
124
|
|
|
. $xoopsDB->prefix('equipment_rentals') . ' AS r WHERE e.id = r.equipmentid AND c.id = r.customerid'; |
125
|
|
|
|
126
|
|
|
$borrow_data = EquipmentUtility::getQueryDataToJSON($borrow_sql); |
127
|
|
|
|
128
|
|
|
return $borrow_data; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
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.