Completed
Pull Request — experimental/sf (#3412)
by Kentaro
272:45 queued 265:41
created

OrderPdfService::renderOrderDetailData()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 79

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 46
CRAP Score 4.0001

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 79
ccs 46
cts 47
cp 0.9787
crap 4.0001
rs 8.4581
c 0
b 0
f 0

How to fix   Long Method   

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
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Service;
15
16
use Eccube\Application;
17
use Eccube\Common\EccubeConfig;
18
use Eccube\Entity\BaseInfo;
19
use Eccube\Entity\Order;
20
use Eccube\Entity\OrderItem;
21
use Eccube\Repository\BaseInfoRepository;
22
use Eccube\Repository\OrderRepository;
23
use Eccube\Repository\OrderPdfRepository;
24
use Eccube\Twig\Extension\EccubeExtension;
25
use setasign\Fpdi\TcpdfFpdi;
26
27
/**
28
 * Class OrderPdfService.
29
 * Do export pdf function.
30
 */
31
class OrderPdfService extends TcpdfFpdi
32
{
33
    /** @var OrderRepository */
34
    protected $orderRepository;
35
36
    /** @var OrderPdfRepository */
37
    protected $orderPdfRepository;
38
39
    /** @var TaxRuleService */
40
    protected $taxRuleService;
41
    /**
42
     * @var Application
43
     */
44
    private $eccubeConfig;
45
46
    /**
47
     * @var EccubeExtension
48
     */
49
    private $eccubeExtension;
50
51
    // ====================================
52
    // 定数宣言
53
    // ====================================
54
55
    /** ダウンロードするPDFファイルのデフォルト名 */
56
    const DEFAULT_PDF_FILE_NAME = 'nouhinsyo.pdf';
57
58
    /** FONT ゴシック */
59
    const FONT_GOTHIC = 'kozgopromedium';
60
    /** FONT 明朝 */
61
    const FONT_SJIS = 'kozminproregular';
62
63
    // ====================================
64
    // 変数宣言
65
    // ====================================
66
67
    /** @var BaseInfo */
68
    public $baseInfoRepository;
69
70
    /** 購入詳細情報 ラベル配列
71
     * @var array
72
     */
73
    private $labelCell = [];
74
75
    /*** 購入詳細情報 幅サイズ配列
76
     * @var array
77
     */
78
    private $widthCell = [];
79
80
    /** 最後に処理した注文番号 @var string */
81
    private $lastOrderId = null;
82
83
    // --------------------------------------
84
    // Font情報のバックアップデータ
85
    /** @var string フォント名 */
86
    private $bakFontFamily;
87
    /** @var string フォントスタイル */
88
    private $bakFontStyle;
89
    /** @var string フォントサイズ */
90
    private $bakFontSize;
91
    // --------------------------------------
92
93
    // lfTextのoffset
94
    private $baseOffsetX = 0;
95
    private $baseOffsetY = -4;
96
97
    /** ダウンロードファイル名 @var string */
98
    private $downloadFileName = null;
99
100
    /** 発行日 @var string */
101
    private $issueDate = '';
102
103
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$eccubeExtension" missing
Loading history...
104
     * OrderPdfService constructor.
105
     *
106
     * @param EccubeConfig $eccubeConfig
0 ignored issues
show
introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
107
     * @param OrderRepository $orderRepository
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
108
     * @param TaxRuleService $taxRuleService
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
109
     * @param BaseInfoRepository $baseInfoRepository
110
     */
111 28
    public function __construct(EccubeConfig $eccubeConfig, OrderRepository $orderRepository, TaxRuleService $taxRuleService, BaseInfoRepository $baseInfoRepository, EccubeExtension $eccubeExtension)
112
    {
113 28
        $this->eccubeConfig = $eccubeConfig;
0 ignored issues
show
Documentation Bug introduced by
It seems like $eccubeConfig of type object<Eccube\Common\EccubeConfig> is incompatible with the declared type object<Eccube\Application> of property $eccubeConfig.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
114 28
        $this->baseInfoRepository = $baseInfoRepository->get();
115 28
        $this->orderRepository = $orderRepository;
116 28
        $this->taxRuleService = $taxRuleService;
117 28
        $this->eccubeExtension = $eccubeExtension;
118 28
        parent::__construct();
119
120
        // 購入詳細情報の設定を行う
121
        // 動的に入れ替えることはない
122 28
        $this->labelCell[] = '商品名 / 商品コード / [ 規格 ]';
123 28
        $this->labelCell[] = '数量';
124 28
        $this->labelCell[] = '単価';
125 28
        $this->labelCell[] = '金額(税込)';
126 28
        $this->widthCell = [110.3, 12, 21.7, 24.5];
127
128
        // Fontの設定しておかないと文字化けを起こす
129 28
        $this->SetFont(self::FONT_SJIS);
130
131
        // PDFの余白(上左右)を設定
132 28
        $this->SetMargins(15, 20);
133
134
        // ヘッダーの出力を無効化
135 28
        $this->setPrintHeader(false);
136
137
        // フッターの出力を無効化
138 28
        $this->setPrintFooter(true);
139 28
        $this->setFooterMargin();
140 28
        $this->setFooterFont([self::FONT_SJIS, '', 8]);
141
    }
142
143
    /**
144
     * 注文情報からPDFファイルを作成する.
145
     *
146
     * @param array $formData
147
     *                        [KEY]
148
     *                        ids: 注文番号
149
     *                        issue_date: 発行日
150
     *                        title: タイトル
151
     *                        message1: メッセージ1行目
152
     *                        message2: メッセージ2行目
153
     *                        message3: メッセージ3行目
154
     *                        note1: 備考1行目
155
     *                        note2: 備考2行目
156
     *                        note3: 備考3行目
157
     *
158
     * @return bool
159
     */
160 3
    public function makePdf(array $formData)
161
    {
162
        // 発行日の設定
163 3
        $this->issueDate = '作成日: '.$formData['issue_date']->format('Y年m月d日');
164
        // ダウンロードファイル名の初期化
165 3
        $this->downloadFileName = null;
166
167
        // データが空であれば終了
168 3
        if (!$formData['ids']) {
169
            return false;
170
        }
171
172
        // 注文番号をStringからarrayに変換
173 3
        $ids = explode(',', $formData['ids']);
174
175
        // 空文字列の場合のデフォルトメッセージを設定する
176 3
        $this->setDefaultData($formData);
177
178
        // テンプレートファイルを読み込む
179 3
        $userPath = $this->eccubeConfig->get('eccube_html_admin_dir').'/assets/pdf/nouhinsyo1.pdf';
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<Eccube\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
180 3
        $this->setSourceFile($userPath);
181
182 3
        foreach ($ids as $id) {
183 3
            $this->lastOrderId = $id;
184
185
            // 注文番号から受注情報を取得する
186
            /** @var Order $order */
187 3
            $order = $this->orderRepository->find($id);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $order is correct as $this->orderRepository->find($id) (which targets Doctrine\ORM\EntityRepository::find()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
188 3
            if (!$order) {
189
                // 注文情報の取得ができなかった場合
190
                continue;
191
            }
192
193
            // PDFにページを追加する
194 3
            $this->addPdfPage();
195
196
            // タイトルを描画する
197 3
            $this->renderTitle($formData['title']);
198
199
            // 店舗情報を描画する
200 3
            $this->renderShopData();
201
202
            // 注文情報を描画する
203 3
            $this->renderOrderData($order);
204
205
            // メッセージを描画する
206 3
            $this->renderMessageData($formData);
207
208
            // 受注詳細情報を描画する
209 3
            $this->renderOrderDetailData($order);
210
211
            // 備考を描画する
212 3
            $this->renderEtcData($formData);
213
        }
214
215 3
        return true;
216
    }
217
218
    /**
219
     * PDFファイルを出力する.
220
     *
221
     * @return string|mixed
222
     */
223 3
    public function outputPdf()
224
    {
225 3
        return $this->Output($this->getPdfFileName(), 'S');
226
    }
227
228
    /**
229
     * PDFファイル名を取得する
230
     * PDFが1枚の時は注文番号をファイル名につける.
231
     *
232
     * @return string ファイル名
233
     */
234 3
    public function getPdfFileName()
235
    {
236 3
        if (!is_null($this->downloadFileName)) {
237 3
            return $this->downloadFileName;
238
        }
239 3
        $this->downloadFileName = self::DEFAULT_PDF_FILE_NAME;
240 3
        if ($this->PageNo() == 1) {
241 3
            $this->downloadFileName = 'nouhinsyo-No'.$this->lastOrderId.'.pdf';
242
        }
243
244 3
        return $this->downloadFileName;
245
    }
246
247
    /**
248
     * フッターに発行日を出力する.
249
     */
250 3
    public function Footer()
0 ignored issues
show
Coding Style introduced by
Method name "OrderPdfService::Footer" is not in camel caps format
Loading history...
251
    {
252 3
        $this->Cell(0, 0, $this->issueDate, 0, 0, 'R');
253
    }
254
255
    /**
256
     * 作成するPDFのテンプレートファイルを指定する.
257
     */
258 3
    protected function addPdfPage()
259
    {
260
        // ページを追加
261 3
        $this->AddPage();
262
263
        // テンプレートに使うテンプレートファイルのページ番号を取得
264 3
        $tplIdx = $this->importPage(1);
265
266
        // テンプレートに使うテンプレートファイルのページ番号を指定
267 3
        $this->useTemplate($tplIdx, null, null, null, null, true);
268
    }
269
270
    /**
271
     * PDFに店舗情報を設定する
272
     * ショップ名、ロゴ画像以外はdtb_helpに登録されたデータを使用する.
273
     */
274 3
    protected function renderShopData()
275
    {
276
        // 基準座標を設定する
277 3
        $this->setBasePosition();
278
279
        // ショップ名
280 3
        $this->lfText(125, 60, $this->baseInfoRepository->getShopName(), 8, 'B');
281
282
        // 都道府県+所在地
283 3
        $text = $this->baseInfoRepository->getAddr01();
284 3
        $this->lfText(125, 65, $text, 8);
285 3
        $this->lfText(125, 69, $this->baseInfoRepository->getAddr02(), 8);
286
287
        // 電話番号
288 3
        $text = 'TEL: '.$this->baseInfoRepository->getPhoneNumber();
289 3
        $this->lfText(125, 72, $text, 8);  //TEL・FAX
290
291
        // メールアドレス
292 3
        if (strlen($this->baseInfoRepository->getEmail01()) > 0) {
293 3
            $text = 'Email: '.$this->baseInfoRepository->getEmail01();
294 3
            $this->lfText(125, 75, $text, 8);      // Email
295
        }
296
297
        // ロゴ画像(app配下のロゴ画像を優先して読み込む)
298 3
        $logoFile = $this->eccubeConfig->get('eccube_html_admin_dir').'/assets/pdf/logo.png';
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<Eccube\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
299 3
        $this->Image($logoFile, 124, 46, 40);
300
    }
301
302
    /**
303
     * メッセージを設定する.
304
     *
305
     * @param array $formData
306
     */
307 3
    protected function renderMessageData(array $formData)
308
    {
309 3
        $this->lfText(27, 70, $formData['message1'], 8);  //メッセージ1
310 3
        $this->lfText(27, 74, $formData['message2'], 8);  //メッセージ2
311 3
        $this->lfText(27, 78, $formData['message3'], 8);  //メッセージ3
312
    }
313
314
    /**
315
     * PDFに備考を設定数.
316
     *
317
     * @param array $formData
318
     */
319 3
    protected function renderEtcData(array $formData)
320
    {
321
        // フォント情報のバックアップ
322 3
        $this->backupFont();
323
324 3
        $this->Cell(0, 10, '', 0, 1, 'C', 0, '');
325
326 3
        $this->SetFont(self::FONT_GOTHIC, 'B', 9);
327 3
        $this->MultiCell(0, 6, '< 備考 >', 'T', 2, 'L', 0, '');
328
329 3
        $this->SetFont(self::FONT_SJIS, '', 8);
330
331 3
        $this->Ln();
332
        // rtrimを行う
333 3
        $text = preg_replace('/\s+$/us', '', $formData['note1']."\n".$formData['note2']."\n".$formData['note3']);
334 3
        $this->MultiCell(0, 4, $text, '', 2, 'L', 0, '');
335
336
        // フォント情報の復元
337 3
        $this->restoreFont();
338
    }
339
340
    /**
341
     * タイトルをPDFに描画する.
342
     *
343
     * @param string $title
344
     */
345 3
    protected function renderTitle($title)
346
    {
347
        // 基準座標を設定する
348 3
        $this->setBasePosition();
349
350
        // フォント情報のバックアップ
351 3
        $this->backupFont();
352
353
        //文書タイトル(納品書・請求書)
354 3
        $this->SetFont(self::FONT_GOTHIC, '', 15);
355 3
        $this->Cell(0, 10, $title, 0, 2, 'C', 0, '');
356 3
        $this->Cell(0, 66, '', 0, 2, 'R', 0, '');
357 3
        $this->Cell(5, 0, '', 0, 0, 'R', 0, '');
358
359
        // フォント情報の復元
360 3
        $this->restoreFont();
361
    }
362
363
    /**
364
     * 購入者情報を設定する.
365
     *
366
     * @param Order $Order
367
     */
368 3
    protected function renderOrderData(Order $Order)
369
    {
370
        // 基準座標を設定する
371 3
        $this->setBasePosition();
372
373
        // フォント情報のバックアップ
374 3
        $this->backupFont();
375
376
        // =========================================
377
        // 購入者情報部
378
        // =========================================
379
380
        // 購入者都道府県+住所1
381 3
        $text = $Order->getPref().$Order->getAddr01();
382 3
        $this->lfText(27, 47, $text, 10);
383 3
        $this->lfText(27, 51, $Order->getAddr02(), 10); //購入者住所2
384
385
        // 購入者氏名
386 3
        $text = $Order->getName01().' '.$Order->getName02().' 様';
387 3
        $this->lfText(27, 59, $text, 11);
388
389
        // =========================================
390
        // お買い上げ明細部
391
        // =========================================
392 3
        $this->SetFont(self::FONT_SJIS, '', 10);
393
394
        //ご注文日
395 3
        $orderDate = $Order->getCreateDate()->format('Y/m/d H:i');
396 3
        if ($Order->getOrderDate()) {
397
            $orderDate = $Order->getOrderDate()->format('Y/m/d H:i');
398
        }
399
400 3
        $this->lfText(25, 125, $orderDate, 10);
401
        //注文番号
402 3
        $this->lfText(25, 135, $Order->getId(), 10);
403
404
        // 総合計金額
405 3
        $this->SetFont(self::FONT_SJIS, 'B', 15);
406 3
        $paymentTotalText = $this->eccubeExtension->getPriceFilter($Order->getPaymentTotal());
407
408 3
        $this->setBasePosition(120, 95.5);
409 3
        $this->Cell(5, 7, '', 0, 0, '', 0, '');
410 3
        $this->Cell(67, 8, $paymentTotalText, 0, 2, 'R', 0, '');
411 3
        $this->Cell(0, 45, '', 0, 2, '', 0, '');
412
413
        // フォント情報の復元
414 3
        $this->restoreFont();
415
    }
416
417
    /**
418
     * 購入商品詳細情報を設定する.
419
     *
420
     * @param Order $Order
421
     */
422 3
    protected function renderOrderDetailData(Order $Order)
423
    {
424 3
        $arrOrder = [];
425
        // テーブルの微調整を行うための購入商品詳細情報をarrayに変換する
426
427
        // =========================================
428
        // 受注詳細情報
429
        // =========================================
430 3
        $i = 0;
431
        /* @var OrderItem $OrderItem */
432 3
        foreach ($Order->getOrderItems() as $OrderItem) {
433
            // class categoryの生成
434 3
            $classCategory = '';
435
            /** @var OrderItem $OrderItem */
436 3
            if ($OrderItem->getClassCategoryName1()) {
437 3
                $classCategory .= ' [ '.$OrderItem->getClassCategoryName1();
438 3
                if ($OrderItem->getClassCategoryName2() == '') {
439 3
                    $classCategory .= ' ]';
440
                } else {
441
                    $classCategory .= ' * '.$OrderItem->getClassCategoryName2().' ]';
442
                }
443
            }
444
            // 税
445 3
            $tax = $this->taxRuleService->calcTax($OrderItem->getPrice(), $OrderItem->getTaxRate(), \Eccube\Entity\Master\RoundingType::ROUND);
446 3
            $OrderItem->setPriceIncTax($OrderItem->getPrice() + $tax);
447
448
            // product
449 3
            $arrOrder[$i][0] = sprintf('%s / %s / %s', $OrderItem->getProductName(), $OrderItem->getProductCode(), $classCategory);
450
            // 購入数量
451 3
            $arrOrder[$i][1] = number_format($OrderItem->getQuantity());
452
            // 税込金額(単価)
453 3
            $arrOrder[$i][2] = $this->eccubeExtension->getPriceFilter($OrderItem->getPriceIncTax());
454
            // 小計(商品毎)
455 3
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($OrderItem->getTotalPrice());
456
457 3
            ++$i;
458
        }
459
460
        // =========================================
461
        // 小計
462
        // =========================================
463 3
        $arrOrder[$i][0] = '';
464 3
        $arrOrder[$i][1] = '';
465 3
        $arrOrder[$i][2] = '';
466 3
        $arrOrder[$i][3] = '';
467
468 3
        ++$i;
469 3
        $arrOrder[$i][0] = '';
470 3
        $arrOrder[$i][1] = '';
471 3
        $arrOrder[$i][2] = '商品合計';
472 3
        $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getSubtotal());
473
474 3
        ++$i;
475 3
        $arrOrder[$i][0] = '';
476 3
        $arrOrder[$i][1] = '';
477 3
        $arrOrder[$i][2] = '送料';
478 3
        $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getDeliveryFeeTotal());
479
480 3
        ++$i;
481 3
        $arrOrder[$i][0] = '';
482 3
        $arrOrder[$i][1] = '';
483 3
        $arrOrder[$i][2] = '手数料';
484 3
        $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getCharge());
485
486 3
        ++$i;
487 3
        $arrOrder[$i][0] = '';
488 3
        $arrOrder[$i][1] = '';
489 3
        $arrOrder[$i][2] = '値引き';
490 3
        $arrOrder[$i][3] = '- '.$this->eccubeExtension->getPriceFilter($Order->getDiscount());
491
492 3
        ++$i;
493 3
        $arrOrder[$i][0] = '';
494 3
        $arrOrder[$i][1] = '';
495 3
        $arrOrder[$i][2] = '請求金額';
496 3
        $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getPaymentTotal());
