123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- <?php
- // Copyright (C) 2010-2015 Combodo SARL
- //
- // This file is part of iTop.
- //
- // iTop is free software; you can redistribute it and/or modify
- // it under the terms of the GNU Affero General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // iTop is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU Affero General Public License for more details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with iTop. If not, see <http://www.gnu.org/licenses/>
- namespace Combodo\iTop\Portal\Brick;
- use \ModuleDesign;
- use \Combodo\iTop\DesignElement;
- use \Combodo\iTop\Portal\Brick\AbstractBrick;
- /**
- * Description of PortalBrick
- *
- * Classes that will be used only in the portal, not the console.
- *
- * @author Guillaume Lajarige
- */
- abstract class PortalBrick extends AbstractBrick
- {
- const DEFAULT_WIDTH = 1;
- const DEFAULT_HEIGHT = 1;
- const DEFAULT_MODAL = false;
- const DEFAULT_VISIBLE_HOME = true;
- const DEFAULT_VISIBLE_NAVIGATION_MENU = true;
- const DEFAULT_DECORATION_CLASS_HOME = '';
- const DEFAULT_DECORATION_CLASS_NAVIGATION_MENU = '';
- const DEFAULT_TILE_TEMPLATE_PATH = 'itop-portal-base/portal/src/views/bricks/tile.html.twig';
- static $sRouteName = null;
- protected $iWidth;
- protected $iHeight;
- protected $bModal;
- protected $bVisibleHome;
- protected $bVisibleNavigationMenu;
- protected $sDecorationClassHome;
- protected $sDecorationClassNavigationMenu;
- protected $sTileTemplatePath;
- // Vars below are itemization from parent class
- protected $fRankHome;
- protected $fRankNavigationMenu;
- protected $sTitleHome;
- protected $sTitleNavigationMenu;
- static function GetRouteName()
- {
- return static::$sRouteName;
- }
- /**
- * Default attributes values of AbstractBrick are specified in the definition, not the constructor.
- */
- function __construct()
- {
- parent::__construct();
- $this->iWidth = static::DEFAULT_WIDTH;
- $this->iHeight = static::DEFAULT_HEIGHT;
- $this->bModal = static::DEFAULT_MODAL;
- $this->bVisibleHome = static::DEFAULT_VISIBLE_HOME;
- $this->bVisibleNavigationMenu = static::DEFAULT_VISIBLE_NAVIGATION_MENU;
- $this->sDecorationClassHome = static::DEFAULT_DECORATION_CLASS_HOME;
- $this->sDecorationClassNavigationMenu = static::DEFAULT_DECORATION_CLASS_NAVIGATION_MENU;
- $this->sTileTemplatePath = static::DEFAULT_TILE_TEMPLATE_PATH;
- }
- /**
- * Returns width of the brick
- *
- * @return int
- */
- public function GetWidth()
- {
- return $this->iWidth;
- }
- /**
- * Returns height of the brick
- *
- * @return int
- */
- public function GetHeight()
- {
- return $this->iHeight;
- }
- /**
- * Returns if the brick will show in a modal dialog or not
- *
- * @return boolean
- */
- public function GetModal()
- {
- return $this->bModal;
- }
- /**
- * Returns if the brick is visible on the portal's home page
- *
- * @return int
- */
- public function GetVisibleHome()
- {
- return $this->bVisibleHome;
- }
- /**
- * Returns if the brick is visible on the portal's navigation menu
- *
- * @return int
- */
- public function GetVisibleNavigationMenu()
- {
- return $this->bVisibleNavigationMenu;
- }
- /**
- * Returns if the brick's rank on the portal's home page
- *
- * @return int
- */
- public function GetRankHome()
- {
- return $this->fRankHome;
- }
- /**
- * Returns if the brick's rank on the portal's navigation menu
- *
- * @return int
- */
- public function GetRankNavigationMenu()
- {
- return $this->fRankNavigationMenu;
- }
- /**
- * Return the css class that will be applied to the brick's decoration in its home tile
- *
- * @return string
- */
- public function GetDecorationClassHome()
- {
- return $this->sDecorationClassHome;
- }
- /**
- * Return the css class that will be applied to the brick's decoration in its navigation menu item
- *
- * @return string
- */
- public function GetDecorationClassNavigationMenu()
- {
- return $this->sDecorationClassNavigationMenu;
- }
- /**
- * Return the brick's title on the home page
- *
- * @return string
- */
- public function GetTitleHome()
- {
- return $this->sTitleHome;
- }
- /**
- * Return the brick's title on the navigation menu
- *
- * @return string
- */
- public function GetTitleNavigationMenu()
- {
- return $this->sTitleNavigationMenu;
- }
- /**
- * Returns the brick tile template path
- *
- * @return string
- */
- public function GetTileTemplatePath()
- {
- return $this->sTileTemplatePath;
- }
- /**
- * Sets the width of the brick
- *
- * @param boolean $iWidth
- */
- public function SetWidth($iWidth)
- {
- $this->iWidth = $iWidth;
- return $this;
- }
- /**
- * Sets the width of the brick
- *
- * @param boolean $iWidth
- */
- public function SetHeight($iHeight)
- {
- $this->iHeight = $iHeight;
- return $this;
- }
- /**
- * Sets if the brick will show in a modal dialog or not
- *
- * @param boolean $bModal
- */
- public function SetModal($bModal)
- {
- $this->bModal = $bModal;
- return $this;
- }
- /**
- * Sets if the brick is visible on the portal's home
- *
- * @param boolean $iWidth
- */
- public function SetVisibleHome($bVisibleHome)
- {
- $this->bVisibleHome = $bVisibleHome;
- return $this;
- }
- /**
- * Sets if the brick is visible on the portal's navigation menu
- *
- * @param boolean $iWidth
- */
- public function SetVisibleNavigationMenu($bVisibleNavigationMenu)
- {
- $this->bVisibleNavigationMenu = $bVisibleNavigationMenu;
- return $this;
- }
- /**
- * Sets if the brick's rank on the portal's home
- *
- * @param boolean $fRank
- */
- public function SetRankHome($fRankHome)
- {
- $this->fRankHome = $fRankHome;
- return $this;
- }
- /**
- * Sets if the brick's rank on the portal's navigation menu
- *
- * @param boolean $fRank
- */
- public function SetRankNavigationMenu($fRankNavigationMenu)
- {
- $this->fRankNavigationMenu = $fRankNavigationMenu;
- return $this;
- }
- /**
- * Sets if the brick's decoration class on the portal's home
- *
- * @param boolean $sDecorationClassHome
- */
- public function SetDecorationClassHome($sDecorationClassHome)
- {
- $this->sDecorationClassHome = $sDecorationClassHome;
- return $this;
- }
- /**
- * Sets if the brick's decoration class on the portal's navigation menu
- *
- * @param boolean $sDecorationClassNavigationMenu
- */
- public function SetDecorationClassNavigationMenu($sDecorationClassNavigationMenu)
- {
- $this->sDecorationClassNavigationMenu = $sDecorationClassNavigationMenu;
- return $this;
- }
- /**
- * Sets if the brick's title on the portal's home
- *
- * @param boolean $sTitleHome
- */
- public function SetTitleHome($sTitleHome)
- {
- $this->sTitleHome = $sTitleHome;
- return $this;
- }
- /**
- * Sets if the brick's title on the portal's navigation menu
- *
- * @param boolean $sTitleNavigationMenu
- */
- public function SetTitleNavigationMenu($sTitleNavigationMenu)
- {
- $this->sTitleNavigationMenu = $sTitleNavigationMenu;
- return $this;
- }
- /**
- * Sets the brick tile template path
- *
- * @param boolean $sTileTemplatePath
- */
- public function SetTileTemplatePath($sTileTemplatePath)
- {
- $this->sTileTemplatePath = $sTileTemplatePath;
- return $this;
- }
- /**
- * Load the brick's data from the xml passed as a ModuleDesignElement.
- * This is used to set all the brick attributes at once.
- *
- * @param \Combodo\iTop\DesignElement $oMDElement
- * @return PortalBrick
- */
- public function LoadFromXml(DesignElement $oMDElement)
- {
- parent::LoadFromXml($oMDElement);
- // Checking specific elements
- foreach ($oMDElement->GetNodes('./*') as $oBrickSubNode)
- {
- switch ($oBrickSubNode->nodeName)
- {
- case 'width':
- $this->SetWidth((int) $oBrickSubNode->GetText(static::DEFAULT_WIDTH));
- break;
- case 'height':
- $this->SetHeight((int) $oBrickSubNode->GetText(static::DEFAULT_HEIGHT));
- break;
- case 'modal':
- $bModal = ($oBrickSubNode->GetText(static::DEFAULT_MODAL) === 'true');
- $this->SetModal($bModal);
- break;
- case 'visible':
- // Default value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('default');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = ($oOptionalNode->GetText() === 'false') ? false : true;
- $this->SetVisibleHome($optionalNodeValue);
- $this->SetVisibleNavigationMenu($optionalNodeValue);
- }
- // Home value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('home');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = ($oOptionalNode->GetText() === 'false') ? false : true;
- $this->SetVisibleHome($optionalNodeValue);
- }
- // Navigation menu value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('navigation_menu');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = ($oOptionalNode->GetText() === 'false') ? false : true;
- $this->SetVisibleNavigationMenu($optionalNodeValue);
- }
- break;
- case 'templates':
- $oTemplateNodeList = $oBrickSubNode->GetNodes('template[@id=' . ModuleDesign::XPathQuote('tile') . ']');
- if ($oTemplateNodeList->length > 0)
- {
- $this->SetTileTemplatePath($oTemplateNodeList->item(0)->GetText(static::DEFAULT_TILE_TEMPLATE_PATH));
- }
- break;
- case 'rank':
- // Setting value from parent attribute
- $this->SetRankHome($this->fRank);
- $this->SetRankNavigationMenu($this->fRank);
- // Default value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('default');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_RANK);
- $this->SetRankHome($optionalNodeValue);
- $this->SetRankNavigationMenu($optionalNodeValue);
- }
- // Home value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('home');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_RANK);
- $this->SetRankHome($optionalNodeValue);
- }
- // Navigation menu value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('navigation_menu');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_RANK);
- $this->SetRankNavigationMenu($optionalNodeValue);
- }
- break;
- case 'title':
- // Setting value from parent attribute
- $this->SetTitleHome($this->sTitle);
- $this->SetTitleNavigationMenu($this->sTitle);
- // Default value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('default');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_TITLE);
- $this->SetTitleHome($optionalNodeValue);
- $this->SetTitleNavigationMenu($optionalNodeValue);
- }
- // Home value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('home');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_TITLE);
- $this->SetTitleHome($optionalNodeValue);
- }
- // Navigation menu value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('navigation_menu');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_TITLE);
- $this->SetTitleNavigationMenu($optionalNodeValue);
- $this->SetTitle($optionalNodeValue);
- }
- break;
- case 'decoration_class':
- // Setting value from parent attribute
- $this->SetDecorationClassHome(static::DEFAULT_DECORATION_CLASS_HOME);
- $this->SetDecorationClassNavigationMenu(static::DEFAULT_DECORATION_CLASS_NAVIGATION_MENU);
- // Default value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('default');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_DECORATION_CLASS_NAVIGATION_MENU);
- $this->SetDecorationClassHome($optionalNodeValue);
- $this->SetDecorationClassNavigationMenu($optionalNodeValue);
- }
- // Home value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('home');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_DECORATION_CLASS_HOME);
- $this->SetDecorationClassHome($optionalNodeValue);
- }
- // Navigation menu value
- $oOptionalNode = $oBrickSubNode->GetOptionalElement('navigation_menu');
- if ($oOptionalNode !== null)
- {
- $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_DECORATION_CLASS_NAVIGATION_MENU);
- $this->SetDecorationClassNavigationMenu($optionalNodeValue);
- }
- break;
- }
- }
- return $this;
- }
- }
- ?>
|