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

DealerContactExport::getOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
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 Propel\Runtime\ActiveQuery\Criteria;
16
use Propel\Runtime\ActiveQuery\Join;
17
use Thelia\Core\FileFormat\FormatType;
18
use Thelia\ImportExport\Export\ExportHandler;
19
use Thelia\Model\Lang;
20
use Dealer\Model\Map\DealerTableMap;
21
use Dealer\Model\Map\DealerI18nTableMap;
22
use Dealer\Model\DealerQuery;
23
use Dealer\Model\Map\DealerContactTableMap;
24
use Dealer\Model\Map\DealerContactI18nTableMap;
25
use Dealer\Model\Map\DealerContactInfoTableMap;
26
use Dealer\Model\Map\DealerContactInfoI18nTableMap;
27
28
/**
29
 * Class DealerExport
30
 * @package Thelia\ImportExport\Export
31
 * @author  Zzuutt [email protected]
32
 */
33
class DealerContactExport extends ExportHandler
34
{
35
    /**
36
     * @param  Lang                                            $lang
37
     * @return array|\Propel\Runtime\ActiveQuery\ModelCriteria
38
     */
39
    public function buildDataSet(Lang $lang)
40
    {
41
        $contactInfoType = "CASE ".DealerContactInfoTableMap::CONTACT_TYPE.
42
                            " WHEN 0 THEN '".DealerContactInfoTableMap::CONTACT_TYPE_EMAIL."'".
43
                            " WHEN 1 THEN '".DealerContactInfoTableMap::CONTACT_TYPE_TEL."'".
44
                            " WHEN 2 THEN '".DealerContactInfoTableMap::CONTACT_TYPE_FAX."'".
45
                            " WHEN 3 THEN '".DealerContactInfoTableMap::CONTACT_TYPE_URL."'".
46
                            " WHEN 4 THEN '".DealerContactInfoTableMap::CONTACT_TYPE_FACEBOOK."'".
47
                            " WHEN 5 THEN '".DealerContactInfoTableMap::CONTACT_TYPE_TWITTER."'".
48
                            " WHEN 6 THEN '".DealerContactInfoTableMap::CONTACT_TYPE_PINTEREST."'".
49
                            " WHEN 7 THEN '".DealerContactInfoTableMap::CONTACT_TYPE_GOOGLE."'".
50
                            " WHEN 8 THEN '".DealerContactInfoTableMap::CONTACT_TYPE_YOUTUBE."'".
51
                            " WHEN 9 THEN '".DealerContactInfoTableMap::CONTACT_TYPE_INSTAGRAM."'".
52
                            " ELSE '?'".
53
                            " END";
54
55
56
        $dealer = DealerQuery::create()
57
            ->useDealerI18nQuery()
58
                ->addAsColumn("dealer_TITLE", DealerI18nTableMap::TITLE)
59
            ->endUse()
60
            ->useDealerContactQuery()
61
                ->addAsColumn("contact_DEFAULT", DealerContactTableMap::IS_DEFAULT)
62
                ->useDealerContactI18nQuery()
63
                    ->addAsColumn("contact_LABEL", DealerContactI18nTableMap::LABEL)
64
                ->endUse()
65
                ->useDealerContactInfoQuery()
66
                    //->addAsColumn("contact_TYPE", DealerContactInfoTableMap::CONTACT_TYPE)
67
                    ->addAsColumn("contact_TYPE_NAME", $contactInfoType)
68
                    ->useDealerContactInfoI18nQuery()
69
                        ->addAsColumn("contact_VALUE", DealerContactInfoI18nTableMap::VALUE)
70
                    ->endUse()
71
                ->endUse()
72
            ->endUse()
73
74
75
76
            ->select([
77
                DealerTableMap::ID,
78
                'dealer_TITLE',
79
                'contact_LABEL',
80
                'contact_DEFAULT',
81
                'contact_TYPE_NAME',
82
                'contact_VALUE'
83
            ])
84
            ->orderById()
85
            ->find()
86
            ->toArray()
87
        ;
88
89
        return $dealer;
90
    }
91
92
    protected function getAliases()
93
    {
94
95
        return [
96
            DealerTableMap::ID  => 'id',
97
            'dealer_TITLE'      => 'title',
98
            'contact_LABEL'     => 'label',
99
            'contact_DEFAULT'   => 'is_default',
100
            'contact_TYPE_NAME' => 'type',
101
            'contact_VALUE'     => 'value'
102
        ];
103
    }
104
105
    public function getOrder()
106
    {
107
        return [
108
            'id',
109
            'title',
110
            'label',
111
            'is_default',
112
            'type',
113
            'value'
114
        ];
115
    }
116
    /**
117
     * @return string|array
118
     *
119
     * Define all the type of export/formatters that this can handle
120
     * return a string if it handle a single type ( specific exports ),
121
     * or an array if multiple.
122
     *
123
     * Thelia types are defined in \Thelia\Core\FileFormat\FormatType
124
     *
125
     * example:
126
     * return array(
127
     *     FormatType::TABLE,
128
     *     FormatType::UNBOUNDED,
129
     * );
130
     */
131
    public function getHandledTypes()
132
    {
133
        return array(
134
            FormatType::TABLE,
135
            FormatType::UNBOUNDED,
136
        );
137
    }
138
}
139