| Total Complexity | 74 |
| Total Lines | 926 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
Complex classes like tx_dlf_basket 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 tx_dlf_basket, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class tx_dlf_basket extends tx_dlf_plugin { |
||
| 21 | |||
| 22 | public $scriptRelPath = 'plugins/basket/class.tx_dlf_basket.php'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The main method of the PlugIn |
||
| 26 | * |
||
| 27 | * @access public |
||
| 28 | * |
||
| 29 | * @param string $content: The PlugIn content |
||
| 30 | * @param array $conf: The PlugIn configuration |
||
| 31 | * |
||
| 32 | * @return string The content that is displayed on the website |
||
| 33 | */ |
||
| 34 | public function main($content, $conf) { |
||
| 35 | |||
| 36 | $this->init($conf); |
||
| 37 | |||
| 38 | // Don't cache the output. |
||
| 39 | $this->setCache(FALSE); |
||
| 40 | |||
| 41 | // Load template file. |
||
| 42 | if (!empty($this->conf['templateFile'])) { |
||
| 43 | |||
| 44 | $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), '###TEMPLATE###'); |
||
| 45 | |||
| 46 | } else { |
||
| 47 | |||
| 48 | $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/basket/template.tmpl'), '###TEMPLATE###'); |
||
| 49 | |||
| 50 | } |
||
| 51 | |||
| 52 | $subpartArray['entry'] = $this->cObj->getSubpart($this->template, '###ENTRY###'); |
||
|
|
|||
| 53 | |||
| 54 | $markerArray['###JS###'] = ''; |
||
| 55 | |||
| 56 | // get user session |
||
| 57 | $sessionId = $GLOBALS['TSFE']->fe_user->id; |
||
| 58 | |||
| 59 | if ($GLOBALS['TSFE']->loginUser) { |
||
| 60 | |||
| 61 | $insertArray['fe_user_id'] = $GLOBALS['TSFE']->fe_user->user['uid']; |
||
| 62 | |||
| 63 | $query = $GLOBALS['TYPO3_DB']->SELECTquery( |
||
| 64 | '*', |
||
| 65 | 'tx_dlf_basket', |
||
| 66 | 'tx_dlf_basket.fe_user_id='.intval($insertArray['fe_user_id']).tx_dlf_helper::whereClause('tx_dlf_basket'), |
||
| 67 | '', |
||
| 68 | '', |
||
| 69 | '1' |
||
| 70 | ); |
||
| 71 | |||
| 72 | } else { |
||
| 73 | |||
| 74 | $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_dlf_basket', ''); |
||
| 75 | |||
| 76 | $GLOBALS['TSFE']->fe_user->sesData_change = TRUE; |
||
| 77 | |||
| 78 | $GLOBALS['TSFE']->fe_user->storeSessionData(); |
||
| 79 | |||
| 80 | $query = $GLOBALS['TYPO3_DB']->SELECTquery( |
||
| 81 | '*', |
||
| 82 | 'tx_dlf_basket', |
||
| 83 | 'tx_dlf_basket.session_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($sessionId, 'tx_dlf_basket').tx_dlf_helper::whereClause('tx_dlf_basket'), |
||
| 84 | '', |
||
| 85 | '', |
||
| 86 | '1' |
||
| 87 | ); |
||
| 88 | |||
| 89 | } |
||
| 90 | |||
| 91 | $result = $GLOBALS['TYPO3_DB']->sql_query($query); |
||
| 92 | |||
| 93 | // session already exists |
||
| 94 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) == 0) { |
||
| 95 | |||
| 96 | // create new basket in db |
||
| 97 | $insertArray['session_id'] = $sessionId; |
||
| 98 | $insertArray['doc_ids'] = ''; |
||
| 99 | $insertArray['label'] = ''; |
||
| 100 | $insertArray['l18n_diffsource'] = ''; |
||
| 101 | |||
| 102 | $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_dlf_basket', $insertArray); |
||
| 103 | |||
| 104 | $result = $GLOBALS['TYPO3_DB']->sql_query($query); |
||
| 105 | |||
| 106 | } |
||
| 107 | |||
| 108 | $basketData = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
||
| 109 | |||
| 110 | $piVars = $this->piVars; |
||
| 111 | |||
| 112 | // action add to basket |
||
| 113 | if (!empty($this->piVars['id']) && $this->piVars['addToBasket']) { |
||
| 114 | |||
| 115 | $returnData = $this->addToBasket($this->piVars, $basketData); |
||
| 116 | |||
| 117 | $basketData = $returnData['basketData']; |
||
| 118 | |||
| 119 | $markerArray['###JS###'] = $returnData['jsOutput']; |
||
| 120 | |||
| 121 | } else { |
||
| 122 | |||
| 123 | $basketData['doc_ids'] = json_decode($basketData['doc_ids']); |
||
| 124 | |||
| 125 | } |
||
| 126 | |||
| 127 | // action remove from basket |
||
| 128 | if ($this->piVars['basket_action'] == 'remove') { |
||
| 129 | |||
| 130 | // remove entry from list |
||
| 131 | unset($piVars['basket_action']); |
||
| 132 | |||
| 133 | if (isset($this->piVars['selected'])) { |
||
| 134 | |||
| 135 | $basketData = $this->removeFromBasket($piVars, $basketData); |
||
| 136 | |||
| 137 | } |
||
| 138 | |||
| 139 | } |
||
| 140 | |||
| 141 | // action remove from basket |
||
| 142 | if ($this->piVars['basket_action'] == 'open') { |
||
| 143 | |||
| 144 | // open selected documents |
||
| 145 | unset($piVars['basket_action']); |
||
| 146 | |||
| 147 | if (isset($this->piVars['selected'])) { |
||
| 148 | |||
| 149 | $basketData = $this->openFromBasket($piVars, $basketData); |
||
| 150 | |||
| 151 | } |
||
| 152 | |||
| 153 | } |
||
| 154 | |||
| 155 | // action print from basket |
||
| 156 | if ($this->piVars['print_action']) { |
||
| 157 | |||
| 158 | // open selected documents |
||
| 159 | unset($piVars['print_action']); |
||
| 160 | |||
| 161 | if (isset($this->piVars['selected'])) { |
||
| 162 | |||
| 163 | $basketData = $this->printDocument($piVars, $basketData); |
||
| 164 | |||
| 165 | } |
||
| 166 | |||
| 167 | } |
||
| 168 | |||
| 169 | // action send mail |
||
| 170 | if ($this->piVars['mail_action']) { |
||
| 171 | |||
| 172 | if (isset($this->piVars['selected'])) { |
||
| 173 | |||
| 174 | $this->sendMail($this->piVars); |
||
| 175 | |||
| 176 | } |
||
| 177 | |||
| 178 | } |
||
| 179 | |||
| 180 | // set marker |
||
| 181 | $markerArray['###ACTION###'] = $this->pi_getPageLink($GLOBALS['TSFE']->id); |
||
| 182 | |||
| 183 | $markerArray['###LISTTITLE###'] = $this->pi_getLL('basket', '', TRUE); |
||
| 184 | |||
| 185 | if ($basketData['doc_ids']) { |
||
| 186 | |||
| 187 | if (is_object($basketData['doc_ids'])) { |
||
| 188 | |||
| 189 | $basketData['doc_ids'] = get_object_vars($basketData['doc_ids']); |
||
| 190 | |||
| 191 | } |
||
| 192 | |||
| 193 | $markerArray['###COUNT###'] = sprintf($this->pi_getLL('count'), count($basketData['doc_ids'])); |
||
| 194 | |||
| 195 | } else { |
||
| 196 | |||
| 197 | $markerArray['###COUNT###'] = sprintf($this->pi_getLL('count'), 0); |
||
| 198 | |||
| 199 | } |
||
| 200 | |||
| 201 | // get mail addresses |
||
| 202 | $resultMail = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 203 | '*', |
||
| 204 | 'tx_dlf_mail', |
||
| 205 | '1'.tx_dlf_helper::whereClause('tx_dlf_mail'), |
||
| 206 | '', |
||
| 207 | 'tx_dlf_mail.sorting', |
||
| 208 | '' |
||
| 209 | ); |
||
| 210 | |||
| 211 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($resultMail) > 0) { |
||
| 212 | |||
| 213 | $mails = array (); |
||
| 214 | |||
| 215 | $mailForm = '<select name="tx_dlf[mail_action]">'; |
||
| 216 | |||
| 217 | $mailForm .= '<option value="">'.$this->pi_getLL('chooseMail', '', TRUE).'</option>'; |
||
| 218 | |||
| 219 | while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resultMail)) { |
||
| 220 | |||
| 221 | $mails[] = $row; |
||
| 222 | |||
| 223 | $mailForm .= '<option value="'.$row['uid'].'">'.$row['name'].' ('.$row['mail'].')</option>'; |
||
| 224 | |||
| 225 | } |
||
| 226 | |||
| 227 | $mailForm .= '</select><input type="submit">'; |
||
| 228 | |||
| 229 | } |
||
| 230 | |||
| 231 | // mail action form |
||
| 232 | $markerArray['###MAILACTION###'] = $mailForm; |
||
| 233 | |||
| 234 | // remove action form |
||
| 235 | $markerArray['###REMOVEACTION###'] = ' |
||
| 236 | <select name="tx_dlf[basket_action]"> |
||
| 237 | <option value="">'.$this->pi_getLL('chooseAction', '', TRUE).'</option> |
||
| 238 | <option value="open">'.$this->pi_getLL('download', '', TRUE).'</option> |
||
| 239 | <option value="remove">'.$this->pi_getLL('remove', '', TRUE).'</option> |
||
| 240 | </select> |
||
| 241 | <input type="submit"> |
||
| 242 | '; |
||
| 243 | |||
| 244 | // get mail addresses |
||
| 245 | $resultPrinter = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 246 | '*', |
||
| 247 | 'tx_dlf_printer', |
||
| 248 | '1'.tx_dlf_helper::whereClause('tx_dlf_printer'), |
||
| 249 | '', |
||
| 250 | '', |
||
| 251 | '' |
||
| 252 | ); |
||
| 253 | |||
| 254 | $printForm = ''; |
||
| 255 | |||
| 256 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($resultPrinter) > 0) { |
||
| 257 | |||
| 258 | $printers = array (); |
||
| 259 | |||
| 260 | $printForm = '<select name="tx_dlf[print_action]">'; |
||
| 261 | |||
| 262 | $printForm .= '<option value="">'.$this->pi_getLL('choosePrinter', '', TRUE).'</option>'; |
||
| 263 | |||
| 264 | while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resultPrinter)) { |
||
| 265 | |||
| 266 | $printers[] = $row; |
||
| 267 | |||
| 268 | $printForm .= '<option value="'.$row['uid'].'">'.$row['label'].'</option>'; |
||
| 269 | |||
| 270 | } |
||
| 271 | |||
| 272 | $printForm .= '</select><input type="submit" />'; |
||
| 273 | |||
| 274 | } |
||
| 275 | |||
| 276 | // print action form |
||
| 277 | $markerArray['###PRINTACTION###'] = $printForm; |
||
| 278 | |||
| 279 | $entries = ''; |
||
| 280 | |||
| 281 | if (isset($basketData['doc_ids'])) { |
||
| 282 | |||
| 283 | // get each entry |
||
| 284 | foreach ($basketData['doc_ids'] as $key => $value) { |
||
| 285 | |||
| 286 | $entries .= $this->getEntry($value, $subpartArray); |
||
| 287 | |||
| 288 | } |
||
| 289 | |||
| 290 | } else { |
||
| 291 | |||
| 292 | $entries = ''; |
||
| 293 | |||
| 294 | } |
||
| 295 | |||
| 296 | // basket go to |
||
| 297 | if ($this->conf['targetBasket'] && $this->conf['basketGoToButton'] && $this->piVars['id']) { |
||
| 298 | |||
| 299 | $label = $this->pi_getLL('goBasket', '', TRUE); |
||
| 300 | |||
| 301 | $basketConf = array ( |
||
| 302 | 'parameter' => $this->conf['targetBasket'], |
||
| 303 | 'title' => $label |
||
| 304 | ); |
||
| 305 | |||
| 306 | $markerArray['###BASKET###'] = $this->cObj->typoLink($label, $basketConf); |
||
| 307 | |||
| 308 | } else { |
||
| 309 | |||
| 310 | $markerArray['###BASKET###'] = ''; |
||
| 311 | |||
| 312 | } |
||
| 313 | |||
| 314 | $content = $this->cObj->substituteMarkerArray($this->cObj->substituteSubpart($this->template, '###ENTRY###', $entries, TRUE), $markerArray); |
||
| 315 | |||
| 316 | return $this->pi_wrapInBaseClass($content); |
||
| 317 | |||
| 318 | } |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Return one basket entry |
||
| 322 | * @param array $data DocumentData |
||
| 323 | * @param array $template Template information |
||
| 324 | * @return Template |
||
| 325 | */ |
||
| 326 | public function getEntry($data, $template) { |
||
| 395 | |||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Adds documents to the basket |
||
| 400 | * @param array $_piVars piVars |
||
| 401 | * @param array $basketData basket data |
||
| 402 | */ |
||
| 403 | public function addToBasket($_piVars, $basketData) { |
||
| 404 | |||
| 405 | if (!$_piVars['startpage']) { |
||
| 406 | |||
| 407 | $page = 0; |
||
| 408 | |||
| 409 | } else { |
||
| 410 | |||
| 411 | $page = intval($_piVars['startpage']); |
||
| 412 | |||
| 413 | } |
||
| 414 | |||
| 415 | if ($page != NULL || $_piVars['addToBasket'] == 'list') { |
||
| 416 | |||
| 417 | $documentItem = array ( |
||
| 418 | 'id' => intval($_piVars['id']), |
||
| 419 | 'startpage' => intval($_piVars['startpage']), |
||
| 420 | 'endpage' => intval($_piVars['endpage']), |
||
| 421 | 'startX' => intval($_piVars['startX']), |
||
| 422 | 'startY' => intval($_piVars['startY']), |
||
| 423 | 'endX' => intval($_piVars['endX']), |
||
| 424 | 'endY' => intval($_piVars['endY']), |
||
| 425 | 'rotation' => intval($_piVars['rotation']) |
||
| 426 | ); |
||
| 427 | |||
| 428 | // update basket |
||
| 429 | if (!empty($basketData['doc_ids'])) { |
||
| 430 | |||
| 431 | $items = json_decode($basketData['doc_ids']); |
||
| 432 | |||
| 433 | $items = get_object_vars($items); |
||
| 434 | |||
| 435 | } else { |
||
| 436 | |||
| 437 | $items = array (); |
||
| 438 | |||
| 439 | } |
||
| 440 | |||
| 441 | // get document instance to load further information |
||
| 442 | $document = tx_dlf_document::getInstance($documentItem['id'], 0); |
||
| 443 | |||
| 444 | // set endpage for toc and subentry based on logid |
||
| 445 | if (($_piVars['addToBasket'] == 'subentry') or ($_piVars['addToBasket'] == 'toc')) { |
||
| 446 | |||
| 447 | $smLinks = $document->smLinks; |
||
| 448 | |||
| 449 | $pageCounter = sizeof($smLinks['l2p'][$_piVars['logId']]); |
||
| 450 | |||
| 451 | $documentItem['endpage'] = ($documentItem['startpage'] + $pageCounter) - 1; |
||
| 452 | |||
| 453 | } |
||
| 454 | |||
| 455 | // add whole document |
||
| 456 | if ($_piVars['addToBasket'] == 'list') { |
||
| 457 | |||
| 458 | $documentItem['endpage'] = $document->numPages; |
||
| 459 | |||
| 460 | } |
||
| 461 | |||
| 462 | $arrayKey = $documentItem['id'].'_'.$page; |
||
| 463 | |||
| 464 | if (!empty($documentItem['startX'])) { |
||
| 465 | |||
| 466 | $arrayKey .= '_'.$documentItem['startX']; |
||
| 467 | |||
| 468 | } |
||
| 469 | |||
| 470 | if (!empty($documentItem['endX'])) { |
||
| 471 | |||
| 472 | $arrayKey .= '_'.$documentItem['endX']; |
||
| 473 | |||
| 474 | } |
||
| 475 | |||
| 476 | // do not add more than one identical object |
||
| 477 | if (!in_array($arrayKey, $items)) { |
||
| 478 | |||
| 479 | $items[$arrayKey] = $documentItem; |
||
| 480 | |||
| 481 | // replace url param placeholder |
||
| 482 | $pdfParams = str_replace("##startpage##", $documentItem['startpage'], $this->conf['pdfparams']); |
||
| 483 | |||
| 484 | $pdfParams = str_replace("##docId##", $document->recordId, $pdfParams); |
||
| 485 | |||
| 486 | $pdfParams = str_replace("##startx##", $documentItem['startX'], $pdfParams); |
||
| 487 | |||
| 488 | $pdfParams = str_replace("##starty##", $documentItem['startY'], $pdfParams); |
||
| 489 | |||
| 490 | $pdfParams = str_replace("##endx##", $documentItem['endX'], $pdfParams); |
||
| 491 | |||
| 492 | $pdfParams = str_replace("##endy##", $documentItem['endY'], $pdfParams); |
||
| 493 | |||
| 494 | $pdfParams = str_replace("##rotation##", $documentItem['rotation'], $pdfParams); |
||
| 495 | |||
| 496 | if ($documentItem['startpage'] != $documentItem['endpage']) { |
||
| 497 | |||
| 498 | $pdfParams = str_replace("##endpage##", $documentItem['endpage'], $pdfParams); |
||
| 499 | |||
| 500 | } else { |
||
| 501 | |||
| 502 | // remove parameter endpage |
||
| 503 | $pdfParams = str_replace(",##endpage##", '', $pdfParams); |
||
| 504 | |||
| 505 | } |
||
| 506 | |||
| 507 | $pdfGenerateUrl = $this->conf['pdfgenerate'].$pdfParams; |
||
| 508 | |||
| 509 | if ($this->conf['pregeneration']) { |
||
| 510 | |||
| 511 | // send ajax request to webapp |
||
| 512 | $output .= ' |
||
| 513 | <script> |
||
| 514 | $(document).ready(function(){ |
||
| 515 | $.ajax({ |
||
| 516 | url: "'.$pdfGenerateUrl.'", |
||
| 517 | }).done(function() { |
||
| 518 | }); |
||
| 519 | }); |
||
| 520 | </script>'; |
||
| 521 | |||
| 522 | } |
||
| 523 | |||
| 524 | } |
||
| 525 | |||
| 526 | $update = array ('doc_ids' => json_encode($items)); |
||
| 527 | |||
| 528 | $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_dlf_basket', 'uid='.intval($basketData['uid']), $update); |
||
| 529 | |||
| 530 | $basketData['doc_ids'] = $items; |
||
| 531 | |||
| 532 | } |
||
| 533 | |||
| 534 | return array ('basketData' => $basketData, 'jsOutput' => $output); |
||
| 535 | |||
| 536 | } |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Removes selected documents from basket |
||
| 540 | * @param array $_piVars plugin variables |
||
| 541 | * @param array $basketData array with document information |
||
| 542 | * @return array basket data |
||
| 543 | */ |
||
| 544 | public function removeFromBasket($_piVars, $basketData) { |
||
| 545 | |||
| 546 | if (!empty($basketData['doc_ids'])) { |
||
| 547 | |||
| 548 | $items = $basketData['doc_ids']; |
||
| 549 | |||
| 550 | $items = get_object_vars($items); |
||
| 551 | |||
| 552 | } |
||
| 553 | |||
| 554 | foreach ($_piVars['selected'] as $key => $value) { |
||
| 555 | |||
| 556 | if (isset($value['id'])) { |
||
| 557 | |||
| 558 | $arrayKey = $value['id'].'_'.$value['startpage']; |
||
| 559 | |||
| 560 | if (isset($value['startX'])) { |
||
| 561 | |||
| 562 | $arrayKey .= '_'.$value['startX']; |
||
| 563 | |||
| 564 | } |
||
| 565 | |||
| 566 | if (isset($value['endX'])) { |
||
| 567 | |||
| 568 | $arrayKey .= '_'.$value['endX']; |
||
| 569 | |||
| 570 | } |
||
| 571 | |||
| 572 | if (isset($items[$arrayKey])) { |
||
| 573 | |||
| 574 | unset($items[$arrayKey]); |
||
| 575 | |||
| 576 | } |
||
| 577 | |||
| 578 | } |
||
| 579 | |||
| 580 | } |
||
| 581 | |||
| 582 | if (empty($items)) { |
||
| 583 | |||
| 584 | $update = array ('doc_ids' => ''); |
||
| 585 | |||
| 586 | } else { |
||
| 587 | |||
| 588 | $update = array ('doc_ids' => json_encode($items)); |
||
| 589 | |||
| 590 | } |
||
| 591 | |||
| 592 | $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_dlf_basket', 'uid='.intval($basketData['uid']), $update); |
||
| 593 | |||
| 594 | $basketData['doc_ids'] = $items; |
||
| 595 | |||
| 596 | return $basketData; |
||
| 597 | |||
| 598 | } |
||
| 599 | |||
| 600 | /** |
||
| 601 | * Open selected documents from basket |
||
| 602 | * @param array $_piVars plugin variables |
||
| 603 | * @param array $basketData array with document information |
||
| 604 | * @return array basket data |
||
| 605 | */ |
||
| 606 | public function openFromBasket($_piVars, $basketData) { |
||
| 607 | |||
| 608 | $pdfUrl = $this->conf['pdfgenerate']; |
||
| 609 | |||
| 610 | foreach ($this->piVars['selected'] as $docId => $docValue) { |
||
| 611 | |||
| 612 | if ($docValue['id']) { |
||
| 613 | |||
| 614 | $filename .= $docValue['id'].'_'; |
||
| 615 | |||
| 616 | $docData = $this->getDocumentData($docValue['id'], $docValue); |
||
| 617 | |||
| 618 | $pdfUrl .= $docData['urlParams'].$this->conf['pdfparamseparator']; |
||
| 619 | |||
| 620 | $numberOfPages += $docData['pageNums']; |
||
| 621 | |||
| 622 | } |
||
| 623 | |||
| 624 | } |
||
| 625 | |||
| 626 | header('Location: '.$pdfUrl); |
||
| 627 | |||
| 628 | ob_end_flush(); |
||
| 629 | |||
| 630 | exit; |
||
| 631 | |||
| 632 | } |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Returns the downloadurl configured in the basket |
||
| 636 | * @param integer $id Document id |
||
| 637 | * @return mixed download url or false |
||
| 638 | */ |
||
| 639 | public function getDocumentData($id, $data) { |
||
| 640 | |||
| 641 | // get document instance to load further information |
||
| 642 | $document = tx_dlf_document::getInstance($id, 0); |
||
| 643 | |||
| 644 | if ($document) { |
||
| 645 | |||
| 646 | // replace url param placeholder |
||
| 647 | $urlParams = str_replace("##page##", intval($data['page']), $this->conf['pdfparams']); |
||
| 648 | |||
| 649 | $urlParams = str_replace("##docId##", $document->recordId, $urlParams); |
||
| 650 | |||
| 651 | $urlParams = str_replace("##startpage##", intval($data['startpage']), $urlParams); |
||
| 652 | |||
| 653 | if ($data['startpage'] != $data['endpage']) { |
||
| 654 | |||
| 655 | $urlParams = str_replace("##endpage##", intval($data['endpage']), $urlParams); |
||
| 656 | |||
| 657 | } else { |
||
| 658 | |||
| 659 | // remove parameter endpage |
||
| 660 | $urlParams = str_replace(",##endpage##", '', $urlParams); |
||
| 661 | |||
| 662 | } |
||
| 663 | |||
| 664 | $urlParams = str_replace("##startx##", intval($data['startX']), $urlParams); |
||
| 665 | |||
| 666 | $urlParams = str_replace("##starty##", intval($data['startY']), $urlParams); |
||
| 667 | |||
| 668 | $urlParams = str_replace("##endx##", intval($data['endX']), $urlParams); |
||
| 669 | |||
| 670 | $urlParams = str_replace("##endy##", intval($data['endY']), $urlParams); |
||
| 671 | |||
| 672 | $urlParams = str_replace("##rotation##", intval($data['rotation']), $urlParams); |
||
| 673 | |||
| 674 | $downloadUrl = $this->conf['pdfgenerate'].$urlParams; |
||
| 675 | |||
| 676 | $title = $document->getTitle($id, TRUE); |
||
| 677 | |||
| 678 | if (empty($title)) { |
||
| 679 | |||
| 680 | $title = $this->pi_getLL('noTitle', '', TRUE); |
||
| 681 | |||
| 682 | } |
||
| 683 | |||
| 684 | // Set page and cutout information |
||
| 685 | $info = ''; |
||
| 686 | |||
| 687 | if ($data['startX'] != '' && $data['endX'] != '') { |
||
| 688 | |||
| 689 | // cutout |
||
| 690 | $info .= $this->pi_getLL('cutout', '', TRUE).' '; |
||
| 691 | |||
| 692 | } |
||
| 693 | |||
| 694 | if ($data['startpage'] == $data['endpage']) { |
||
| 695 | |||
| 696 | // One page |
||
| 697 | $info .= $this->pi_getLL('page', '', TRUE).' '.$data['startpage']; |
||
| 698 | |||
| 699 | } else { |
||
| 700 | |||
| 701 | $info .= $this->pi_getLL('page', '', TRUE).' '.$data['startpage'].'-'.$data['endpage']; |
||
| 702 | |||
| 703 | } |
||
| 704 | |||
| 705 | $downloadLink = '<a href="'.$downloadUrl.'" target="_blank">'.$title.'</a> ('.$info.')'; |
||
| 706 | |||
| 707 | if ($data['startpage'] == $data['endpage']) { |
||
| 708 | |||
| 709 | $pageNums = 1; |
||
| 710 | |||
| 711 | } else { |
||
| 712 | |||
| 713 | $pageNums = $data['endpage'] - $data['startpage']; |
||
| 714 | |||
| 715 | } |
||
| 716 | |||
| 717 | return array ( |
||
| 718 | 'downloadUrl' => $downloadUrl, |
||
| 719 | 'downloadLink' => $downloadLink, |
||
| 720 | 'pageNums' => $pageNums, |
||
| 721 | 'urlParams' => $urlParams, |
||
| 722 | 'record_id' => $document->recordId, |
||
| 723 | ); |
||
| 724 | |||
| 725 | } |
||
| 726 | |||
| 727 | return FALSE; |
||
| 728 | |||
| 729 | } |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Send mail with pdf download url |
||
| 733 | */ |
||
| 734 | public function sendMail() { |
||
| 840 | |||
| 841 | } |
||
| 842 | |||
| 843 | /** |
||
| 844 | * Sends document information to an external printer (url) |
||
| 845 | */ |
||
| 846 | public function printDocument() { |
||
| 946 | |||
| 947 | } |
||
| 948 | |||
| 949 | } |