Completed
Push — master ( 858d63...cc8c1e )
by Marcus
03:06
created

Itemadmin::getItem()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 36
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 36
rs 8.5806
cc 4
eloc 24
nc 5
nop 1
1
<?php
2
3
/*
4
    HCSF - A multilingual CMS and Shopsystem
5
    Copyright (C) 2014  Marcus Haase - [email protected]
6
7
    This program is free software: you can redistribute it and/or modify
8
    it under the terms of the GNU General Public License as published by
9
    the Free Software Foundation, either version 3 of the License, or
10
    (at your option) any later version.
11
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16
17
    You should have received a copy of the GNU General Public License
18
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
namespace HaaseIT\HCSF\Controller\Admin\Shop;
22
23
24
use HaaseIT\HCSF\HardcodedText;
25
use HaaseIT\HCSF\HelperConfig;
26
use HaaseIT\Toolbox\Tools;
27
use Zend\Diactoros\ServerRequest;
28
use Zend\ServiceManager\ServiceManager;
29
30
/**
31
 * Class Itemadmin
32
 * @package HaaseIT\HCSF\Controller\Admin\Shop
33
 */
34
class Itemadmin extends Base
35
{
36
    /**
37
     * @var \Doctrine\DBAL\Connection
38
     */
39
    protected $dbal;
40
41
    /**
42
     * @var array
43
     */
44
    protected $get;
45
46
    /**
47
     * @var array
48
     */
49
    protected $post;
50
51
    /**
52
     * @var ServerRequest;
53
     */
54
    protected $request;
55
56
    /**
57
     * Itemadmin constructor.
58
     * @param ServiceManager $serviceManager
59
     */
60 View Code Duplication
    public function __construct(ServiceManager $serviceManager)
0 ignored issues
show
Duplication introduced by
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.

Loading history...
61
    {
62
        parent::__construct($serviceManager);
63
        $this->dbal = $serviceManager->get('dbal');
64
        $this->request = $serviceManager->get('request');
65
        $this->get = $this->request->getQueryParams();
66
        $this->post = $this->request->getParsedBody();
67
    }
68
69
    /**
70
     *
71
     */
72
    public function preparePage()
73
    {
74
        $this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager);
75
        $this->P->cb_pagetype = 'content';
76
        $this->P->cb_subnav = 'admin';
77
78
        $this->P->cb_customcontenttemplate = 'shop/itemadmin';
79
80
        if (isset($this->get['action']) && $this->get['action'] === 'insert_lang') {
81
            $aItemdata = $this->getItem();
82
83
            if (isset($aItemdata['base']) && !isset($aItemdata['text'])) {
84
                $querybuilder = $this->dbal->createQueryBuilder();
85
                $querybuilder
86
                    ->insert('item_lang')
87
                    ->setValue('itml_pid', '?')
88
                    ->setValue('itml_lang', '?')
89
                    ->setParameter(0, $aItemdata['base']['itm_id'])
90
                    ->setParameter(1, HelperConfig::$lang)
91
                ;
92
                $querybuilder->execute();
93
94
                \HaaseIT\HCSF\Helper::redirectToPage('/_admin/itemadmin.html?itemno='.$this->get['itemno'].'&action=showitem');
95
            }
96
        }
97
        $this->P->cb_customdata['searchform'] = $this->prepareItemlistsearchform();
98
99
        if (isset($this->get['action'])) {
100
            if ($this->get['action'] === 'search') {
101
                $this->P->cb_customdata['searchresult'] = true;
102
                if ($aItemlist = $this->getItemlist()) {
103
                    if (count($aItemlist['data']) == 1) {
104
                        $aItemdata = $this->getItem($aItemlist['data'][0]['itm_no']);
105
                        $this->P->cb_customdata['item'] = $this->prepareItem($aItemdata);
106
                    } else {
107
                        $this->P->cb_customdata['itemlist'] = $this->prepareItemlist($aItemlist);
108
                    }
109
                }
110
            } elseif (isset($this->post['doaction']) && $this->post['doaction'] === 'edititem') {
111
                $this->updateItem();
112
                $this->P->cb_customdata['itemupdated'] = true;
113
114
                $aItemdata = $this->getItem();
115
                $this->P->cb_customdata['item'] = $this->prepareItem($aItemdata);
116
            } elseif ($this->get['action'] === 'showitem') {
117
                $aItemdata = $this->getItem();
118
                $this->P->cb_customdata['item'] = $this->prepareItem($aItemdata);
119
            } elseif ($this->get['action'] === 'additem') {
120
                $aErr = [];
121
                if (isset($this->post['additem']) && $this->post['additem'] === 'do') {
122
                    if (strlen($this->post['itemno']) < 4) {
123
                        $aErr['itemnotooshort'] = true;
124
                    } else {
125
                        $querybuilder = $this->dbal->createQueryBuilder();
126
                        $querybuilder
127
                            ->select('itm_no')
128
                            ->from('item_base')
129
                            ->where('itm_no = ?')
130
                            ->setParameter(0, trim(filter_input(INPUT_POST, 'itemno', FILTER_SANITIZE_SPECIAL_CHARS)))
131
                        ;
132
                        $stmt = $querybuilder->execute();
133
134
                        if ($stmt->rowCount() > 0) {
135
                            $aErr['itemnoalreadytaken'] = true;
136
                        } else {
137
                            $querybuilder = $this->dbal->createQueryBuilder();
138
                            $querybuilder
139
                                ->insert('item_base')
140
                                ->setValue('itm_no', '?')
141
                                ->setParameter(0, trim(filter_input(INPUT_POST, 'itemno', FILTER_SANITIZE_SPECIAL_CHARS)))
142
                            ;
143
144
                            $querybuilder->execute();
145
                            $iInsertID = $this->dbal->lastInsertId();
146
147
                            $queryBuilder = $this->dbal->createQueryBuilder();
148
                            $queryBuilder
149
                                ->select('itm_no')
150
                                ->from('item_base')
151
                                ->where('itm_id = '.$queryBuilder->createNamedParameter($iInsertID))
152
                            ;
153
                            $statement = $queryBuilder->execute();
154
                            $row = $statement->fetch();
155
156
                            \HaaseIT\HCSF\Helper::redirectToPage('/_admin/itemadmin.html?itemno='.$row['itm_no'].'&action=showitem');
157
                        }
158
                    }
159
                }
160
                $this->P->cb_customdata['showaddform'] = true;
161
                $this->P->cb_customdata['err'] = $aErr;
162
            }
163
        }
164
    }
