src/bekanntmacher/boxmaker-bundle/src/Module/TypeDetail.php line 89

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright Bekanntmacher
  4.  *
  5.  * @author Simon Wohler <s.wohler@bekanntmacher.ch>
  6.  * @license    commercial
  7.  */
  8. namespace Bekanntmacher\BoxmakerBundle\Module;
  9. use Bekanntmacher\BoxmakerBundle\Classes\Config;
  10. use Bekanntmacher\BoxmakerBundle\Classes\UserInput;
  11. use Bekanntmacher\BoxmakerBundle\Model\FarbeModel;
  12. use Bekanntmacher\BoxmakerBundle\Model\TypeModel;
  13. use Bekanntmacher\BoxmakerBundle\Model\ConfigModel;
  14. use Bekanntmacher\BoxmakerBundle\Model\WelleModel;
  15. use Bekanntmacher\BoxmakerBundle\Model\TypeOptionModel;
  16. use Bekanntmacher\BoxmakerBundle\Calculation\OptionCalculator;
  17. use Contao\System;
  18. use Haste\Util\Url;
  19. use Mpdf;
  20. use Contao\File;
  21. use Haste\Form\Form;
  22. /**
  23.  * Boxmaker Typelist
  24.  */
  25. class TypeDetail extends TypeUtil
  26. {
  27.     /**
  28.      * @var string Template
  29.      */
  30.     protected $strTemplate 'mod_boxmaker_typedetail';
  31.     protected $objType null;
  32.     protected $objConfig null;
  33.     protected $objUserInput null;
  34.     /**
  35.      * Display a wildcard in the back end
  36.      * @return string
  37.      */
  38.     public function generate()
  39.     {
  40.         // Display a wildcard in the back end
  41.         if (TL_MODE === 'BE')
  42.         {
  43.             $template =new \BackendTemplate('be_wildcard');
  44.             $template->wildcard '### BOXMAKER TYPE DETAIL ###';
  45.             $template->title $this->name;
  46.             $template->id $this->id;
  47.             $template->link $this->name;
  48.             $template->href 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' $this->id;
  49.         }
  50.         return parent::generate();
  51.     }
  52.     /**
  53.      * Generate the module
  54.      */
  55.     protected function compile()
  56.     {
  57.         // Type
  58.         $objTypeModel TypeModel::findPublishedById((int) \Input::get('type'), array('eager' => true));
  59.         if ($objTypeModel === null)
  60.         {
  61.             global $objPage;
  62.             $objHandler = new $GLOBALS['TL_PTY']['error_404']();
  63.             $objHandler->generate($objPage->id);
  64.         }
  65.         // Type and type_config
  66.         $arrType $this->compileTypeData($objTypeModel);
  67.         $this->objType = new Type($arrType);
  68.         $this->objType->addTypeConfig($objTypeModel->getRelated('type_config_set')->row());
  69.         $this->Template->type $this->objType->getAll();
  70.         $this->Template->typeImagePaths_json json_encode($arrType['image']);
  71.         // Boxmaker Konfiguration
  72.         $this->objConfig = new Config(ConfigModel::findByPk($this->boxmaker_config)->row());
  73.         // User Input
  74.         $this->objUserInput = new UserInput($this->objConfig$this->objType->type_standardwelle);
  75.         $this->objUserInput->set('farbe_title'FarbeModel::findByPk($this->objUserInput->farbe)->selecttitle);
  76.         $this->Template->userInput $this->objUserInput->getAll();
  77.         // Preise berechnen
  78.         $this->arrPrices $this->addTypePrices();
  79.         $this->Template->prices_json json_encode($this->arrPrices['arrPriceTotal']);
  80.         // Wellen Table
  81.         $this->generateWellenTable();
  82.         // Select Druckverfahren
  83.         $str_1f_selected = ($this->objUserInput->druckverfahren != null && $this->objUserInput->druckfarben == '_1f') ? $this->objUserInput->druckverfahren $this->arrPrices['cheapestPrintingMethod']['_1f'];
  84.         $arr_1f_select $this->getPrintingMethodSelect('1f');
  85.         $this->Template->printingMethodSelect_1f = (count($arr_1f_select)) ? $arr_1f_select : [];
  86.         $this->Template->printingMethodSelect_1f_selected str_replace('_1f',''$str_1f_selected);
  87.         $str_4f_selected = ($this->objUserInput->druckverfahren != null && $this->objUserInput->druckfarben == '_4f') ? $this->objUserInput->druckverfahren $this->arrPrices['cheapestPrintingMethod']['_4f'];
  88.         $arr_4f_select $this->getPrintingMethodSelect('4f');
  89.         $this->Template->printingMethodSelect_4f = (count($arr_4f_select)) ? $arr_4f_select : [];
  90.         $this->Template->printingMethodSelect_4f_selected str_replace('_4f',''$str_4f_selected);
  91.         $this->Template->dva = ($this->objUserInput->druckfarben !== null) ? $this->objUserInput->druckfarben 'blank';
  92.         $this->Template->sa $this->objUserInput->seite;
  93.         // CHF, Wellenbild, etc.
  94.         $this->addGeneralTemplateData();
  95.         $this->addWellenInfo();
  96.         // Druckbild Weiss hinterlegt
  97.         $objOptionCalc = new OptionCalculator($this->objType,$this->objUserInput);
  98.         $objO = new \stdClass();
  99.         $objO->surcharge_stk $this->objConfig->hg_print_surcharge_stk;
  100.         $objO->surcharge_m2 $this->objConfig->hg_print_surcharge_m2;
  101.         $objO->surcharge_total $this->objConfig->hg_print_surcharge_total;
  102.         $this->Template->white_background_title $this->objConfig->wp_title;
  103.         $this->Template->white_background_price $this->getAmount($objOptionCalc->calculateOptionPriceStk($objO), truetruefalse);
  104.         // Lieferzeit
  105.         $this->generateDeliveryTable();
  106.         // Muster
  107.         $this->Template->boxmaker_price_sample_blank $this->objConfig->boxmaker_price_sample_blank;
  108.         $this->Template->boxmaker_price_sample_printed $this->objConfig->boxmaker_price_sample_printed;
  109.         // Debug Info
  110.         $this->Template->showDebugInfo false;
  111.         if (System::getContainer()->get('contao.security.token_checker')->hasBackendUser()) {
  112.            $this->Template->showDebugInfo true;
  113.            $this->Template->cheapestProductionMethod $this->arrPrices['cheapestProductionMethod'];
  114.            $this->Template->debug print_r($this->arrPrices,true);
  115.         }
  116.         // Weiterleitungsseiten
  117.         $objJumpToCart = \PageModel::findByPk($this->boxmaker_jumpToCart);
  118.         if($objJumpToCart !== null) {
  119.             $this->Template->boxmaker_jumpToCart $objJumpToCart->getFrontendUrl();
  120.         }
  121.         $objJumpToStart = \PageModel::findByPk($this->boxmaker_jumpToStart);
  122.         if($objJumpToStart !== null) {
  123.             $this->Template->boxmaker_jumpToStart $objJumpToStart->getFrontendUrl();
  124.         }
  125.     }
  126.     // generate Deliverytable
  127.     private function generateDeliveryTable()
  128.     {
  129.         $idWelle = ($this->objUserInput->welle != null) ? $this->objUserInput->welle $this->objType->type_standardwelle;
  130.         $idFarbe = ($this->objUserInput->farbe != null) ? $this->objUserInput->farbe 1;
  131.         $arrTableRaw $this->arrPrices['arrDeliverySurcharge'][$idWelle][$idFarbe]['blank'];
  132.         $arrTable = array();
  133.         foreach($arrTableRaw as $methode => $surcharge)
  134.         {
  135.             $arrTable[$methode] = array
  136.             (
  137.                 'title' => $this->getDeliveryDate($methode),
  138.                 'price' => $surcharge,
  139.                 'class' => ($surcharge == 0) ? 'active' ''
  140.             );
  141.         }
  142.         $arrLabels = array
  143.         (
  144.             'p' =>  $this->getDeliveryDate('p'),
  145.             'ht' =>  $this->getDeliveryDate('ht'),
  146.             'ap' =>  $this->getDeliveryDate('ap'),
  147.         );
  148.         $this->Template->deliveryPrices_json json_encode($this->arrPrices['arrDeliverySurcharge']);
  149.         $this->Template->deliveryDateLabels_json json_encode($arrLabels);
  150.         $this->Template->deliveryDateLabels_json;
  151.         $this->Template->deliveryTable array_reverse($arrTable);
  152.         $this->Template->delivery_date $this->getDeliveryDate($this->arrPrices['cheapestProductionMethod']);
  153.     }
  154.     // ok generate Wellentable
  155.     private function generateWellenTable()
  156.     {
  157.         $objWellen WelleModel::findAllOrderedBySorting();
  158.         $objFarben FarbeModel::findAllOrderedBySorting();
  159.         $arrMaterial $this->arrPrices['arrAll']['material'][$this->arrPrices['cheapestProductionMethod']];
  160.         $idWelle = ($this->objUserInput->welle != null) ? $this->objUserInput->welle $this->objType->type_standardwelle;
  161.         $arrTable = array();
  162.         $arrJson = array();
  163.         foreach ($objWellen as $welle)
  164.         {
  165.             $arrTable[$welle->id]['title'] = $welle->title;
  166.             foreach ($objFarben as $f)
  167.             {
  168.                 $arrTable[$welle->id]['fields'][$f->id] = array
  169.                 (
  170.                     'title' => $f->title,
  171.                     'av'    => (key_exists('farbe_'.$f->id, (array) $arrMaterial[$welle->id])) ? 0,
  172.                     'class' => ($f->id == $this->objUserInput->farbe && $welle->id == $idWelle) ? ' active'''
  173.                 );
  174.                 $arrJson[$welle->id][$f->id] = $f->farbe;
  175.             }
  176.         }
  177.         $this->Template->wellenHead             $objFarben->fetchEach('title');
  178.         $this->Template->wellenHead_json        json_encode($objFarben->fetchEach('selecttitle'));
  179.         $this->Template->wellenTable            $arrTable;
  180.         $this->Template->wellenFarbeAlias_json  json_encode($arrJson);
  181.     }
  182.     // ok druckverfahren für die select's  als array zurückgeben
  183.     private function getPrintingMethodSelect($strF='1f')
  184.     {
  185.         $arrReturn = array();
  186.         foreach ($GLOBALS['BOXMAKER']['printingMethods'] as $method)
  187.         {
  188.             if($this->objUserInput->stk $this->objType->{$method '_min'})
  189.             {
  190.                 continue;
  191.             }
  192.             if($method == 'blank' || strpos($method$strF) === false || ($method == 'offsetdruck_1f')) {
  193.                 continue;
  194.             }
  195.             $arrReturn[] = array (
  196.                 'value' => str_replace(array('_1f','_4f'), ''$method),
  197.                 'label' => $GLOBALS['BOXMAKER']['printingMethodsLabels_short'][$method]
  198.             );
  199.         }
  200.         return ($arrReturn);
  201.     }
  202.     // ok Welleninfo
  203.     private function addWellenInfo()
  204.     {
  205.         // Wellen Image und Title
  206.         $arrWellenInfo = array();
  207.         $objWelle WelleModel::findAllOrderedBySorting();
  208.         foreach ($objWelle as $welle)
  209.         {
  210.             $image = \FilesModel::findByUuid($welle->image);
  211.             $arrWellenInfo[$welle->id] = array
  212.             (
  213.                 'path'  => $image->path,
  214.                 'title' => $welle->title
  215.             );
  216.         }
  217.         $this->Template->wellenInfo $arrWellenInfo[$this->objType->type_standardwelle];
  218.         $this->Template->wellenInfo_json json_encode($arrWellenInfo);
  219.     }
  220. }