497
498
        // PDFに設定する
499 3
        $this->setFancyTable($this->labelCell, $arrOrder, $this->widthCell);
500
    }
501
502
    /**
503
     * PDFへのテキスト書き込み
504
     *
505
     * @param int    $x     X座標
506
     * @param int    $y     Y座標
507
     * @param string $text  テキスト
508
     * @param int    $size  フォントサイズ
509
     * @param string $style フォントスタイル
510
     */
511 3
    protected function lfText($x, $y, $text, $size = 0, $style = '')
512
    {
513
        // 退避
514 3
        $bakFontStyle = $this->FontStyle;
515 3
        $bakFontSize = $this->FontSizePt;
516
517 3
        $this->SetFont('', $style, $size);
518 3
        $this->Text($x + $this->baseOffsetX, $y + $this->baseOffsetY, $text);
519
520
        // 復元
521 3
        $this->SetFont('', $bakFontStyle, $bakFontSize);
522
    }
523
524
    /**
525
     * Colored table.
526
     *
527
     * TODO: 後の列の高さが大きい場合、表示が乱れる。
528
     *
529
     * @param array $header 出力するラベル名一覧
530
     * @param array $data   出力するデータ
531
     * @param array $w      出力するセル幅一覧
532
     */
533 3
    protected function setFancyTable($header, $data, $w)