165
166
    /**
167
     * @return mixed
168
     */
169
    private function prepareItemlistsearchform()
0 ignored issues
show
Coding Style introduced by
prepareItemlistsearchform uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
170
    {
171
        $aData['searchcats'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aData was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aData = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
172
            'nummer|'.HardcodedText::get('itemadmin_search_itemno'),
173
            'name|'.HardcodedText::get('itemadmin_search_itemname'),
174
            'index|'.HardcodedText::get('itemadmin_search_itemindex'),
175
        ];
176
        $aData['orderbys'] = [
177
            'nummer|'.HardcodedText::get('itemadmin_search_itemno'),
178
            'name|'.HardcodedText::get('itemadmin_search_itemname'),
179
        ];
180
181 View Code Duplication
        if (isset($this->get['searchcat'])) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
182
            $aData['searchcat'] = $this->get['searchcat'];
183
            $_SESSION['itemadmin_searchcat'] = $this->get['searchcat'];
184
        } elseif (isset($_SESSION['itemadmin_searchcat'])) {
185
            $aData['searchcat'] = $_SESSION['itemadmin_searchcat'];
186
        }
187
188 View Code Duplication
        if (isset($this->get['orderby'])) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
189
            $aData['orderby'] = $this->get['orderby'];
190
            $_SESSION['itemadmin_orderby'] = $this->get['orderby'];
