<?php
/**
* 47_CustomModule for Contao Open Source CMS
*
* Copyright (C) 2016 Studienkreis Tourismus
* @author Holger Neuner <neuner@47gradnord.de>
* @project 47_CustomModule
* @license commercial
*/
namespace CustomModule\Frontend\Modules;
use Contao\Module;
use Contao\PageModel;
use Isotope\Isotope;
use Isotope\Model\ProductCollection;
class TopBar extends Module
{
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_TopBar';
/** @var bool */
protected $feUserLoggedIn = false;
/**
* Display a wildcard in the back end
*
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE')
{
/** @var \BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['47_ModTopBar'][0]) . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
return parent::generate();
}
/**
* Generate the module
*/
protected function compile()
{
/** @var \PageModel $objPage */
global $objPage;
// Set all Vars to Template by default
$this->Template->setData($this->arrData);
if (FE_USER_LOGGED_IN)
{
$this->feUserLoggedIn = true;
}
// Left
$this->Template->modTopBarJumpToNewsletter = PageModel::findByIdOrAlias($this->modTopBarJumpToNewsletter)->alias;
// Right
$this->Template->modTopBarJumpToCart = PageModel::findByIdOrAlias($this->modTopBarJumpToCart)->alias;
$this->Template->modTopBarJumpToLogin = PageModel::findByIdOrAlias($this->modTopBarJumpToLogin)->alias;
$this->Template->modTopBarJumpToLogout = PageModel::findByIdOrAlias($this->modTopBarJumpToLogout)->alias;
$this->Template->feUserLoggedIn = $this->feUserLoggedIn;
$this->Template->cartItems = $this->getCartItems();
}
/**
* get Cart Items
*
* @return int
*/
private function getCartItems()
{
/** @var ProductCollection $cart */
$cart = \Isotope\Isotope::getCart();
return count($cart->getItems());
}
}