534
    {
535
        // フォント情報のバックアップ
536 3
        $this->backupFont();
537
538
        // 開始座標の設定
539 3
        $this->setBasePosition(0, 149);
540
541
        // Colors, line width and bold font
542 3
        $this->SetFillColor(216, 216, 216);
543 3
        $this->SetTextColor(0);
544 3
        $this->SetDrawColor(0, 0, 0);
545 3
        $this->SetLineWidth(.3);
546 3
        $this->SetFont(self::FONT_SJIS, 'B', 8);
547 3
        $this->SetFont('', 'B');
548
549
        // Header
550 3
        $this->Cell(5, 7, '', 0, 0, '', 0, '');
551 3
        $count = count($header);
552 3
        for ($i = 0; $i < $count; ++$i) {
553 3
            $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
554
        }
555 3
        $this->Ln();
556
557
        // Color and font restoration
558 3
        $this->SetFillColor(235, 235, 235);
559 3
        $this->SetTextColor(0);
560 3
        $this->SetFont('');
561
        // Data
562 3
        $fill = 0;
563 3
        $h = 4;
564 3
        foreach ($data as $row) {
565
            // 行のの処理
566 3
            $i = 0;
567 3
            $h = 4;
568 3
            $this->Cell(5, $h, '', 0, 0, '', 0, '');
569
570
            // Cellの高さを保持
571 3
            $cellHeight = 0;
572 3
            foreach ($row as $col) {
573
                // 列の処理
574
                // TODO: 汎用的ではない処理。この指定は呼び出し元で行うようにしたい。
575
                // テキストの整列を指定する
576 3
                $align = ($i == 0) ? 'L' : 'R';
577
578
                // セル高さが最大値を保持する
579 3
                if ($h >= $cellHeight) {
580 3
                    $cellHeight = $h;
581
                }
582
583
                // 最終列の場合は次の行へ移動
584
                // (0: 右へ移動(既定)/1: 次の行へ移動/2: 下へ移動)
585 3
                $ln = ($i == (count($row) - 1)) ? 1 : 0;
586
587 3
                $this->MultiCell(
588 3
                    $w[$i],             // セル幅
589 3
                    $cellHeight,        // セルの最小の高さ
590 3
                    $col,               // 文字列
591 3
                    1,                  // 境界線の描画方法を指定
592 3
                    $align,             // テキストの整列
593 3
                    $fill,              // 背景の塗つぶし指定
594 3
                    $ln                 // 出力後のカーソルの移動方法
595
                );
596 3
                $h = $this->getLastH();
597
598 3
                ++$i;
599
            }
600 3
            $fill = !$fill;
601
        }
602 3
        $this->Cell(5, $h, '', 0, 0, '', 0, '');
603 3
        $this->Cell(array_sum($w), 0, '', 'T');
604 3
        $this->SetFillColor(255);
605
606
        // フォント情報の復元
607 3
        $this->restoreFont();
608
    }