191
        } elseif (isset($_SESSION['itemadmin_orderby'])) {
192
            $aData['orderby'] = $_SESSION['itemadmin_orderby'];
193
        }
194
195
        return $aData;
196
    }
197
198
    /**
199
     * @return bool
200
     */
201
    private function getItemlist()
202
    {
203
        $sSearchstring = filter_input(INPUT_GET, 'searchstring', FILTER_SANITIZE_SPECIAL_CHARS);
204
        $sSearchstring = str_replace('*', '%', $sSearchstring);
205
206
        $querybuilder = $this->dbal->createQueryBuilder();
207
        $querybuilder
208
            ->select('itm_no, itm_name, itm_index')
209
            ->from('item_base', 'b')
210
            ->leftJoin('b', 'item_lang', 'l', 'b.itm_id = l.itml_pid AND l.itml_lang = :lang')
211
        ;
212
213
        if ($this->get['searchcat'] === 'name') {
214
            $querybuilder->where('itm_name LIKE :searchstring');
215
        } elseif ($this->get['searchcat'] === 'nummer') {
216
            $querybuilder->where('itm_no LIKE :searchstring');
217
        } elseif ($this->get['searchcat'] === 'index') {
218
            $querybuilder->where('itm_index LIKE :searchstring');
219
        } else {
220
            \HaaseIT\HCSF\Helper::terminateScript();
221
        }
222
223
        if ($this->get['orderby'] === 'name') {
224
            $querybuilder->orderBy('itm_name');
225
        } elseif ($this->get['orderby'] === 'nummer') {
226
            $querybuilder->orderBy('itm_no');
227
        }
228
229
        $querybuilder
230
            ->setParameter(':searchstring', $sSearchstring)
231
            ->setParameter(':lang', HelperConfig::$lang)
232
        ;
233
234
        $stmt = $querybuilder->execute();
235
236
        $aItemlist['numrows'] = $stmt->rowCount();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aItemlist was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aItemlist = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
237
238
        if ($aItemlist['numrows'] !== 0) {
239
            while ($aRow = $stmt->fetch()) {
240
                $aItemlist['data'][] = $aRow;
241
            }
242
            return $aItemlist;
243
        }
244
245
        return false;
246
    }
247
248
    /**
249
     * @param $aItemlist
250
     * @return array
251
     */
252
    private function prepareItemlist($aItemlist)
253
    {
254
        $aList = [
255
            ['title' => HardcodedText::get('itemadmin_list_active'), 'key' => 'itemindex', 'width' => 30, 'linked' => false, 'callback' => 'renderItemStatusIcon',],
256
            ['title' => HardcodedText::get('itemadmin_list_itemno'), 'key' => 'itemno', 'width' => 100, 'linked' => false,],
257
            ['title' => HardcodedText::get('itemadmin_list_name'), 'key' => 'name', 'width' => 350, 'linked' => false,],
258
            ['title' => HardcodedText::get('itemadmin_list_edit'), 'key' => 'itemno', 'width' => 30, 'linked' => true, 'ltarget' => '/_admin/itemadmin.html', 'lkeyname' => 'itemno', 'lgetvars' => ['action' => 'showitem'],],
259
        ];
260
        $aData = [];
261
        foreach ($aItemlist['data'] as $aValue) {
262
            $aData[] = [
263
                'itemindex' => $aValue['itm_index'],
264
                'itemno' => $aValue['itm_no'],
265
                'name' => $aValue['itm_name'],
266
            ];
267
        }
268
269
        return [
270
            'numrows' => $aItemlist['numrows'],
271
            'listtable' => Tools::makeListtable($aList, $aData, $this->serviceManager->get('twig')),
272
        ];
273
    }
274
275
    /**
276
     * @param string $sItemno
277
     * @return bool
278
     */
279
    private function getItem($sItemno = '')
