system/modules/47_CustomModule/library/CustomModule/Frontend/Modules/TopBar.php line 57

Open in your IDE?
  1. <?php
  2. /**
  3.  * 47_CustomModule for Contao Open Source CMS
  4.  *
  5.  * Copyright (C) 2016 Studienkreis Tourismus
  6.  * @author     Holger Neuner <neuner@47gradnord.de>
  7.  * @project    47_CustomModule
  8.  * @license    commercial
  9.  */
  10. namespace CustomModule\Frontend\Modules;
  11. use Contao\Module;
  12. use Contao\PageModel;
  13. use Isotope\Isotope;
  14. use Isotope\Model\ProductCollection;
  15. class TopBar extends Module
  16. {
  17.     /**
  18.      * Template
  19.      * @var string
  20.      */
  21.     protected $strTemplate 'mod_TopBar';
  22.     /** @var bool  */
  23.     protected $feUserLoggedIn false;
  24.     /**
  25.      * Display a wildcard in the back end
  26.      *
  27.      * @return string
  28.      */
  29.     public function generate()
  30.     {
  31.         if (TL_MODE == 'BE')
  32.         {
  33.             /** @var \BackendTemplate|object $objTemplate */
  34.             $objTemplate = new \BackendTemplate('be_wildcard');
  35.             $objTemplate->wildcard '### ' utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['47_ModTopBar'][0]) . ' ###';
  36.             $objTemplate->title $this->headline;
  37.             $objTemplate->id $this->id;
  38.             $objTemplate->link $this->name;
  39.             $objTemplate->href 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' $this->id;
  40.             return $objTemplate->parse();
  41.         }
  42.         return parent::generate();
  43.     }
  44.     /**
  45.      * Generate the module
  46.      */
  47.     protected function compile()
  48.     {
  49.         /** @var \PageModel $objPage */
  50.         global $objPage;
  51.         // Set all Vars to Template by default
  52.         $this->Template->setData($this->arrData);
  53.         if (FE_USER_LOGGED_IN)
  54.         {
  55.             $this->feUserLoggedIn true;
  56.         }
  57.         // Left
  58.         $this->Template->modTopBarJumpToNewsletter PageModel::findByIdOrAlias($this->modTopBarJumpToNewsletter)->alias;
  59.         // Right
  60.         $this->Template->modTopBarJumpToCart PageModel::findByIdOrAlias($this->modTopBarJumpToCart)->alias;
  61.         $this->Template->modTopBarJumpToLogin PageModel::findByIdOrAlias($this->modTopBarJumpToLogin)->alias;
  62.         $this->Template->modTopBarJumpToLogout PageModel::findByIdOrAlias($this->modTopBarJumpToLogout)->alias;
  63.         $this->Template->feUserLoggedIn $this->feUserLoggedIn;
  64.         $this->Template->cartItems $this->getCartItems();
  65.     }
  66.     /**
  67.      * get Cart Items
  68.      *
  69.      * @return int
  70.      */
  71.     private function getCartItems()
  72.     {
  73.         /** @var ProductCollection $cart */
  74.         $cart = \Isotope\Isotope::getCart();
  75.         return count($cart->getItems());
  76.     }
  77. }