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

DealerSchedulesExport   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 118
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
B buildDataSet() 0 46 1
A getAliases() 0 14 1
A getOrder() 0 13 1
A getHandledTypes() 0 7 1
A getDayLabel() 0 12 1
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 Thelia\Model\LangQuery;
21
use Dealer\Model\Map\DealerTableMap;
22
use Dealer\Model\Map\DealerI18nTableMap;
23
use Dealer\Model\DealerQuery;
24
use Dealer\Model\Map\DealerShedulesTableMap;
25
use Dealer\Dealer;
26
use Thelia\Core\Translation\Translator;
27
28
/**
29
 * Class DealerExport
30
 * @package Thelia\ImportExport\Export
31
 * @author  Zzuutt [email protected]
32
 */
33
class DealerSchedulesExport extends ExportHandler
34
{
35
36
    /**
37
     * @param  Lang                                            $lang
38
     * @return array|\Propel\Runtime\ActiveQuery\ModelCriteria
39
     */
40
    public function buildDataSet(Lang $lang)
41
    {
42
        $locale = $lang->getLocale($lang);
43
44
        $schedulesDay = "CASE ".DealerShedulesTableMap::DAY.
45
            " WHEN 0 THEN '".$this->getDayLabel(0, $locale)."'".
46
            " WHEN 1 THEN '".$this->getDayLabel(1, $locale)."'".
47
            " WHEN 2 THEN '".$this->getDayLabel(2, $locale)."'".
48
            " WHEN 3 THEN '".$this->getDayLabel(3, $locale)."'".
49
            " WHEN 4 THEN '".$this->getDayLabel(4, $locale)."'".
50
            " WHEN 5 THEN '".$this->getDayLabel(5, $locale)."'".
51
            " WHEN 6 THEN '".$this->getDayLabel(6, $locale)."'".
52
            " ELSE '?'".
53
            " END";
54
55
56
        $dealer = DealerQuery::create()
57
            ->useDealerI18nQuery()
58
            ->addAsColumn("dealer_TITLE", DealerI18nTableMap::TITLE)
59
            ->endUse()
60
            ->useDealerShedulesQuery()
61
                ->addAsColumn("schedules_DAY", $schedulesDay)
62
                ->addAsColumn("schedules_BEGIN", DealerShedulesTableMap::BEGIN)
63
                ->addAsColumn("schedules_END", DealerShedulesTableMap::END)
64
                ->addAsColumn("schedules_CLOSED", DealerShedulesTableMap::CLOSED)
65
                ->addAsColumn("schedules_PERIOD_BEGIN", DealerShedulesTableMap::PERIOD_BEGIN)
66
                ->addAsColumn("schedules_PERIOD_END", DealerShedulesTableMap::PERIOD_END)
67
            ->endUse()
68
69
            ->select([
70
                DealerTableMap::ID,
71
                'dealer_TITLE',
72
                'schedules_DAY',
73
                'schedules_BEGIN',
74
                'schedules_END',
75
                'schedules_CLOSED',
76
                'schedules_PERIOD_BEGIN',
77
                'schedules_PERIOD_END'
78
            ])
79
            ->orderById()
80
            ->find()
81
            ->toArray()
82
        ;
83
84
        return $dealer;
85
    }
86
87
    protected function getAliases()
88
    {
89
90
        return [
91
            DealerTableMap::ID      => 'id',
92
            'dealer_TITLE'          => 'title',
93
            'schedules_DAY'          => 'day',
94
            'schedules_BEGIN'        => 'begin',
95
            'schedules_END'          => 'end',
96
            'schedules_CLOSED'       => 'closed',
97
            'schedules_PERIOD_BEGIN' => 'period_begin',
98
            'schedules_PERIOD_END'   => 'period_end'
99
        ];
100
    }
101
102
    public function getOrder()
103
    {
104
        return [
105
            'id',
106
            'title',
107
            'day',
108
            'begin',
109
            'end',
110
            'closed',
111
            'period_begin',
112
            'period_end'
113
        ];
114
    }
115
    /**
116
     * @return string|array
117
     *
118
     * Define all the type of export/formatters that this can handle
119
     * return a string if it handle a single type ( specific exports ),
120
     * or an array if multiple.
121
     *
122
     * Thelia types are defined in \Thelia\Core\FileFormat\FormatType
123
     *
124
     * example:
125
     * return array(
126
     *     FormatType::TABLE,
127
     *     FormatType::UNBOUNDED,
128
     * );
129
     */
130
    public function getHandledTypes()
131
    {
132
        return array(
133
            FormatType::TABLE,
134
            FormatType::UNBOUNDED,
135
        );
136
    }
137
138
    protected function getDayLabel($int = 0, $locale = null)
139
    {
140
        return [
141
            Translator::getInstance()->trans("Monday", [], Dealer::MESSAGE_DOMAIN, $locale),
142
            Translator::getInstance()->trans("Tuesday", [], Dealer::MESSAGE_DOMAIN, $locale),
143
            Translator::getInstance()->trans("Wednesday", [], Dealer::MESSAGE_DOMAIN, $locale),
144
            Translator::getInstance()->trans("Thursday", [], Dealer::MESSAGE_DOMAIN, $locale),
145
            Translator::getInstance()->trans("Friday", [], Dealer::MESSAGE_DOMAIN, $locale),
146
            Translator::getInstance()->trans("Saturday", [], Dealer::MESSAGE_DOMAIN, $locale),
147
            Translator::getInstance()->trans("Sunday", [], Dealer::MESSAGE_DOMAIN, $locale)
148
        ][$int];
149
    }
150
}
151