280
    {
281
        if ($sItemno === '') {
282
            if (empty($this->get['itemno'])) {
283
                return false;
284
            }
285
            $sItemno = filter_var($this->get['itemno'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
286
        }
287
288
        $querybuilder = $this->dbal->createQueryBuilder();
289
        $querybuilder
290
            ->select('*')
291
            ->from('item_base')
292
            ->where('itm_no = ?')
293
            ->setParameter(0, $sItemno)
294
        ;
295
        $stmt = $querybuilder->execute();
296
297
        $aItemdata['base'] = $stmt->fetch();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aItemdata was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aItemdata = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
298
299
        $querybuilder = $this->dbal->createQueryBuilder();
300
        $querybuilder
301
            ->select('*')
302
            ->from('item_lang')
303
            ->where('itml_pid = ? AND itml_lang = ?')
304
            ->setParameter(0, $aItemdata['base']['itm_id'])
305
            ->setParameter(1, HelperConfig::$lang)
306
        ;
307
        $stmt = $querybuilder->execute();
308
309
        if ($stmt->rowCount() != 0) {
310
            $aItemdata['text'] = $stmt->fetch();
311
        }
312
313
        return $aItemdata;
314
    }
315
316
    /**
317
     * @param $aItemdata
318
     * @return array
319
     */
320
    private function prepareItem($aItemdata)
321
    {
322
        $aData = [
323
            'form' => ['action' => Tools::makeLinkHRefWithAddedGetVars('/_admin/itemadmin.html', ['action' => 'showitem', 'itemno' => $aItemdata['base']['itm_no']]),],
324
            'id' => $aItemdata['base']['itm_id'],
325
            'itemno' => $aItemdata['base']['itm_no'],
326
            'name' => $aItemdata['base']['itm_name'],
327
            'img' => $aItemdata['base']['itm_img'],
328
            'price' => $aItemdata['base']['itm_price'],
329
            'vatid' => $aItemdata['base']['itm_vatid'],
330
            'rg' => $aItemdata['base']['itm_rg'],
331
            'index' => $aItemdata['base']['itm_index'],
332
            'prio' => $aItemdata['base']['itm_order'],
333
            'group' => $aItemdata['base']['itm_group'],
334
            'data' => $aItemdata['base']['itm_data'],
335
            'weight' => $aItemdata['base']['itm_weight'],
336
        ];
337
338
        if (!HelperConfig::$shop['vat_disable']) {
339
            $aOptions[] = '|';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aOptions was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aOptions = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
340
            foreach (HelperConfig::$shop['vat'] as $sKey => $sValue) {
341
                $aOptions[] = $sKey.'|'.$sValue;
342
            }
343
            $aData['vatoptions'] = $aOptions;
344
            unset($aOptions);
345
        }
346
        $aData['rgoptions'][] = '';
347
        foreach (HelperConfig::$shop['rebate_groups'] as $sKey => $aValue) {
348
            $aData['rgoptions'][] = $sKey;
349
        }
350
351
        $aGroups = $this->getItemgroups('');
352
        $aData['groupoptions'][] = '';
353
        foreach ($aGroups as $aValue) {
354
            $aData['groupoptions'][] = $aValue['itmg_id'] . '|' . $aValue['itmg_no'] . ' - ' . $aValue['itmg_name'];
355
        }
356
        unset($aGroups);
357
358
        if (isset($aItemdata['text'])) {
359
            $aData['lang'] = [
360
                'textid' => $aItemdata['text']['itml_id'],
361
                'nameoverride' => $aItemdata['text']['itml_name_override'],
362
                'text1' => $aItemdata['text']['itml_text1'],
363
                'text2' => $aItemdata['text']['itml_text2'],
364
            ];
365
        }
366
367
        return $aData;
368
    }
369
370
    /**
371
     * @return bool
372
     */
373
    private function updateItem()
374
    {
375
        $purifier = false;
376
        if (HelperConfig::$shop['itemtext_enable_purifier']) {
377
            $purifier = \HaaseIT\HCSF\Helper::getPurifier('item');
378
        }
379
380
        $querybuilder = $this->dbal->createQueryBuilder();
381
        $querybuilder
382
            ->update('item_base')
383
            ->set('itm_name', ':itm_name')
384
            ->set('itm_group', ':itm_group')
385
            ->set('itm_img', ':itm_img')
386
            ->set('itm_index', ':itm_index')
387
            ->set('itm_order', ':itm_order')
388
            ->set('itm_price', ':itm_price')
389
            ->set('itm_rg', ':itm_rg')
390
            ->set('itm_data', ':itm_data')
391
            ->set('itm_weight', ':itm_weight')
392
            ->set('itm_vatid', ':itm_vatid')
393
            ->where('itm_id = :itm_id')
394
            ->setParameter(':itm_name', filter_var($this->post['name'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
395
            ->setParameter(':itm_group', filter_var($this->post['group'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
396
            ->setParameter(':itm_img', filter_var($this->post['bild'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
397
            ->setParameter(':itm_index', filter_var($this->post['index'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
398
            ->setParameter(':itm_order', filter_var($this->post['prio'], FILTER_SANITIZE_NUMBER_INT))
399
            ->setParameter(':itm_price', filter_var($this->post['price'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION))
400
            ->setParameter(':itm_rg', filter_var($this->post['rg'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
401
            ->setParameter(':itm_data', filter_var($this->post['data'], FILTER_UNSAFE_RAW))
402
            ->setParameter(':itm_weight', filter_var($this->post['weight'], FILTER_SANITIZE_NUMBER_INT))
403
            ->setParameter(':itm_id', filter_var($this->post['id'], FILTER_SANITIZE_NUMBER_INT))
404
        ;
405
406
        if (!HelperConfig::$shop['vat_disable']) {
407
            $querybuilder->setParameter(':itm_vatid', filter_var($this->post['vatid'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW));
408
        } else {
409
            $querybuilder->setParameter(':itm_vatid', 'full');
410
        }
411
        $querybuilder->execute();
412
413
        if (isset($this->post['textid'])) {
414
            $querybuilder = $this->dbal->createQueryBuilder();
415
            $querybuilder
416
                ->update('item_lang')
417
                ->set('itml_text1', ':itml_text1')
418
                ->set('itml_text2', ':itml_text2')
419
                ->set('itml_name_override', ':itml_name_override')
420
                ->where('itml_id = :itml_id')
421
                ->setParameter(':itml_text1', !empty($this->purifier) ? $purifier->purify($this->post['text1']) : $this->post['text1'])
0 ignored issues
show
Bug introduced by
The property purifier does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
422
                ->setParameter(':itml_text2', !empty($this->purifier) ? $purifier->purify($this->post['text2']) : $this->post['text2'])
423
                ->setParameter(':itml_name_override', filter_var($this->post['name_override'], FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW))
424
                ->setParameter(':itml_id', filter_var($this->post['textid'], FILTER_SANITIZE_NUMBER_INT))
425
            ;
426
            $querybuilder->execute();
427
        }
428
429
        return true;
430
    }
431
432
    /**
433
     * @param string $iGID
434
     * @return mixed
435
     */
436 View Code Duplication
    private function getItemgroups($iGID = '') // this function should be outsourced, a duplicate is used in admin itemgroups!
0 ignored issues
show
Duplication introduced by
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.

Loading history...
437
    {
438
        $querybuilder = $this->dbal->createQueryBuilder();
439
        $querybuilder
440
            ->select('*')
441
            ->from('itemgroups_base', 'b')
442
            ->leftJoin('b', 'itemgroups_text', 't', 'b.itmg_id = t.itmgt_pid AND t.itmgt_lang = ?')
443
            ->setParameter(0, HelperConfig::$lang)
444
            ->orderBy('itmg_no')
445
        ;
446
447
        if ($iGID != '') {
448
            $querybuilder
449
                ->where('itmg_id = :gid')
450
                ->setParameter(1, $iGID)
451
            ;
452
        }
453
        $stmt = $querybuilder->execute();
454
455
        return $stmt->fetchAll();
456
    }
457
}
458