getQueryBuilderBySearchDataForAdmin()   F
last analyzed

Complexity

Conditions 45
Paths > 20000

Size

Total Lines 184
Code Lines 123

Duplication

Lines 128
Ratio 69.57 %
Metric Value
dl 128
loc 184
rs 2
cc 45
eloc 123
nc 3145728
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Repository;
26
27
use Eccube\Util\Str;
28
use Doctrine\ORM\EntityRepository;
29
use Doctrine\ORM\QueryBuilder;
30
31
/**
32
 * OrderRepository
33
 *
34
 * This class was generated by the Doctrine ORM. Add your own custom
35
 * repository methods below.
36
 */
37
class OrderRepository extends EntityRepository
38
{
39
    protected $app;
40
41
    public function setApplication($app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
42
    {
43
        $this->app = $app;
44
    }
45
46
    public function changeStatus($orderId, \Eccube\Entity\Master\OrderStatus $Status)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
47
    {
48
        $Order = $this
49
            ->find($orderId)
50
            ->setOrderStatus($Status)
51
        ;
52
53
        switch ($Status->getId()) {
54
            case '5': // 発送済へ
55
                $Order->setCommitDate(new \DateTime());
56
                break;
57
            case '6': // 入金済へ
58
                $Order->setPaymentDate(new \DateTime());
59
                break;
60
        }
61
62
        $em = $this->getEntityManager();
63
        $em->persist($Order);
64
        $em->flush();
65
    }
66
67
    /**
68
     *
69
     * @param  array        $searchData
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
70
     * @return QueryBuilder
71
     */
72
    public function getQueryBuilderBySearchData($searchData)
73
    {
74
        $qb = $this->createQueryBuilder('o');
75
76
        $joinedCustomer = false;
77
78
        // order_id_start
79 View Code Duplication
        if (isset($searchData['order_id_start']) && Str::isNotBlank($searchData['order_id_start'])) {
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...
80
            $qb
81
                ->andWhere('o.id >= :order_id_start')
82
                ->setParameter('order_id_start', $searchData['order_id_start']);
83
        }
84
85
        // order_id_end
86 View Code Duplication
        if (isset($searchData['order_id_end']) && Str::isNotBlank($searchData['order_id_end'])) {
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...
87
            $qb
88
                ->andWhere('o.id <= :order_id_end')
89
                ->setParameter('order_id_end', $searchData['order_id_end']);
90
        }
91
92
        // status
93
        if (!empty($searchData['status']) && $searchData['status']) {
94
            $qb
95
                ->andWhere('o.OrderStatus = :status')
96
                ->setParameter('status', $searchData['status']);
97
        }
98
99
        // name
100 View Code Duplication
        if (isset($searchData['name']) && Str::isNotBlank($searchData['name'])) {
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...
101
            $qb
102
                ->andWhere('CONCAT(o.name01, o.name02) LIKE :name')
103
                ->setParameter('name', '%' . $searchData['name'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
104
        }
105
106
        // kana
107 View Code Duplication
        if (isset($searchData['kana']) && Str::isNotBlank($searchData['kana'])) {
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...
108
            $qb
109
                ->andWhere('CONCAT(o.kana01, o.kana02) LIKE :kana')
110
                ->setParameter('kana', '%' . $searchData['kana'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
111
        }
112
113
        // email
114 View Code Duplication
        if (isset($searchData['email']) && Str::isNotBlank($searchData['email'])) {
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...
115
            $qb
116
                ->andWhere('o.email = :email')
117
                ->setParameter('email', $searchData['email']);
118
        }
119
120
        // tel
121 View Code Duplication
        if (isset($searchData['tel01']) && Str::isNotBlank($searchData['tel01'])) {
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...
122
            $qb
123
                ->andWhere('o.tel01 = :tel01')
124
                ->setParameter('tel01', $searchData['tel01']);
125
        }
126 View Code Duplication
        if (isset($searchData['tel02']) && Str::isNotBlank($searchData['tel02'])) {
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...
127
            $qb
128
                ->andWhere('o.tel02 = :tel02')
129
                ->setParameter('tel02', $searchData['tel02']);
130
        }
131 View Code Duplication
        if (isset($searchData['tel03']) && Str::isNotBlank($searchData['tel03'])) {
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...
132
            $qb
133
                ->andWhere('o.tel03 = :tel03')
134
                ->setParameter('tel03', $searchData['tel03']);
135
        }
136
137
        // birth
138 View Code Duplication
        if (!empty($searchData['birth_start']) && $searchData['birth_start']) {
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...
139
            if (!$joinedCustomer) {
140
                $qb->leftJoin('o.Customer', 'c');
141
                $joinedCustomer = true;
142
            }
143
144
            $date = $searchData['birth_start']
145
                ->format('Y-m-d H:i:s');
146
            $qb
147
                ->andWhere('c.birth >= :birth_start')
148
                ->setParameter('birth_start', $date);
149
        }
150 View Code Duplication
        if (!empty($searchData['birth_end']) && $searchData['birth_end']) {
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...
151
            if (!$joinedCustomer) {
152
                $qb->leftJoin('o.Customer', 'c');
153
                $joinedCustomer = true;
154
            }
155
156
            $date = clone $searchData['birth_end'];
157
            $date = $date
158
                ->modify('+1 days')
159
                ->format('Y-m-d H:i:s');
160
            $qb
161
                ->andWhere('c.birth < :birth_end')
162
                ->setParameter('birth_end', $date);
163
        }
164
165
        // sex
166
        if (!empty($searchData['sex']) && count($searchData['sex']) > 0) {
167
            if (!$joinedCustomer) {
168
                $qb->leftJoin('o.Customer', 'c');
169
                $joinedCustomer = true;
0 ignored issues
show
Unused Code introduced by
$joinedCustomer is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
170
            }
171
172
            $sexs = array();
173
            foreach ($searchData['sex'] as $sex) {
174
                $sexs[] = $sex->getId();
175
            }
176
177
            $qb
178
                ->andWhere($qb->expr()->in('c.Sex', ':sexs'))
179
                ->setParameter('sexs', $sexs);
180
        }
181
182
        // payment
183 View Code Duplication
        if (!empty($searchData['payment']) && count($searchData['payment'])) {
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...
184
            $payments = array();
185
            foreach ($searchData['payment'] as $payment) {
186
                $payments[] = $payment->getId();
187
            }
188
            $qb
189
                ->leftJoin('o.Payment', 'p')
190
                ->andWhere($qb->expr()->in('p.id', ':payments'))
191
                ->setParameter('payments', $payments);
192
        }
193
194
        // oreder_date
195 View Code Duplication
        if (!empty($searchData['order_date_start']) && $searchData['order_date_start']) {
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...
196
            $date = $searchData['order_date_start']
197
                ->format('Y-m-d H:i:s');
198
            $qb
199
                ->andWhere('o.create_date >= :order_date_start')
200
                ->setParameter('order_date_start', $date);
201
        }
202 View Code Duplication
        if (!empty($searchData['order_date_end']) && $searchData['order_date_end']) {
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...
203
            $date = clone $searchData['order_date_end'];
204
            $date = $date
205
                ->modify('+1 days')
206
                ->format('Y-m-d H:i:s');
207
            $qb
208
                ->andWhere('o.create_date < :order_date_end')
209
                ->setParameter('order_date_end', $date);
210
        }
211
212
        // create_date
213 View Code Duplication
        if (!empty($searchData['update_date_start']) && $searchData['update_date_start']) {
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...
214
            $date = $searchData['update_date_start']
215
                ->format('Y-m-d H:i:s');
216
            $qb
217
                ->andWhere('o.update_date >= :update_date_start')
218
                ->setParameter('update_date_start', $date);
219
        }
220 View Code Duplication
        if (!empty($searchData['update_date_end']) && $searchData['update_date_end']) {
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...
221
            $date = clone $searchData['update_date_end'];
222
            $date = $date
223
                ->modify('+1 days')
224
                ->format('Y-m-d H:i:s');
225
            $qb
226
                ->andWhere('o.update_date < :update_date_end')
227
                ->setParameter('update_date_end', $date);
228
        }
229
230
        // payment_total
231 View Code Duplication
        if (isset($searchData['payment_total_start']) && Str::isNotBlank($searchData['payment_total_start'])) {
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...
232
            $qb
233
                ->andWhere('o.payment_total >= :payment_total_start')
234
                ->setParameter('payment_total_start', $searchData['payment_total_start']);
235
        }
236 View Code Duplication
        if (isset($searchData['payment_total_end']) && Str::isNotBlank($searchData['payment_total_end'])) {
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...
237
            $qb
238
                ->andWhere('o.payment_total <= :payment_total_end')
239
                ->setParameter('payment_total_end', $searchData['payment_total_end']);
240
        }
241
242
        // buy_product_name
243 View Code Duplication
        if (isset($searchData['buy_product_name']) && Str::isNotBlank($searchData['buy_product_name'])) {
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...
244
            $qb
245
                ->leftJoin('o.OrderDetails', 'od')
246
                ->andWhere('od.product_name LIKE :buy_product_name')
247
                ->setParameter('buy_product_name', '%' . $searchData['buy_product_name'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
248
        }
249
250
        // Order By
251
        $qb->addOrderBy('o.update_date', 'DESC');
252
253
        return $qb;
254
    }
255
256
257
    /**
258
     *
259
     * @param  array        $searchData
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
260
     * @return QueryBuilder
261
     */
262
    public function getQueryBuilderBySearchDataForAdmin($searchData)
263
    {
264
        $qb = $this->createQueryBuilder('o');
265
266
        // order_id_start
267 View Code Duplication
        if (isset($searchData['order_id_start']) && Str::isNotBlank($searchData['order_id_start'])) {
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...
268
            $qb
269
                ->andWhere('o.id >= :order_id_start')
270
                ->setParameter('order_id_start', $searchData['order_id_start']);
271
        }
272
        // multi
273 View Code Duplication
        if (isset( $searchData['multi']) && Str::isNotBlank($searchData['multi'])) {
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...
274
            $multi = preg_match('/^\d+$/', $searchData['multi']) ? $searchData['multi'] : null;
275
            $qb
276
                ->andWhere('o.id = :multi OR o.name01 LIKE :likemulti OR o.name02 LIKE :likemulti OR ' .
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
277
                           'o.kana01 LIKE :likemulti OR o.kana02 LIKE :likemulti OR o.company_name LIKE :likemulti')
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 27.
Loading history...
278
                ->setParameter('multi', $multi)
279
                ->setParameter('likemulti', '%' . $searchData['multi'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
280
        }
281
282
        // order_id_end
283 View Code Duplication
        if (isset($searchData['order_id_end']) && Str::isNotBlank($searchData['order_id_end'])) {
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...
284
            $qb
285
                ->andWhere('o.id <= :order_id_end')
286
                ->setParameter('order_id_end', $searchData['order_id_end']);
287
        }
288
289
        // status
290
        if (!empty($searchData['status']) && $searchData['status']) {
291
            $qb
292
                ->andWhere('o.OrderStatus = :status')
293
                ->setParameter('status', $searchData['status']);
294
        } else {
295
            // 購入処理中は検索対象から除外
296
            $qb->andWhere('o.OrderStatus <> :status')
297
                ->setParameter('status', $this->app['config']['order_processing']);
298
        }
299
300
        // name
301 View Code Duplication
        if (isset($searchData['name']) && Str::isNotBlank($searchData['name'])) {
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...
302
            $qb
303
                ->andWhere('CONCAT(o.name01, o.name02) LIKE :name')
304
                ->setParameter('name', '%' . $searchData['name'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
305
        }
306
307
        // kana
308 View Code Duplication
        if (isset($searchData['kana']) && Str::isNotBlank($searchData['kana'])) {
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...
309
            $qb
310
                ->andWhere('CONCAT(o.kana01, o.kana02) LIKE :kana')
311
                ->setParameter('kana', '%' . $searchData['kana'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
312
        }
313
314
        // email
315 View Code Duplication
        if (isset($searchData['email']) && Str::isNotBlank($searchData['email'])) {
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...
316
            $qb
317
                ->andWhere('o.email like :email')
318
                ->setParameter('email', '%' . $searchData['email'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
319
        }
320
321
        // tel
322 View Code Duplication
        if (isset($searchData['tel']) && Str::isNotBlank($searchData['tel'])) {
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...
323
            $qb
324
                ->andWhere('CONCAT(o.tel01, o.tel02, o.tel03) LIKE :tel')
325
                ->setParameter('tel', '%' . $searchData['tel'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
326
        }
327
328
        // sex
329
        if (!empty($searchData['sex']) && count($searchData['sex']) > 0) {
330
            $qb
331
                ->andWhere($qb->expr()->in('o.Sex', ':sex'))
332
                ->setParameter('sex', $searchData['sex']->toArray());
333
        }
334
335
        // payment
336 View Code Duplication
        if (!empty($searchData['payment']) && count($searchData['payment'])) {
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...
337
            $payments = array();
338
            foreach ($searchData['payment'] as $payment) {
339
                $payments[] = $payment->getId();
340
            }
341
            $qb
342
                ->leftJoin('o.Payment', 'p')
343
                ->andWhere($qb->expr()->in('p.id', ':payments'))
344
                ->setParameter('payments', $payments);
345
        }
346
347
        // oreder_date
348 View Code Duplication
        if (!empty($searchData['order_date_start']) && $searchData['order_date_start']) {
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...
349
            $date = $searchData['order_date_start']
350
                ->format('Y-m-d H:i:s');
351
            $qb
352
                ->andWhere('o.order_date >= :order_date_start')
353
                ->setParameter('order_date_start', $date);
354
        }
355 View Code Duplication
        if (!empty($searchData['order_date_end']) && $searchData['order_date_end']) {
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...
356
            $date = clone $searchData['order_date_end'];
357
            $date = $date
358
                ->modify('+1 days')
359
                ->format('Y-m-d H:i:s');
360
            $qb
361
                ->andWhere('o.order_date < :order_date_end')
362
                ->setParameter('order_date_end', $date);
363
        }
364
365
        // payment_date
366 View Code Duplication
        if (!empty($searchData['payment_date_start']) && $searchData['payment_date_start']) {
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...
367
            $date = $searchData['payment_date_start']
368
                ->format('Y-m-d H:i:s');
369
            $qb
370
                ->andWhere('o.payment_date >= :payment_date_start')
371
                ->setParameter('payment_date_start', $date);
372
        }
373 View Code Duplication
        if (!empty($searchData['payment_date_end']) && $searchData['payment_date_end']) {
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...
374
            $date = clone $searchData['payment_date_end'];
375
            $date = $date
376
                ->modify('+1 days')
377
                ->format('Y-m-d H:i:s');
378
            $qb
379
                ->andWhere('o.payment_date < :payment_date_end')
380
                ->setParameter('payment_date_end', $date);
381
        }
382
383
        // commit_date
384 View Code Duplication
        if (!empty($searchData['commit_date_start']) && $searchData['commit_date_start']) {
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...
385
            $date = $searchData['commit_date_start']
386
                ->format('Y-m-d H:i:s');
387
            $qb
388
                ->andWhere('o.commit_date >= :commit_date_start')
389
                ->setParameter('commit_date_start', $date);
390
        }
391 View Code Duplication
        if (!empty($searchData['commit_date_end']) && $searchData['commit_date_end']) {
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...
392
            $date = clone $searchData['commit_date_end'];
393
            $date = $date
394
                ->modify('+1 days')
395
                ->format('Y-m-d H:i:s');
396
            $qb
397
                ->andWhere('o.commit_date < :commit_date_end')
398
                ->setParameter('commit_date_end', $date);
399
        }
400
401
402
        // update_date
403 View Code Duplication
        if (!empty($searchData['update_date_start']) && $searchData['update_date_start']) {
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...
404
            $date = $searchData['update_date_start']
405
                ->format('Y-m-d H:i:s');
406
            $qb
407
                ->andWhere('o.update_date >= :update_date_start')
408
                ->setParameter('update_date_start', $date);
409
        }
410 View Code Duplication
        if (!empty($searchData['update_date_end']) && $searchData['update_date_end']) {
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...
411
            $date = clone $searchData['update_date_end'];
412
            $date = $date
413
                ->modify('+1 days')
414
                ->format('Y-m-d H:i:s');
415
            $qb
416
                ->andWhere('o.update_date < :update_date_end')
417
                ->setParameter('update_date_end', $date);
418
        }
419
420
        // payment_total
421 View Code Duplication
        if (isset($searchData['payment_total_start']) && Str::isNotBlank($searchData['payment_total_start'])) {
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...
422
            $qb
423
                ->andWhere('o.payment_total >= :payment_total_start')
424
                ->setParameter('payment_total_start', $searchData['payment_total_start']);
425
        }
426 View Code Duplication
        if (isset($searchData['payment_total_end']) && Str::isNotBlank($searchData['payment_total_end'])) {
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...
427
            $qb
428
                ->andWhere('o.payment_total <= :payment_total_end')
429
                ->setParameter('payment_total_end', $searchData['payment_total_end']);
430
        }
431
432
        // buy_product_name
433 View Code Duplication
        if (isset($searchData['buy_product_name']) && Str::isNotBlank($searchData['buy_product_name'])) {
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...
434
            $qb
435
                ->leftJoin('o.OrderDetails', 'od')
436
                ->andWhere('od.product_name LIKE :buy_product_name')
437
                ->setParameter('buy_product_name', '%' . $searchData['buy_product_name'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
438
        }
439
440
441
        // Order By
442
        $qb->addOrderBy('o.update_date', 'DESC');
443
444
        return $qb;
445
    }
446
447
448
    /**
449
     * @param  \Eccube\Entity\Customer $Customer
450
     * @return QueryBuilder
451
     */
452
    public function getQueryBuilderByCustomer(\Eccube\Entity\Customer $Customer)
453
    {
454
        $qb = $this->createQueryBuilder('o')
455
            ->where('o.Customer = :Customer')
456
            ->setParameter('Customer', $Customer);
457
458
        // Order By
459
        $qb->addOrderBy('o.id', 'DESC');
460
461
        return $qb;
462
    }
463
464
    /**
465
     * 新規受付一覧の取得
466
     *
467
     * @return \Eccube\Entity\Order[]
468
     */
469
    public function getNew()
470
    {
471
        $qb = $this->createQueryBuilder('o');
472
        $qb
473
            ->where('o.OrderStatus <> :OrderStatus')
474
            ->setParameter('OrderStatus', $this->app['config']['order_cancel'])
475
            ->setMaxResults(10)
476
            ->orderBy('o.create_date', 'DESC');
477
478
        return $qb
479
            ->getQuery()
480
            ->getResult();
481
    }
482
483
    /**
484
     * 会員の合計購入金額を取得、回数を取得
485
     *
486
     * @param  \Eccube\Entity\Customer $Customer
487
     * @param  array $OrderStatuses
0 ignored issues
show
introduced by
Expected 19 spaces after parameter type; 1 found
Loading history...
488
     * @return QueryBuilder
489
     */
490
    public function getCustomerCount(\Eccube\Entity\Customer $Customer, array $OrderStatuses)
491
    {
492
        $result = $this->createQueryBuilder('o')
493
            ->select('COUNT(o.id) AS buy_times, SUM(o.total)  AS buy_total')
494
            ->where('o.Customer = :Customer')
495
            ->andWhere('o.OrderStatus in (:OrderStatuses)')
496
            ->setParameter('Customer', $Customer)
497
            ->setParameter('OrderStatuses', $OrderStatuses)
498
            ->groupBy('o.id')
499
            ->orderBy('o.id', 'ASC')
500
            ->getQuery()
501
            ->getResult();
502
503
        return $result;
504
    }
505
}
506