ShopadminExportCSV   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 69
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A preparePage() 0 41 3
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
use Zend\ServiceManager\ServiceManager;
24
25
/**
26
 * Class Shopadmin
27
 * @package HaaseIT\HCSF\Controller\Admin\Shop
28
 */
29
class ShopadminExportCSV extends Base
30
{
31
    /**
32
     * @var \PDO
33
     */
34
    protected $db;
35
36
    /**
37
     * @var \Doctrine\DBAL\Connection
38
     */
39
    protected $dbal;
40
41
    /**
42
     * Shopadmin constructor.
43
     * @param ServiceManager $serviceManager
44
     */
45
    public function __construct(ServiceManager $serviceManager)
46
    {
47
        parent::__construct($serviceManager);
48
        $this->db = $serviceManager->get('db');
49
        $this->dbal = $serviceManager->get('dbal');
50
    }
51
52
    /**
53
     *
54
     */
55
    public function preparePage()
56
    {
57
        $headers = [
58
            'Content-Disposition' => 'attachment; filename=hcsf_export.csv',
59
            'Content-type' => 'text/csv',
60
//            'Content-type' => 'text/plain',
61
            'Pragma' => 'no-cache',
62
            'Expires' => '0'
63
        ];
64
        $this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager, $headers, 'shop/shopadmin-export-csv.twig');
65
        $this->P->cb_pagetype = 'content';
66
        $this->P->cb_subnav = 'admin';
67
68
        // filter input
69
        $ids = filter_input_array(INPUT_POST, ['id' => ['filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY]]);
70
71
        if ($ids['id'] === false) {
72
            $this->helper->terminateScript('Invalid input.');
73
        }
74
75
        // fetch orders from db and add to $this->P->cb_customdata
76
        $queryBuilder = $this->dbal->createQueryBuilder();
77
        $queryBuilder
78
            ->select('*')
79
            ->from('orders', 'o')
80
            ->innerJoin('o', 'orders_items', 'oi', 'o.o_id = oi.oi_o_id')
81
            ->where('o.o_id IN ('.substr(str_repeat('?,', count($ids['id'])), 0, -1).')')
82
            ->orderBy('oi.oi_o_id')
83
            ->addOrderBy('oi.oi_id')
84
        ;
85
        $i = 0;
86
        foreach ($ids['id'] as $id) {
87
            $queryBuilder->setParameter($i, $id);
88
            $i++;
89
        }
90
        $statement = $queryBuilder->execute();
91
92
        $rows = $statement->fetchAll();
93
94
        $this->P->cb_customdata['rows'] = $rows;
95
    }
96
97
}
98