Completed
Pull Request — master (#19)
by zzuutt
03:15
created

DealerExport::getOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
rs 9.4285
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
/*************************************************************************************/
3
/*      This file is part of the Thelia package.                                     */
4
/*                                                                                   */
5
/*      Copyright (c) OpenStudio                                                     */
6
/*      email : [email protected]                                                       */
7
/*      web : http://www.thelia.net                                                  */
8
/*                                                                                   */
9
/*      For the full copyright and license information, please view the LICENSE.txt  */
10
/*      file that was distributed with this source code.                             */
11
/*************************************************************************************/
12
13
namespace Dealer\ImportExport\Export;
14
15
use Thelia\Core\FileFormat\FormatType;
16
use Thelia\ImportExport\Export\ExportHandler;
17
use Thelia\Model\Lang;
18
use Dealer\Model\Map\DealerTableMap;
19
use Dealer\Model\Map\DealerI18nTableMap;
20
use Dealer\Model\DealerQuery;
21
use Thelia\Model\Map\CountryI18nTableMap;
22
use Thelia\Model\Map\CountryTableMap;
23
use Thelia\Tools\I18n;
24
25
/**
26
 * Class DealerExport
27
 * @package Thelia\ImportExport\Export
28
 * @author  Zzuutt [email protected]
29
 */
30
class DealerExport extends ExportHandler
31
{
32
    /**
33
     * @param  Lang                                            $lang
34
     * @return array|\Propel\Runtime\ActiveQuery\ModelCriteria
35
     */
36
    public function buildDataSet(Lang $lang)
37
    {
38
        $locale = $lang->getLocale();
39
40
        $dealer = DealerQuery::create()
41
            ->useCountryQuery()
42
                ->useCountryI18nQuery()
43
                    ->addAsColumn("address_COUNTRY", CountryI18nTableMap::TITLE)
44
                ->endUse()
45
            ->endUse()
46
            ->useDealerI18nQuery()
47
                ->addAsColumn("dealer_TITLE", DealerI18nTableMap::TITLE)
48
                ->addAsColumn("dealer_DESCRIPTION", DealerI18nTableMap::DESCRIPTION)
49
                ->addAsColumn("dealer_ACCESS", DealerI18nTableMap::ACCESS)
50
            ->endUse()
51
            ->select([
52
                DealerTableMap::ID,
53
                //DealerTableMap::VERSION,
54
                DealerTableMap::VISIBLE,
55
                'dealer_TITLE',
56
                'dealer_DESCRIPTION',
57
                'dealer_ACCESS',
58
                DealerTableMap::ADDRESS1,
59
                DealerTableMap::ADDRESS2,
60
                DealerTableMap::ADDRESS3,
61
                DealerTableMap::ZIPCODE,
62
                DealerTableMap::CITY,
63
                DealerTableMap::COUNTRY_ID,
64
                'address_COUNTRY',
65
                DealerTableMap::LATITUDE,
66
                DealerTableMap::LONGITUDE
67
            ])
68
            ->orderById()
69
        ;
70
71
        I18n::addI18nCondition(
72
            $dealer,
73
            CountryI18nTableMap::TABLE_NAME,
74
            CountryTableMap::ID,
75
            CountryI18nTableMap::ID,
76
            CountryI18nTableMap::LOCALE,
77
            $locale
78
        );
79
80
        $dealer
81
            ->find()
82
            ->toArray()
83
        ;
84
85
        return $dealer;
86
    }
87
88
    protected function getAliases()
89
    {
90
91
        return [
92
            //DealerTableMap::VERSION     => 'version',
93
            DealerTableMap::ID          => 'id',
94
            DealerTableMap::VISIBLE     =>  'visible',
95
            'dealer_TITLE'              => 'title',
96
            'dealer_DESCRIPTION'        => 'description',
97
            'dealer_ACCESS'             => 'access',
98
            DealerTableMap::ADDRESS1    => 'address1',
99
            DealerTableMap::ADDRESS2    => 'address2',
100
            DealerTableMap::ADDRESS3    => 'address3',
101
            DealerTableMap::ZIPCODE     => 'zipcode',
102
            DealerTableMap::CITY        => 'city',
103
            DealerTableMap::COUNTRY_ID  => 'country_id',
104
            'address_COUNTRY'           => 'country',
105
            DealerTableMap::LATITUDE    => 'latitude',
106
            DealerTableMap::LONGITUDE   => 'longitude'
107
        ];
108
    }
109
110
    public function getOrder()
111
    {
112
        return [
113
            'id',
114
            //'version',
115
            'visible',
116
            'title',
117
            'description',
118
            'access',
119
            'address1',
120
            'address2',
121
            'address3',
122
            'zipcode',
123
            'city',
124
            'country_id',
125
            'country',
126
            'latitude',
127
            'longitude'
128
        ];
129
    }
130
    /**
131
     * @return string|array
132
     *
133
     * Define all the type of export/formatters that this can handle
134
     * return a string if it handle a single type ( specific exports ),
135
     * or an array if multiple.
136
     *
137
     * Thelia types are defined in \Thelia\Core\FileFormat\FormatType
138
     *
139
     * example:
140
     * return array(
141
     *     FormatType::TABLE,
142
     *     FormatType::UNBOUNDED,
143
     * );
144
     */
145
    public function getHandledTypes()
146
    {
147
        return array(
148
            FormatType::TABLE,
149
            FormatType::UNBOUNDED,
150
        );
151
    }
152
}
153