609
610
    /**
611
     * 基準座標を設定する.
612
     *
613
     * @param int $x
614
     * @param int $y
615
     */
616 3
    protected function setBasePosition($x = null, $y = null)
617
    {
618
        // 現在のマージンを取得する
619 3
        $result = $this->getMargins();
620
621
        // 基準座標を指定する
622 3
        $actualX = is_null($x) ? $result['left'] : $x;
623 3
        $this->SetX($actualX);
624 3
        $actualY = is_null($y) ? $result['top'] : $y;
625 3
        $this->SetY($actualY);
626
    }
627
628
    /**
629
     * データが設定されていない場合にデフォルト値を設定する.
630
     *
631
     * @param array $formData
632
     */
633 3
    protected function setDefaultData(array &$formData)
634
    {
635
        $defaultList = [
636 3
            'title' => trans('admin.order.export.pdf.title.default'),
637 3
            'message1' => trans('admin.order.export.pdf.message1.default'),
638 3
            'message2' => trans('admin.order.export.pdf.message2.default'),
639 3
            'message3' => trans('admin.order.export.pdf.message3.default'),
640
        ];
641
642 3
        foreach ($defaultList as $key => $value) {
643 3
            if (is_null($formData[$key])) {
644 3
                $formData[$key] = $value;
645
            }
646
        }
647
    }
648
649
    /**
650
     * Font情報のバックアップ.
651
     */
652 3
    protected function backupFont()
653
    {
654
        // フォント情報のバックアップ
655 3
        $this->bakFontFamily = $this->FontFamily;
656 3
        $this->bakFontStyle = $this->FontStyle;
657 3
        $this->bakFontSize = $this->FontSizePt;
658
    }
659
660
    /**
661
     * Font情報の復元.
662
     */
663 3
    protected function restoreFont()
664
    {
665 3
        $this->SetFont($this->bakFontFamily, $this->bakFontStyle, $this->bakFontSize);
666
    }
667
}
668