1 | <?php |
||
2 | /* |
||
3 | // ID: class.offer.php 30-apr-2007 13:39:01 efqconsultancy |
||
4 | // ------------------------------------------------------------------------ // |
||
5 | // EFQ Directory // |
||
6 | // Copyright (c) 2006 EFQ Consultancy // |
||
7 | // <http://www.efqdirectory.com/> // |
||
8 | // ------------------------------------------------------------------------ // |
||
9 | // This program is free software; you can redistribute it and/or modify // |
||
10 | // it under the terms of the GNU General Public License as published by // |
||
11 | // the Free Software Foundation; either version 2 of the License, or // |
||
12 | // (at your option) any later version. // |
||
13 | // // |
||
14 | // You may not change or alter any portion of this comment or credits // |
||
15 | // of supporting developers from this source code or any supporting // |
||
16 | // source code which is considered copyrighted (c) material of the // |
||
17 | // original comment or credit authors. // |
||
18 | // // |
||
19 | // This program is distributed in the hope that it will be useful, // |
||
20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
22 | // GNU General Public License for more details. // |
||
23 | // // |
||
24 | // You should have received a copy of the GNU General Public License // |
||
25 | // along with this program; if not, write to the Free Software // |
||
26 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
27 | // ------------------------------------------------------------------------ // |
||
28 | // Part of the efqDirectory module provided by: wtravel // |
||
29 | // e-mail: [email protected] // |
||
30 | // Purpose: Create a business directory for xoops. // |
||
31 | // Based upon the mylinks and the mxDirectory modules // |
||
32 | // ------------------------------------------------------------------------- // |
||
33 | */ |
||
34 | |||
35 | /** |
||
36 | * Class efqSubscriptionOffer |
||
37 | * Manages operations for subscription offers |
||
38 | * |
||
39 | * @package efqDirectory |
||
40 | * @author EFQ Consultancy <[email protected]> |
||
41 | * @copyright EFQ Consultancy (c) 2008 |
||
42 | * @version 1.1.0 |
||
43 | */ |
||
44 | View Code Duplication | class efqSubscriptionOffer extends XoopsObject |
|
0 ignored issues
–
show
This class seems to be duplicated in your project.
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. ![]() |
|||
45 | { |
||
46 | |||
47 | /** |
||
48 | * efqSubscriptionOffer::efqSubscriptionOffer() |
||
49 | * |
||
50 | * @param bool $offer |
||
51 | * @internal param bool $itemtype |
||
52 | */ |
||
53 | public function __construct($offer = false) |
||
54 | { |
||
55 | global $moddir; |
||
56 | $this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
0 ignored issues
–
show
The type
XoopsDatabaseFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
57 | $this->initVar('offerid', XOBJ_DTYPE_INT, 0, false); |
||
0 ignored issues
–
show
|
|||
58 | $this->initVar('dirid', XOBJ_DTYPE_INT, 0, false); |
||
59 | $this->initVar('typeid', XOBJ_DTYPE_INT, 0, false); |
||
60 | $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, true, 255); |
||
0 ignored issues
–
show
|
|||
61 | $this->initVar('duration', XOBJ_DTYPE_INT, 0, true, 5); |
||
62 | $this->initVar('count', XOBJ_DTYPE_INT, 0, true, 5); |
||
63 | $this->initVar('price', XOBJ_DTYPE_CURRENCY, 0.00, true); |
||
0 ignored issues
–
show
|
|||
64 | $this->initVar('activeyn', XOBJ_DTYPE_INT, 0, true, 2); |
||
65 | $this->initVar('currency', XOBJ_DTYPE_TXTBOX, null, false, 10); |
||
66 | $this->initVar('descr', XOBJ_DTYPE_OTHER, 0); |
||
0 ignored issues
–
show
|
|||
67 | $this->initVar('typename', XOBJ_DTYPE_TXTBOX, null, false, 50); |
||
68 | $this->initVar('level', XOBJ_DTYPE_INT, null, false, 10); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Class efqFieldTypeHandler |
||
74 | * Manages database operations for field types |
||
75 | * |
||
76 | * @package efqDirectory |
||
77 | * @author EFQ Consultancy <[email protected]> |
||
78 | * @copyright EFQ Consultancy (c) 2007 |
||
79 | * @version 1.1.0 |
||
80 | */ |
||
81 | class efqSubscriptionOfferHandler extends xoopsObjectHandler |
||
0 ignored issues
–
show
The type
xoopsObjectHandler was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
82 | { |
||
83 | // public $db; //Database reference |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% of this comment could be valid code. Did you maybe forget this after debugging?
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. ![]() |
|||
84 | public $objOffer; // reference to object |
||
85 | |||
86 | /** |
||
87 | * efqSubscriptionOfferHandler::efqItemTypeHandler() |
||
88 | * |
||
89 | * @param bool $offer |
||
90 | */ |
||
91 | public function __construct($offer = false) |
||
92 | { |
||
93 | $this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
94 | $this->objOffer = $offer; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Function insertOffer inserts Subscripion offer into DB |
||
99 | * @author EFQ Consultancy <[email protected]> |
||
100 | * @copyright EFQ Consultancy (c) 2008 |
||
101 | * @version 1.0.0 |
||
102 | * |
||
103 | * @param efqSubscriptionOffer $obj object |
||
104 | * |
||
105 | * @param bool $forceQuery |
||
106 | * @return bool true if insertion is succesful, false if unsuccesful |
||
107 | */ |
||
108 | View Code Duplication | public function insertOffer($obj, $forceQuery = false) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
109 | { |
||
110 | $tablename = 'efqdiralpha1_subscr_offers'; |
||
111 | $keyName = 'offerid'; |
||
112 | $excludedVars = array('level', 'typename'); |
||
113 | if ($obj instanceof efqSubscriptionOffer) { |
||
114 | // Variable part of this function ends. From this line you can copy |
||
115 | // this function for similar object handling functions. |
||
116 | $obj->cleanVars(); |
||
117 | $cleanvars = $obj->cleanVars; |
||
118 | } else { |
||
119 | return false; |
||
120 | } |
||
121 | $countVars = count($cleanvars); |
||
122 | $i = 1; |
||
123 | $strFields = ''; |
||
124 | $strValues = ''; |
||
125 | foreach ($cleanvars as $k => $v) { |
||
126 | if (!in_array($k, $excludedVars)) { |
||
127 | $strFields .= $k; |
||
128 | $strValues .= "'" . $v . "'"; |
||
129 | if ($i < $countVars) { |
||
130 | $strFields .= ', '; |
||
131 | $strValues .= ', '; |
||
132 | } |
||
133 | $i++; |
||
134 | } |
||
135 | } |
||
136 | $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $this->db->prefix($tablename), $strFields, $strValues); |
||
137 | if ($forceQuery) { |
||
138 | if ($this->db->queryF($sql)) { |
||
139 | $itemid = $this->db->getInsertId(); |
||
140 | $obj->setVar($keyName, $itemid); |
||
141 | |||
142 | return true; |
||
143 | } |
||
144 | } else { |
||
145 | if ($this->db->query($sql)) { |
||
146 | $itemid = $this->db->getInsertId(); |
||
147 | $obj->setVar($keyName, $itemid); |
||
148 | |||
149 | return true; |
||
150 | } |
||
151 | } |
||
152 | |||
153 | return false; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Function updateOffer updates subscription offer |
||
158 | * @author EFQ Consultancy <[email protected]> |
||
159 | * @copyright EFQ Consultancy (c) 2008 |
||
160 | * @version 1.0.0 |
||
161 | * |
||
162 | * @param $obj |
||
163 | * @param bool $forceQuery |
||
164 | * @return bool true if update is succesful, false if unsuccesful |
||
165 | * @internal param object $objOffer object of type listing |
||
166 | */ |
||
167 | View Code Duplication | public function updateOffer($obj, $forceQuery = false) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
168 | { |
||
169 | $tablename = 'efqdiralpha1_subscr_offers'; |
||
170 | $keyName = 'offerid'; |
||
171 | $excludedVars = array('level', 'typename'); |
||
172 | if ($obj instanceof efqSubscriptionOffer) { |
||
173 | // Variable part of this function ends. From this line you can copy |
||
174 | // this function for similar object handling functions. |
||
175 | $obj->cleanVars(); |
||
176 | $cleanvars = $obj->cleanVars; |
||
177 | $keyValue = $obj->getVar($keyName); |
||
178 | } else { |
||
179 | return false; |
||
180 | } |
||
181 | $countVars = count($cleanvars); |
||
182 | $i = 1; |
||
183 | $strSet = ''; |
||
184 | $strValues = ''; |
||
0 ignored issues
–
show
|
|||
185 | foreach ($cleanvars as $k => $v) { |
||
186 | if (!in_array($k, $excludedVars)) { |
||
187 | if ($i < $countVars and $i > 1) { |
||
188 | $strSet .= ', '; |
||
189 | } |
||
190 | $strSet .= $k . '=' . "'" . $v . "'"; |
||
191 | } |
||
192 | $i++; |
||
193 | } |
||
194 | $sql = sprintf('UPDATE %s SET %s WHERE %s = %u', $this->db->prefix($tablename), $strSet, $keyName, $keyValue); |
||
195 | if ($forceQuery) { |
||
196 | if ($this->db->queryF($sql)) { |
||
197 | return true; |
||
198 | } |
||
199 | } else { |
||
200 | if ($this->db->query($sql)) { |
||
201 | return true; |
||
202 | } |
||
203 | } |
||
204 | |||
205 | return false; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * efqSubscriptionOfferHandler::setOffer() |
||
210 | * |
||
211 | * Sets the object created by class efqSubscriptionOffer with data from query |
||
212 | * |
||
213 | * @param int $gpc_offerid |
||
214 | * @return bool true or false |
||
215 | */ |
||
216 | public function setOffer($gpc_offerid = 0) |
||
217 | { |
||
218 | $sql = 'SELECT o.offerid, o.title, o.typeid, o.duration, o.count, ' |
||
219 | . 'o.price, o.activeyn, o.currency, o.descr, o.dirid, t.typename, t.level FROM ' |
||
220 | . $this->db->prefix('efqdiralpha1_itemtypes') |
||
221 | . ' t, ' |
||
222 | . $this->db->prefix('efqdiralpha1_subscr_offers') |
||
223 | . ' o WHERE o.typeid=t.typeid AND o.offerid=' |
||
224 | . (int)$gpc_offerid |
||
225 | . ''; |
||
226 | $result = $this->db->query($sql); |
||
227 | $numrows = $this->db->getRowsNum($result); |
||
228 | View Code Duplication | if ($numrows > 0) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
229 | while (list($offerid, $offertitle, $typeid, $duration, $count, $price, $activeyn, $currency, $descr, $dirid, $typename, $level) = $this->db->fetchRow($result)) { |
||
230 | if (!$this->objOffer) { |
||
231 | $this->objOffer = new efqSubscriptionOffer(); |
||
232 | } |
||
233 | $this->objOffer->setVar('offerid', $offerid); |
||
234 | $this->objOffer->setVar('title', $offertitle); |
||
235 | $this->objOffer->setVar('typeid', $typeid); |
||
236 | $this->objOffer->setVar('duration', $duration); |
||
237 | $this->objOffer->setVar('count', $count); |
||
238 | $this->objOffer->setVar('price', $price); |
||
239 | $this->objOffer->setVar('activeyn', $activeyn); |
||
240 | $this->objOffer->setVar('currency', $currency); |
||
241 | $this->objOffer->setVar('descr', $descr); |
||
242 | $this->objOffer->setVar('dirid', $dirid); |
||
243 | $this->objOffer->setVar('typename', $typename); |
||
244 | $this->objOffer->setVar('level', $level); |
||
245 | } |
||
246 | } else { |
||
247 | return false; |
||
248 | } |
||
249 | |||
250 | return true; |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * @return bool |
||
255 | */ |
||
256 | public function getOffer() |
||
257 | { |
||
258 | return $this->objOffer; |
||
259 | } |
||
260 | } |
||
261 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths