Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — dev-extbase-fluid (#720)
by Alexander
03:15 queued 21s
created

BasketController   F

Complexity

Total Complexity 92

Size/Duplication

Total Lines 653
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 92
eloc 375
c 3
b 0
f 0
dl 0
loc 653
rs 2

10 Methods

Rating   Name   Duplication   Size   Complexity  
B printDocument() 0 71 7
B sendMail() 0 88 7
B removeFromBasket() 0 35 8
C getDocumentData() 0 57 14
B mainAction() 0 71 9
A getEntry() 0 42 4
F addToBasket() 0 87 25
A getBasketData() 0 48 4
B basketAction() 0 43 11
A addAction() 0 17 3

How to fix   Complexity   

Complex Class

Complex classes like BasketController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use BasketController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Controller;
14
15
use Kitodo\Dlf\Common\Document;
16
use Kitodo\Dlf\Common\Helper;
17
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
18
use TYPO3\CMS\Core\Database\Connection;
19
use TYPO3\CMS\Core\Database\ConnectionPool;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Utility\LocalizationUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
class BasketController extends AbstractController
24
{
25
    /**
26
     * Different actions which depends on the choosen action (form)
27
     *
28
     * @return void
29
     */
30
    public function basketAction()
31
    {
32
        $requestData = GeneralUtility::_GPmerged('tx_dlf');
33
        unset($requestData['__referrer'], $requestData['__trustedProperties']);
34
35
        $basketData = $this->getBasketData();
36
37
        // action remove from basket
38
        if ($requestData['basket_action'] === 'remove') {
39
            // remove entry from list
40
            if (isset($requestData['selected'])) {
41
                $basketData = $this->removeFromBasket($requestData, $basketData);
42
            }
43
        }
44
        // action remove from basket
45
        if ($requestData['basket_action'] == 'download') {
46
            // open selected documents
47
            if (isset($requestData['selected'])) {
48
                $pdfUrl = $this->settings['pdfgenerate'];
49
                foreach ($requestData['selected'] as $docValue) {
50
                    if ($docValue['id']) {
51
                        $docData = $this->getDocumentData($docValue['id'], $docValue);
52
                        $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
53
                        $this->redirectToUri($pdfUrl);
54
                    }
55
                }
56
            }
57
        }
58
        // action print from basket
59
        if ($requestData['print_action']) {
60
            // open selected documents
61
            if (isset($requestData['selected'])) {
62
                $this->printDocument($requestData, $basketData);
63
            }
64
        }
65
        // action send mail
66
        if ($requestData['mail_action']) {
67
            if (isset($requestData['selected'])) {
68
                $this->sendMail($requestData);
69
            }
70
        }
71
72
        $this->redirect('main');
73
    }
74
75
    /**
76
     * Add documents to the basket
77
     *
78
     * @return void
79
     */
80
    public function addAction()
81
    {
82
        $requestData = GeneralUtility::_GPmerged('tx_dlf');
83
        unset($requestData['__referrer'], $requestData['__trustedProperties']);
84
85
        $basketData = $this->getBasketData();
86
87
        if (
88
            !empty($requestData['id'])
89
            && $requestData['addToBasket']
90
        ) {
91
            $returnData = $this->addToBasket($requestData, $basketData);
92
            $basketData = $returnData['basketData'];
0 ignored issues
show
Unused Code introduced by
The assignment to $basketData is dead and can be removed.
Loading history...
93
            $this->view->assign('pregenerateJs', $returnData['jsOutput']);
94
        }
95
96
        $this->redirect('main');
97
    }
98
99
    /**
100
     * The main method of the plugin
101
     *
102
     * @return void
103
     */
104
    public function mainAction()
105
    {
106
        $requestData = GeneralUtility::_GPmerged('tx_dlf');
107
        unset($requestData['__referrer'], $requestData['__trustedProperties']);
108
109
        $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf');
0 ignored issues
show
Bug Best Practice introduced by
The property extConf does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
110
111
        $basketData = $this->getBasketData();
112
113
        if ($basketData['doc_ids']) {
114
            if (is_object($basketData['doc_ids'])) {
115
                $basketData['doc_ids'] = get_object_vars($basketData['doc_ids']);
116
            }
117
            $count = sprintf(LocalizationUtility::translate('basket.count', 'dlf'), count($basketData['doc_ids']));
118
        } else {
119
            $count = sprintf(LocalizationUtility::translate('basket.count', 'dlf'), 0);
120
        }
121
        $this->view->assign('count', $count);
122
123
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
124
            ->getQueryBuilderForTable('tx_dlf_mail');
125
126
        // get mail addresses
127
        $resultMail = $queryBuilder
128
            ->select('*')
129
            ->from('tx_dlf_mail')
130
            ->where(
131
                '1=1',
132
                Helper::whereExpression('tx_dlf_mail')
133
            )
134
            ->orderBy('tx_dlf_mail.sorting')
135
            ->execute();
136
137
        $mailSelect = [];
138
        if ($resultMail->rowCount() > 0) {
139
            $mailSelect[0] = htmlspecialchars(LocalizationUtility::translate('basket.chooseMail', 'dlf'));
140
            while ($row = $resultMail->fetch()) {
141
                $mailSelect[$row['uid']] = htmlspecialchars($row['name']) . ' (' . htmlspecialchars($row['mail']) . ')';
142
            }
143
            $this->view->assign('mailSelect', $mailSelect);
144
        }
145
146
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
147
            ->getQueryBuilderForTable('tx_dlf_printer');
148
149
        // get mail addresses
150
        $resultPrinter = $queryBuilder
151
            ->select('*')
152
            ->from('tx_dlf_printer')
153
            ->where(
154
                '1=1',
155
                Helper::whereExpression('tx_dlf_printer')
156
            )
157
            ->execute();
158
159
        $printSelect = [];
160
        if ($resultPrinter->rowCount() > 0) {
161
            $printSelect[0] = htmlspecialchars(LocalizationUtility::translate('basket.choosePrinter', 'dlf'));
162
            while ($row = $resultPrinter->fetch()) {
163
                $printSelect[$row['uid']] = htmlspecialchars($row['label']);
164
            }
165
            $this->view->assign('printSelect', $printSelect);
166
        }
167
168
        $entries = [];
169
        if (isset($basketData['doc_ids'])) {
170
            // get each entry
171
            foreach ($basketData['doc_ids'] as $value) {
172
                $entries[] = $this->getEntry($value);
173
            }
174
            $this->view->assign('entries', $entries);
175
        }
176
    }
177
178
    /**
179
     * The basket data from user session.
180
     *
181
     * @return array The found data from user session.
182
     */
183
    protected function getBasketData() {
184
        // get user session
185
        $sessionId = $GLOBALS['TSFE']->fe_user->id;
186
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
187
            ->getQueryBuilderForTable('tx_dlf_basket');
188
189
        if ($GLOBALS['TSFE']->loginUser) {
190
            $result = $queryBuilder
191
                ->select('*')
192
                ->from('tx_dlf_basket')
193
                ->where(
194
                    $queryBuilder->expr()->eq('tx_dlf_basket.fe_user_id', (int) $GLOBALS['TSFE']->fe_user->user['uid']),
195
                    Helper::whereExpression('tx_dlf_basket')
196
                )
197
                ->setMaxResults(1)
198
                ->execute();
199
        } else {
200
            $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_dlf_basket', '');
201
            $GLOBALS['TSFE']->fe_user->sesData_change = true;
202
            $GLOBALS['TSFE']->fe_user->storeSessionData();
203
            $result = $queryBuilder
204
                ->select('*')
205
                ->from('tx_dlf_basket')
206
                ->where(
207
                    $queryBuilder->expr()->eq('tx_dlf_basket.session_id', $queryBuilder->createNamedParameter($sessionId)),
208
                    Helper::whereExpression('tx_dlf_basket')
209
                )
210
                ->setMaxResults(1)
211
                ->execute();
212
        }
213
        // session already exists
214
        if ($result->rowCount() === 0) {
215
            // create new basket in db
216
            $insertArray['fe_user_id'] = $GLOBALS['TSFE']->loginUser ? $GLOBALS['TSFE']->fe_user->user['uid'] : 0;
217
            $insertArray['session_id'] = $sessionId;
218
            $insertArray['doc_ids'] = '';
219
            $insertArray['label'] = '';
220
            $insertArray['l18n_diffsource'] = '';
221
            GeneralUtility::makeInstance(ConnectionPool::class)
222
                ->getConnectionForTable('tx_dlf_basket')
223
                ->insert(
224
                    'tx_dlf_basket',
225
                    $insertArray
226
                );
227
        }
228
        $basketData = $result->fetchAll()[0];
229
        $basketData['doc_ids'] = json_decode($basketData['doc_ids']);
230
        return $basketData;
231
    }
232
233
    /**
234
     * Return one basket entry
235
     *
236
     * @access protected
237
     *
238
     * @param array $data: DocumentData
239
     * @param array $template: Template information
240
     *
241
     * @return string One basket entry
242
     */
243
    protected function getEntry($data)
244
    {
245
        if (is_object($data)) {
246
            $data = get_object_vars($data);
247
        }
248
        $id = $data['id'];
249
        $startpage = $data['startpage'];
250
        $endpage = $data['endpage'];
251
        $startX = $data['startX'];
252
        $startY = $data['startY'];
253
        $endX = $data['endX'];
254
        $endY = $data['endY'];
255
        $rotation = $data['rotation'];
256
257
        $docData = $this->getDocumentData($id, $data);
258
259
        $entryArray['BASKETDATA'] = $docData;
260
261
        $entryKey = $id . '_' . $startpage;
262
        if (!empty($startX)) {
263
            $entryKey .= '_' . $startX;
264
        }
265
        if (!empty($endX)) {
266
            $entryKey .= '_' . $endX;
267
        }
268
269
        $entryArray['id'] = $id;
270
        $entryArray['CONTROLS'] = [
271
            'startpage' => $startpage,
272
            'endpage' => $endpage,
273
            'startX' => $startX,
274
            'startY' => $startY,
275
            'endX' => $endX,
276
            'endY' => $endY,
277
            'rotation' => $rotation,
278
        ];
279
280
        $entryArray['NUMBER'] = $docData['record_id'];
281
        $entryArray['key'] = $entryKey;
282
283
        // return one entry
284
        return $entryArray;
285
    }
286
287
    /**
288
     * Returns the downloadurl configured in the basket
289
     *
290
     * @access protected
291
     *
292
     * @param int $id: Document id
293
     *
294
     * @return mixed download url or false
295
     */
296
    protected function getDocumentData($id, $data)
297
    {
298
        // get document instance to load further information
299
        $document = Document::getInstance($id, 0);
300
        if ($document) {
0 ignored issues
show
introduced by
$document is of type Kitodo\Dlf\Common\Document, thus it always evaluated to true.
Loading history...
301
            // replace url param placeholder
302
            $urlParams = str_replace("##page##", (int) $data['page'], $this->settings['pdfparams']);
303
            $urlParams = str_replace("##docId##", $document->recordId, $urlParams);
304
            $urlParams = str_replace("##startpage##", (int) $data['startpage'], $urlParams);
305
            if ($data['startpage'] != $data['endpage']) {
306
                $urlParams = str_replace("##endpage##", $data['endpage'] === "" ? "" : (int) $data['endpage'], $urlParams);
307
            } else {
308
                // remove parameter endpage
309
                $urlParams = str_replace(",##endpage##", '', $urlParams);
310
            }
311
            $urlParams = str_replace("##startx##", $data['startX'] === "" ? "" : (int) $data['startX'], $urlParams);
312
            $urlParams = str_replace("##starty##", $data['startY'] === "" ? "" : (int) $data['startY'], $urlParams);
313
            $urlParams = str_replace("##endx##", $data['endX'] === "" ? "" : (int) $data['endX'], $urlParams);
314
            $urlParams = str_replace("##endy##", $data['endY'] === "" ? "" : (int) $data['endY'], $urlParams);
315
            $urlParams = str_replace("##rotation##", $data['rotation'] === "" ? "" : (int) $data['rotation'], $urlParams);
316
317
            $downloadUrl = $this->settings['pdfgenerate'] . $urlParams;
318
319
            $title = $document->getTitle($id, true);
320
            if (empty($title)) {
321
                $title = LocalizationUtility::translate('basket.noTitle', 'dlf');
322
            }
323
324
            // Set page and cutout information
325
            $info = '';
326
            if ($data['startX'] != '' && $data['endX'] != '') {
327
                // cutout
328
                $info .= htmlspecialchars(LocalizationUtility::translate('basket.cutout', 'dlf')) . ' ';
329
            }
330
            if ($data['startpage'] == $data['endpage']) {
331
                // One page
332
                $info .= htmlspecialchars(LocalizationUtility::translate('page', 'dlf')) . ' ' . $data['startpage'];
333
            } else {
334
                $info .= htmlspecialchars(LocalizationUtility::translate('page', 'dlf')) . ' ' . $data['startpage'] . '-' . $data['endpage'];
335
            }
336
            $downloadLink = '<a href="' . $downloadUrl . '" target="_blank">' . htmlspecialchars($title) . '</a> (' . $info . ')';
337
            if ($data['startpage'] == $data['endpage']) {
338
                $pageNums = 1;
339
            } else {
340
                $pageNums = $data['endpage'] - $data['startpage'];
341
            }
342
            return [
343
                'downloadUrl' => $downloadUrl,
344
                'title' => $title,
345
                'info' => $info,
346
                'downloadLink' => $downloadLink,
347
                'pageNums' => $pageNums,
348
                'urlParams' => $urlParams,
349
                'record_id' => $document->recordId,
350
            ];
351
        }
352
        return false;
353
    }
354
355
    /**
356
     * Adds documents to the basket
357
     *
358
     * @access protected
359
     *
360
     * @param array $_piVars: piVars
361
     * @param array $basketData: basket data
362
     *
363
     * @return array Basket data and Javascript output
364
     */
365
    protected function addToBasket($_piVars, $basketData)
366
    {
367
        $output = '';
368
        if (!$_piVars['startpage']) {
369
            $page = 0;
370
        } else {
371
            $page = (int) $_piVars['startpage'];
372
        }
373
        if ($page != null || $_piVars['addToBasket'] == 'list') {
374
            $documentItem = [
375
                'id' => (int) $_piVars['id'],
376
                'startpage' => (int) $_piVars['startpage'],
377
                'endpage' => !isset($_piVars['endpage']) || $_piVars['endpage'] === "" ? "" : (int) $_piVars['endpage'],
378
                'startX' => !isset($_piVars['startX']) || $_piVars['startX'] === "" ? "" : (int) $_piVars['startX'],
379
                'startY' => !isset($_piVars['startY']) || $_piVars['startY'] === "" ? "" : (int) $_piVars['startY'],
380
                'endX' => !isset($_piVars['endX']) || $_piVars['endX'] === "" ? "" : (int) $_piVars['endX'],
381
                'endY' => !isset($_piVars['endY']) || $_piVars['endY'] === "" ? "" : (int) $_piVars['endY'],
382
                'rotation' => !isset($_piVars['rotation']) || $_piVars['rotation'] === "" ? "" : (int) $_piVars['rotation']
383
            ];
384
            // update basket
385
            if (!empty($basketData['doc_ids'])) {
386
                $items = $basketData['doc_ids'];
387
                $items = get_object_vars($items);
388
            } else {
389
                $items = [];
390
            }
391
            // get document instance to load further information
392
            $document = Document::getInstance($documentItem['id'], 0);
393
            // set endpage for toc and subentry based on logid
394
            if (($_piVars['addToBasket'] == 'subentry') or ($_piVars['addToBasket'] == 'toc')) {
395
                $smLinks = $document->smLinks;
396
                $pageCounter = sizeof($smLinks['l2p'][$_piVars['logId']]);
397
                $documentItem['endpage'] = ($documentItem['startpage'] + $pageCounter) - 1;
398
            }
399
            // add whole document
400
            if ($_piVars['addToBasket'] == 'list') {
401
                $documentItem['endpage'] = $document->numPages;
402
            }
403
            $arrayKey = $documentItem['id'] . '_' . $page;
404
            if (!empty($documentItem['startX'])) {
405
                $arrayKey .= '_' . $documentItem['startX'];
406
            }
407
            if (!empty($documentItem['endX'])) {
408
                $arrayKey .= '_' . $documentItem['endX'];
409
            }
410
            // do not add more than one identical object
411
            if (!in_array($arrayKey, $items)) {
412
                $items[$arrayKey] = $documentItem;
413
                // replace url param placeholder
414
                $pdfParams = str_replace("##startpage##", $documentItem['startpage'], $this->settings['pdfparams']);
415
                $pdfParams = str_replace("##docId##", $document->recordId, $pdfParams);
416
                $pdfParams = str_replace("##startx##", $documentItem['startX'], $pdfParams);
417
                $pdfParams = str_replace("##starty##", $documentItem['startY'], $pdfParams);
418
                $pdfParams = str_replace("##endx##", $documentItem['endX'], $pdfParams);
419
                $pdfParams = str_replace("##endy##", $documentItem['endY'], $pdfParams);
420
                $pdfParams = str_replace("##rotation##", $documentItem['rotation'], $pdfParams);
421
                if ($documentItem['startpage'] != $documentItem['endpage']) {
422
                    $pdfParams = str_replace("##endpage##", $documentItem['endpage'], $pdfParams);
423
                } else {
424
                    // remove parameter endpage
425
                    $pdfParams = str_replace(",##endpage##", '', $pdfParams);
426
                }
427
                $pdfGenerateUrl = $this->settings['pdfgenerate'] . $pdfParams;
428
                if ($this->settings['pregeneration']) {
429
                    // send ajax request to webapp
430
                    $output .= '
431
     <script>
432
      $(document).ready(function(){
433
       $.ajax({
434
         url: "' . $pdfGenerateUrl . '",
435
       }).done(function() {
436
       });
437
      });
438
     </script>';
439
                }
440
            }
441
            $update = ['doc_ids' => json_encode($items)];
442
            GeneralUtility::makeInstance(ConnectionPool::class)
443
                ->getConnectionForTable('tx_dlf_basket')
444
                ->update(
445
                    'tx_dlf_basket',
446
                    $update,
447
                    ['uid' => (int) $basketData['uid']]
448
                );
449
            $basketData['doc_ids'] = $items;
450
        }
451
        return ['basketData' => $basketData, 'jsOutput' => $output];
452
    }
453
454
    /**
455
     * Removes selected documents from basket
456
     *
457
     * @access protected
458
     *
459
     * @param array $_piVars: plugin variables
460
     * @param array $basketData: array with document information
461
     *
462
     * @return array basket data
463
     */
464
    protected function removeFromBasket($_piVars, $basketData)
465
    {
466
        if (!empty($basketData['doc_ids'])) {
467
            $items = $basketData['doc_ids'];
468
            $items = get_object_vars($items);
469
        }
470
        foreach ($_piVars['selected'] as $value) {
471
            if (isset($value['id'])) {
472
                $arrayKey = $value['id'] . '_' . $value['startpage'];
473
                if (!empty($value['startX'])) {
474
                    $arrayKey .= '_' . $value['startX'];
475
                }
476
                if (!empty($value['endX'])) {
477
                    $arrayKey .= '_' . $value['endX'];
478
                }
479
                if (isset($items[$arrayKey])) {
480
                    unset($items[$arrayKey]);
481
                }
482
            }
483
        }
484
        if (empty($items)) {
485
            $update = ['doc_ids' => ''];
486
        } else {
487
            $update = ['doc_ids' => json_encode($items)];
488
        }
489
490
        GeneralUtility::makeInstance(ConnectionPool::class)
491
            ->getConnectionForTable('tx_dlf_basket')
492
            ->update(
493
                'tx_dlf_basket',
494
                 $update,
495
                ['uid' => (int) $basketData['uid']]
496
            );
497
        $basketData['doc_ids'] = $items;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $items does not seem to be defined for all execution paths leading up to this point.
Loading history...
498
        return $basketData;
499
    }
500
501
    /**
502
     * Send mail with pdf download url
503
     *
504
     * @access protected
505
     *
506
     * @return void
507
     */
508
    protected function sendMail($requestData)
509
    {
510
        // send mail
511
        $mailId = $requestData['mail_action'];
512
513
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
514
            ->getQueryBuilderForTable('tx_dlf_mail');
515
516
        // get id from db and send selected doc download link
517
        $resultMail = $queryBuilder
518
            ->select('*')
519
            ->from('tx_dlf_mail')
520
            ->where(
521
                $queryBuilder->expr()->eq('tx_dlf_mail.uid', intval($mailId)),
522
                Helper::whereExpression('tx_dlf_mail')
523
            )
524
            ->setMaxResults(1)
525
            ->execute();
526
527
        $allResults = $resultMail->fetchAll();
528
        $mailData = $allResults[0];
529
        $mailText = htmlspecialchars(LocalizationUtility::translate('basket.mailBody', 'dlf')) . "\n";
530
        $numberOfPages = 0;
531
        $pdfUrl = $this->settings['pdfdownload'];
532
        // prepare links
533
        foreach ($requestData['selected'] as $docValue) {
534
            if ($docValue['id']) {
535
                $explodeId = explode("_", $docValue['id']);
536
                $docData = $this->getDocumentData($explodeId[0], $docValue);
537
                $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
538
                $pages = (abs(intval($docValue['startpage']) - intval($docValue['endpage'])));
539
                if ($pages === 0) {
540
                    $numberOfPages = $numberOfPages + 1;
541
                } else {
542
                    $numberOfPages = $numberOfPages + $pages;
543
                }
544
            }
545
        }
546
        // Remove leading/tailing pdfparamseperator
547
        $pdfUrl = trim($pdfUrl, $this->settings['pdfparamseparator']);
548
        $mailBody = $mailText . $pdfUrl;
549
        // Get hook objects.
550
        $hookObjects = Helper::getHookObjects($this->scriptRelPath);
551
        // Hook for getting a customized mail body.
552
        foreach ($hookObjects as $hookObj) {
553
            if (method_exists($hookObj, 'customizeMailBody')) {
554
                $mailBody = $hookObj->customizeMailBody($mailText, $pdfUrl);
555
            }
556
        }
557
        $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
558
        // send mail
559
        $mail = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
560
        // Prepare and send the message
561
        $mail
562
            // subject
563
            ->setSubject(LocalizationUtility::translate('basket.mailSubject', 'dlf'))
564
            // Set the From address with an associative array
565
            ->setFrom($from)
566
            // Set the To addresses with an associative array
567
            ->setTo([$mailData['mail'] => $mailData['name']])
568
            ->setBody($mailBody, 'text/html')
569
            ->send();
570
        // protocol
571
        $insertArray = [
572
            'pid' => $this->settings['pages'],
573
            'file_name' => $pdfUrl,
574
            'count_pages' => $numberOfPages,
575
            'crdate' => time(),
576
        ];
577
        if ($GLOBALS["TSFE"]->loginUser) {
578
            // internal user
579
            $insertArray['user_id'] = $GLOBALS["TSFE"]->fe_user->user['uid'];
580
            $insertArray['name'] = $GLOBALS["TSFE"]->fe_user->user['username'];
581
            $insertArray['label'] = 'Mail: ' . $mailData['mail'];
582
        } else {
583
            // external user
584
            $insertArray['user_id'] = 0;
585
            $insertArray['name'] = 'n/a';
586
            $insertArray['label'] = 'Mail: ' . $mailData['mail'];
587
        }
588
        // add action to protocol
589
        GeneralUtility::makeInstance(ConnectionPool::class)
590
            ->getConnectionForTable('tx_dlf_actionlog')
591
            ->insert(
592
                'tx_dlf_actionlog',
593
                $insertArray
594
            );
595
        $this->redirect('main');
596
    }
597
598
    /**
599
     * Sends document information to an external printer (url)
600
     *
601
     * @access protected
602
     *
603
     * @return void
604
     */
605
    protected function printDocument($requestData, $basketData)
606
    {
607
        $pdfUrl = $this->settings['pdfprint'];
608
        $numberOfPages = 0;
609
        foreach ($requestData['selected'] as $docId => $docValue) {
610
            if ($docValue['id']) {
611
                $docData = $this->getDocumentData($docValue['id'], $docValue);
612
                $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
613
                $numberOfPages += $docData['pageNums'];
614
            }
615
        }
616
        // get printer data
617
        $printerId = $requestData['print_action'];
618
619
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
620
            ->getQueryBuilderForTable('tx_dlf_printer');
621
622
        // get id from db and send selected doc download link
623
        $resultPrinter = $queryBuilder
624
            ->select('*')
625
            ->from('tx_dlf_printer')
626
            ->where(
627
                $queryBuilder->expr()->eq('tx_dlf_printer.uid', intval($printerId)),
628
                Helper::whereExpression('tx_dlf_printer')
629
            )
630
            ->setMaxResults(1)
631
            ->execute();
632
633
        $allResults = $resultPrinter->fetchAll();
634
        $printerData = $allResults[0];
635
        // printer is selected
636
        if ($printerData) {
637
            $pdfUrl = $printerData['print'];
638
            $numberOfPages = 0;
639
            foreach ($requestData['selected'] as $docId => $docValue) {
640
                if ($docValue['id']) {
641
                    $explodeId = explode("_", $docId);
642
                    $docData = $this->getDocumentData($explodeId[0], $docValue);
643
                    $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
644
                    $numberOfPages += $docData['pageNums'];
645
                }
646
            }
647
            $pdfUrl = trim($pdfUrl, $this->settings['pdfparamseparator']);
648
        }
649
        // protocol
650
        $insertArray = [
651
            'pid' => $this->settings['pages'],
652
            'file_name' => $pdfUrl,
653
            'count_pages' => $numberOfPages,
654
            'crdate' => time(),
655
        ];
656
        if ($GLOBALS["TSFE"]->loginUser) {
657
            // internal user
658
            $insertArray['user_id'] = $GLOBALS["TSFE"]->fe_user->user['uid'];
659
            $insertArray['name'] = $GLOBALS["TSFE"]->fe_user->user['username'];
660
            $insertArray['label'] = 'Print: ' . $printerData['label'];
661
        } else {
662
            // external user
663
            $insertArray['user_id'] = 0;
664
            $insertArray['name'] = 'n/a';
665
            $insertArray['label'] = 'Print: ' . $printerData['label'];
666
        }
667
        // add action to protocol
668
        GeneralUtility::makeInstance(ConnectionPool::class)
669
            ->getConnectionForTable('tx_dlf_actionlog')
670
            ->insert(
671
                'tx_dlf_actionlog',
672
                $insertArray
673
            );
674
675
        $this->redirectToUri($pdfUrl);
676
    }
677
678
}
679