vendor/alnv/catalog-manager/library/alnv/Modules/ModuleUniversalView.php line 157

Open in your IDE?
  1. <?php
  2. namespace CatalogManager;
  3. class ModuleUniversalView extends \Module
  4. {
  5.     protected $strAct;
  6.     protected $strMasterAlias;
  7.     protected $strTemplate 'mod_catalog_universal';
  8.     public function generate()
  9.     {
  10.         if (TL_MODE == 'BE') {
  11.             $objTemplate = new \BackendTemplate('be_wildcard');
  12.             $objTemplate->id $this->id;
  13.             $objTemplate->link $this->name;
  14.             $objTemplate->title $this->headline;
  15.             $objTemplate->href 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' $this->id;
  16.             $objTemplate->wildcard '### ' utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['catalogUniversalView'][0]) . ' ###';
  17.             return $objTemplate->parse();
  18.         }
  19.         if (isset($GLOBALS['TL_HOOKS']['catalogManagerBeforeInitializeView']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerBeforeInitializeView'])) {
  20.             foreach ($GLOBALS['TL_HOOKS']['catalogManagerBeforeInitializeView'] as $arrCallback) {
  21.                 if (is_array($arrCallback)) {
  22.                     $this->import($arrCallback[0]);
  23.                     $this->{$arrCallback[0]}->{$arrCallback[1]}($this);
  24.                 }
  25.             }
  26.         }
  27.         $this->strAct \Input::get('act' $this->id);
  28.         $this->strMasterAlias \Input::get('auto_item');
  29.         if (!$this->strAct && \Input::get('pdf' $this->id)) {
  30.             $this->strAct 'pdf';
  31.         }
  32.         if (TL_MODE == 'FE' && $this->catalogCustomTemplate) {
  33.             $this->strTemplate $this->catalogCustomTemplate;
  34.         }
  35.         if (TL_MODE == 'FE' && $this->catalogUseMap && !$this->strAct) {
  36.             $this->strTemplate $this->catalogMapViewTemplate;
  37.         }
  38.         if (TL_MODE == 'FE' && $this->enableTableView && !$this->strAct) {
  39.             if (!$this->strMasterAlias || $this->catalogPreventMasterView) {
  40.                 $this->strTemplate $this->catalogTableViewTemplate;
  41.             }
  42.         }
  43.         if (TL_MODE == 'FE') {
  44.             if (isset($GLOBALS['TL_HOOKS']['catalogManagerModifyMainTemplate']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerModifyMainTemplate'])) {
  45.                 foreach ($GLOBALS['TL_HOOKS']['catalogManagerModifyMainTemplate'] as $arrCallback) {
  46.                     if (is_array($arrCallback)) {
  47.                         $this->import($arrCallback[0]);
  48.                         $this->strTemplate $this->{$arrCallback[0]}->{$arrCallback[1]}($this->strTemplate$this);
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.         return parent::generate();
  54.     }
  55.     protected function compile()
  56.     {
  57.         switch ($this->strAct) {
  58.             case 'create':
  59.             case 'copy':
  60.             case 'edit':
  61.                 $this->determineFormView();
  62.                 break;
  63.             case 'delete':
  64.                 $this->deleteEntityFromCatalog();
  65.                 break;
  66.             case 'pdf':
  67.                 $this->downloadPdf();
  68.                 break;
  69.             default:
  70.                 if ($this->strMasterAlias && !$this->catalogPreventMasterView) {
  71.                     $this->determineMasterView();
  72.                 } else {
  73.                     $this->determineCatalogView();
  74.                 }
  75.                 break;
  76.         }
  77.     }
  78.     private function deleteEntityFromCatalog()
  79.     {
  80.         $this->import('FrontendEditing');
  81.         $this->FrontendEditing->strAct $this->strAct;
  82.         $this->FrontendEditing->arrOptions $this->arrData;
  83.         $this->FrontendEditing->strItemID \Input::get('id' $this->id);
  84.         $this->FrontendEditing->strTemplate $this->catalogFormTemplate $this->catalogFormTemplate 'form_catalog_default';
  85.         $this->FrontendEditing->initialize();
  86.         $blnIsVisible $this->FrontendEditing->isVisible();
  87.         if (!$this->FrontendEditing->checkPermission($this->strAct) || !$this->catalogEnableFrontendEditing) {
  88.             $objCatalogException = new CatalogException();
  89.             $objCatalogException->set403();
  90.         }
  91.         if (!$blnIsVisible) {
  92.             $objCatalogException = new CatalogException();
  93.             $objCatalogException->set404();
  94.         }
  95.         $this->FrontendEditing->deleteEntity();
  96.     }
  97.     private function determineCatalogView()
  98.     {
  99.         $this->import('CatalogView');
  100.         $this->import('CatalogMessage');
  101.         $arrQuery = [
  102.             'where' => [],
  103.             'orderBy' => []
  104.         ];
  105.         $this->CatalogView->strMode 'view';
  106.         $this->CatalogView->arrOptions $this->arrData;
  107.         $this->CatalogView->objMainTemplate $this->Template;
  108.         $this->CatalogView->strTemplate $this->catalogTemplate $this->catalogTemplate 'catalog_teaser';
  109.         $this->CatalogView->initialize();
  110.         $this->Template->showAsGroup $this->CatalogView->showAsGroup();
  111.         $this->Template->message $this->CatalogMessage->get($this->id);
  112.         $this->Template->createOperation $this->CatalogView->getCreateOperation();
  113.         $varView $this->CatalogView->getCatalogView($arrQuery);
  114.         $this->Template->data is_array($varView) ? $varView : [];
  115.         $this->Template->map $this->CatalogView->getMapViewOptions();
  116.         $this->Template->output is_string($varView) ? $varView '';
  117.         $this->Template->hasOperations $this->CatalogView->getHasOperationFlag();
  118.         if ($this->Template->entityIndex[1] > && $this->catalogShowQuantity$this->Template->message sprintf($GLOBALS['TL_LANG']['MSC']['CATALOG_MANAGER']['entitiesAmount'], $this->Template->entityIndex[1]);
  119.         if ($this->Template->entityIndex[1] == && $this->catalogShowQuantity$this->Template->message $GLOBALS['TL_LANG']['MSC']['CATALOG_MANAGER']['oneEntity'];
  120.         if (!$this->Template->entityIndex[1]) $this->Template->message $GLOBALS['TL_LANG']['MSC']['CATALOG_MANAGER']['noEntities'];
  121.         if ($this->catalogSendJsonHeader) {
  122.             $this->import('CatalogAjaxController');
  123.             $this->CatalogAjaxController->setData([
  124.                 'map' => $this->Template->map,
  125.                 'data' => $this->Template->data,
  126.                 'output' => $this->Template->output,
  127.                 'message' => $this->Template->message,
  128.                 'pagination' => $this->Template->pagination,
  129.                 'showAsGroup' => $this->Template->showAsGroup,
  130.                 'operations' => $this->Template->createOperation,
  131.             ]);
  132.             $this->CatalogAjaxController->setType($this->catalogSendJsonHeader);
  133.             $this->CatalogAjaxController->setModuleID($this->id);
  134.             $this->CatalogAjaxController->sendJsonData();
  135.         }
  136.     }
  137.     private function determineMasterView()
  138.     {
  139.         $this->import('CatalogView');
  140.         $arrQuery = [
  141.             'where' => [
  142.                 [
  143.                     [
  144.                         'field' => 'alias',
  145.                         'operator' => 'equal',
  146.                         'value' => $this->strMasterAlias
  147.                     ]
  148.                 ]
  149.             ]
  150.         ];
  151.         if (is_numeric($this->strMasterAlias)) {
  152.             $arrQuery['where'][0][] = [
  153.                 'field' => 'id',
  154.                 'operator' => 'equal',
  155.                 'value' => $this->strMasterAlias
  156.             ];
  157.         }
  158.         $this->CatalogView->strMode 'master';
  159.         $this->CatalogView->arrOptions $this->arrData;
  160.         $this->CatalogView->objMainTemplate $this->Template;
  161.         $this->CatalogView->strTemplate $this->catalogMasterTemplate $this->catalogMasterTemplate 'catalog_master';
  162.         $this->CatalogView->initialize();
  163.         $strOutput $this->CatalogView->getCatalogView($arrQuery);
  164.         $this->CatalogView->getCommentForm($this->CatalogView->strMasterID);
  165.         if (empty($strOutput)) {
  166.             if ($this->catalogAutoRedirect && $this->catalogViewPage && $this->catalogUseViewPage) {
  167.                 if ($objRedirect \PageModel::findByPk($this->catalogViewPage)) {
  168.                     \Controller::redirect($objRedirect->getFrontendUrl());
  169.                 }
  170.                 return null;
  171.             }
  172.             $objCatalogException = new CatalogException();
  173.             $objCatalogException->set404();
  174.         }
  175.         $this->Template->showAsGroup false;
  176.         $this->Template->data is_array($strOutput) ? $strOutput : [];
  177.         $this->Template->output is_string($strOutput) ? $strOutput '';
  178.         if ($this->catalogSendJsonHeader) {
  179.             $this->import('CatalogAjaxController');
  180.             $this->CatalogAjaxController->setData([
  181.                 'data' => $this->Template->data,
  182.                 'output' => $this->Template->output,
  183.                 'showAsGroup' => $this->Template->showAsGroup,
  184.             ]);
  185.             $this->CatalogAjaxController->setType($this->catalogSendJsonHeader);
  186.             $this->CatalogAjaxController->setModuleID($this->id);
  187.             $this->CatalogAjaxController->sendJsonData();
  188.         }
  189.     }
  190.     private function determineFormView()
  191.     {
  192.         $this->import('FrontendEditing');
  193.         $arrQueries $this->catalogUseTaxonomies Toolkit::parseQueries(\StringUtil::deserialize($this->catalogTaxonomiestrue)['query']) : []; // out
  194.         $this->FrontendEditing->strTemplate $this->catalogFormTemplate ?: 'form_catalog_default';
  195.         $this->FrontendEditing->strItemID \Input::get('id' $this->id);
  196.         $this->FrontendEditing->arrOptions $this->arrData;
  197.         $this->FrontendEditing->strAct $this->strAct;
  198.         $this->FrontendEditing->arrQueries = empty($arrQueries) ? [] : $arrQueries// []
  199.         $this->FrontendEditing->initialize();
  200.         $blnIsVisible $this->FrontendEditing->isVisible();
  201.         if (!$this->FrontendEditing->checkPermission($this->strAct) || !$this->catalogEnableFrontendEditing) {
  202.             $objCatalogException = new CatalogException();
  203.             $objCatalogException->set403();
  204.         }
  205.         if (!$blnIsVisible && $this->strAct != 'create') {
  206.             $objCatalogException = new CatalogException();
  207.             $objCatalogException->set404();
  208.         }
  209.         $this->Template->output $this->FrontendEditing->render();
  210.     }
  211.     public function setOffset($numOffset)
  212.     {
  213.         $this->catalogOffset $numOffset;
  214.     }
  215.     public function setPerPage($numPerPage)
  216.     {
  217.         $this->catalogPerPage $numPerPage;
  218.     }
  219.     public function setPagination($strPagination)
  220.     {
  221.         $this->catalogAddPagination $strPagination;
  222.     }
  223.     public function setTableView($strTableView$strFields)
  224.     {
  225.         $this->enableTableView $strTableView;
  226.         $this->catalogActiveTableColumns $strFields;
  227.         if ($this->catalogUseArray$this->catalogUseArray '';
  228.     }
  229.     public function setFastMode($strFastMode$strFields)
  230.     {
  231.         $this->catalogFastMode $strFastMode;
  232.         $this->catalogPreventFieldFromFastMode $strFields;
  233.     }
  234.     public function setTemplate($strTemplate)
  235.     {
  236.         $this->catalogTemplate $strTemplate;
  237.         $this->catalogMasterTemplate $strTemplate;
  238.         $this->catalogTableBodyViewTemplate $strTemplate;
  239.     }
  240.     public function setCss($strClass)
  241.     {
  242.         if (is_array($this->cssID) && isset($this->cssID[1])) {
  243.             $strId $this->cssID[0];
  244.             $strCss $this->cssID[01];
  245.             $strCss .= (empty($this->cssID[1]) ? '' ' ') . $strClass;
  246.             $this->cssID = [$strId$strCss];
  247.         }
  248.     }
  249.     protected function downloadPdf()
  250.     {
  251.         $objEntity = new Entity(\Input::get('pdf' $this->id), $this->catalogTablename);
  252.         $objEntity->getPdf($this->id$this->catalogPdfTemplate);
  253.     }
  254. }