portalbrick.class.inc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <?php
  2. // Copyright (C) 2010-2015 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. namespace Combodo\iTop\Portal\Brick;
  19. use \ModuleDesign;
  20. use \Combodo\iTop\DesignElement;
  21. use \Combodo\iTop\Portal\Brick\AbstractBrick;
  22. /**
  23. * Description of PortalBrick
  24. *
  25. * Classes that will be used only in the portal, not the console.
  26. *
  27. * @author Guillaume Lajarige
  28. */
  29. abstract class PortalBrick extends AbstractBrick
  30. {
  31. const DEFAULT_WIDTH = 1;
  32. const DEFAULT_HEIGHT = 1;
  33. const DEFAULT_MODAL = false;
  34. const DEFAULT_VISIBLE_HOME = true;
  35. const DEFAULT_VISIBLE_NAVIGATION_MENU = true;
  36. const DEFAULT_DECORATION_CLASS_HOME = '';
  37. const DEFAULT_DECORATION_CLASS_NAVIGATION_MENU = '';
  38. const DEFAULT_TILE_TEMPLATE_PATH = 'itop-portal-base/portal/src/views/bricks/tile.html.twig';
  39. static $sRouteName = null;
  40. protected $iWidth;
  41. protected $iHeight;
  42. protected $bModal;
  43. protected $bVisibleHome;
  44. protected $bVisibleNavigationMenu;
  45. protected $sDecorationClassHome;
  46. protected $sDecorationClassNavigationMenu;
  47. protected $sTileTemplatePath;
  48. // Vars below are itemization from parent class
  49. protected $fRankHome;
  50. protected $fRankNavigationMenu;
  51. protected $sTitleHome;
  52. protected $sTitleNavigationMenu;
  53. static function GetRouteName()
  54. {
  55. return static::$sRouteName;
  56. }
  57. /**
  58. * Default attributes values of AbstractBrick are specified in the definition, not the constructor.
  59. */
  60. function __construct()
  61. {
  62. parent::__construct();
  63. $this->iWidth = static::DEFAULT_WIDTH;
  64. $this->iHeight = static::DEFAULT_HEIGHT;
  65. $this->bModal = static::DEFAULT_MODAL;
  66. $this->bVisibleHome = static::DEFAULT_VISIBLE_HOME;
  67. $this->bVisibleNavigationMenu = static::DEFAULT_VISIBLE_NAVIGATION_MENU;
  68. $this->sDecorationClassHome = static::DEFAULT_DECORATION_CLASS_HOME;
  69. $this->sDecorationClassNavigationMenu = static::DEFAULT_DECORATION_CLASS_NAVIGATION_MENU;
  70. $this->sTileTemplatePath = static::DEFAULT_TILE_TEMPLATE_PATH;
  71. }
  72. /**
  73. * Returns width of the brick
  74. *
  75. * @return int
  76. */
  77. public function GetWidth()
  78. {
  79. return $this->iWidth;
  80. }
  81. /**
  82. * Returns height of the brick
  83. *
  84. * @return int
  85. */
  86. public function GetHeight()
  87. {
  88. return $this->iHeight;
  89. }
  90. /**
  91. * Returns if the brick will show in a modal dialog or not
  92. *
  93. * @return boolean
  94. */
  95. public function GetModal()
  96. {
  97. return $this->bModal;
  98. }
  99. /**
  100. * Returns if the brick is visible on the portal's home page
  101. *
  102. * @return int
  103. */
  104. public function GetVisibleHome()
  105. {
  106. return $this->bVisibleHome;
  107. }
  108. /**
  109. * Returns if the brick is visible on the portal's navigation menu
  110. *
  111. * @return int
  112. */
  113. public function GetVisibleNavigationMenu()
  114. {
  115. return $this->bVisibleNavigationMenu;
  116. }
  117. /**
  118. * Returns if the brick's rank on the portal's home page
  119. *
  120. * @return int
  121. */
  122. public function GetRankHome()
  123. {
  124. return $this->fRankHome;
  125. }
  126. /**
  127. * Returns if the brick's rank on the portal's navigation menu
  128. *
  129. * @return int
  130. */
  131. public function GetRankNavigationMenu()
  132. {
  133. return $this->fRankNavigationMenu;
  134. }
  135. /**
  136. * Return the css class that will be applied to the brick's decoration in its home tile
  137. *
  138. * @return string
  139. */
  140. public function GetDecorationClassHome()
  141. {
  142. return $this->sDecorationClassHome;
  143. }
  144. /**
  145. * Return the css class that will be applied to the brick's decoration in its navigation menu item
  146. *
  147. * @return string
  148. */
  149. public function GetDecorationClassNavigationMenu()
  150. {
  151. return $this->sDecorationClassNavigationMenu;
  152. }
  153. /**
  154. * Return the brick's title on the home page
  155. *
  156. * @return string
  157. */
  158. public function GetTitleHome()
  159. {
  160. return $this->sTitleHome;
  161. }
  162. /**
  163. * Return the brick's title on the navigation menu
  164. *
  165. * @return string
  166. */
  167. public function GetTitleNavigationMenu()
  168. {
  169. return $this->sTitleNavigationMenu;
  170. }
  171. /**
  172. * Returns the brick tile template path
  173. *
  174. * @return string
  175. */
  176. public function GetTileTemplatePath()
  177. {
  178. return $this->sTileTemplatePath;
  179. }
  180. /**
  181. * Sets the width of the brick
  182. *
  183. * @param boolean $iWidth
  184. */
  185. public function SetWidth($iWidth)
  186. {
  187. $this->iWidth = $iWidth;
  188. return $this;
  189. }
  190. /**
  191. * Sets the width of the brick
  192. *
  193. * @param boolean $iWidth
  194. */
  195. public function SetHeight($iHeight)
  196. {
  197. $this->iHeight = $iHeight;
  198. return $this;
  199. }
  200. /**
  201. * Sets if the brick will show in a modal dialog or not
  202. *
  203. * @param boolean $bModal
  204. */
  205. public function SetModal($bModal)
  206. {
  207. $this->bModal = $bModal;
  208. return $this;
  209. }
  210. /**
  211. * Sets if the brick is visible on the portal's home
  212. *
  213. * @param boolean $iWidth
  214. */
  215. public function SetVisibleHome($bVisibleHome)
  216. {
  217. $this->bVisibleHome = $bVisibleHome;
  218. return $this;
  219. }
  220. /**
  221. * Sets if the brick is visible on the portal's navigation menu
  222. *
  223. * @param boolean $iWidth
  224. */
  225. public function SetVisibleNavigationMenu($bVisibleNavigationMenu)
  226. {
  227. $this->bVisibleNavigationMenu = $bVisibleNavigationMenu;
  228. return $this;
  229. }
  230. /**
  231. * Sets if the brick's rank on the portal's home
  232. *
  233. * @param boolean $fRank
  234. */
  235. public function SetRankHome($fRankHome)
  236. {
  237. $this->fRankHome = $fRankHome;
  238. return $this;
  239. }
  240. /**
  241. * Sets if the brick's rank on the portal's navigation menu
  242. *
  243. * @param boolean $fRank
  244. */
  245. public function SetRankNavigationMenu($fRankNavigationMenu)
  246. {
  247. $this->fRankNavigationMenu = $fRankNavigationMenu;
  248. return $this;
  249. }
  250. /**
  251. * Sets if the brick's decoration class on the portal's home
  252. *
  253. * @param boolean $sDecorationClassHome
  254. */
  255. public function SetDecorationClassHome($sDecorationClassHome)
  256. {
  257. $this->sDecorationClassHome = $sDecorationClassHome;
  258. return $this;
  259. }
  260. /**
  261. * Sets if the brick's decoration class on the portal's navigation menu
  262. *
  263. * @param boolean $sDecorationClassNavigationMenu
  264. */
  265. public function SetDecorationClassNavigationMenu($sDecorationClassNavigationMenu)
  266. {
  267. $this->sDecorationClassNavigationMenu = $sDecorationClassNavigationMenu;
  268. return $this;
  269. }
  270. /**
  271. * Sets if the brick's title on the portal's home
  272. *
  273. * @param boolean $sTitleHome
  274. */
  275. public function SetTitleHome($sTitleHome)
  276. {
  277. $this->sTitleHome = $sTitleHome;
  278. return $this;
  279. }
  280. /**
  281. * Sets if the brick's title on the portal's navigation menu
  282. *
  283. * @param boolean $sTitleNavigationMenu
  284. */
  285. public function SetTitleNavigationMenu($sTitleNavigationMenu)
  286. {
  287. $this->sTitleNavigationMenu = $sTitleNavigationMenu;
  288. return $this;
  289. }
  290. /**
  291. * Sets the brick tile template path
  292. *
  293. * @param boolean $sTileTemplatePath
  294. */
  295. public function SetTileTemplatePath($sTileTemplatePath)
  296. {
  297. $this->sTileTemplatePath = $sTileTemplatePath;
  298. return $this;
  299. }
  300. /**
  301. * Load the brick's data from the xml passed as a ModuleDesignElement.
  302. * This is used to set all the brick attributes at once.
  303. *
  304. * @param \Combodo\iTop\DesignElement $oMDElement
  305. * @return PortalBrick
  306. */
  307. public function LoadFromXml(DesignElement $oMDElement)
  308. {
  309. parent::LoadFromXml($oMDElement);
  310. // Checking specific elements
  311. foreach ($oMDElement->GetNodes('./*') as $oBrickSubNode)
  312. {
  313. switch ($oBrickSubNode->nodeName)
  314. {
  315. case 'width':
  316. $this->SetWidth((int) $oBrickSubNode->GetText(static::DEFAULT_WIDTH));
  317. break;
  318. case 'height':
  319. $this->SetHeight((int) $oBrickSubNode->GetText(static::DEFAULT_HEIGHT));
  320. break;
  321. case 'modal':
  322. $bModal = ($oBrickSubNode->GetText(static::DEFAULT_MODAL) === 'true');
  323. $this->SetModal($bModal);
  324. break;
  325. case 'visible':
  326. // Default value
  327. $oOptionalNode = $oBrickSubNode->GetOptionalElement('default');
  328. if ($oOptionalNode !== null)
  329. {
  330. $optionalNodeValue = ($oOptionalNode->GetText() === 'false') ? false : true;
  331. $this->SetVisibleHome($optionalNodeValue);
  332. $this->SetVisibleNavigationMenu($optionalNodeValue);
  333. }
  334. // Home value
  335. $oOptionalNode = $oBrickSubNode->GetOptionalElement('home');
  336. if ($oOptionalNode !== null)
  337. {
  338. $optionalNodeValue = ($oOptionalNode->GetText() === 'false') ? false : true;
  339. $this->SetVisibleHome($optionalNodeValue);
  340. }
  341. // Navigation menu value
  342. $oOptionalNode = $oBrickSubNode->GetOptionalElement('navigation_menu');
  343. if ($oOptionalNode !== null)
  344. {
  345. $optionalNodeValue = ($oOptionalNode->GetText() === 'false') ? false : true;
  346. $this->SetVisibleNavigationMenu($optionalNodeValue);
  347. }
  348. break;
  349. case 'templates':
  350. $oTemplateNodeList = $oBrickSubNode->GetNodes('template[@id=' . ModuleDesign::XPathQuote('tile') . ']');
  351. if ($oTemplateNodeList->length > 0)
  352. {
  353. $this->SetTileTemplatePath($oTemplateNodeList->item(0)->GetText(static::DEFAULT_TILE_TEMPLATE_PATH));
  354. }
  355. break;
  356. case 'rank':
  357. // Setting value from parent attribute
  358. $this->SetRankHome($this->fRank);
  359. $this->SetRankNavigationMenu($this->fRank);
  360. // Default value
  361. $oOptionalNode = $oBrickSubNode->GetOptionalElement('default');
  362. if ($oOptionalNode !== null)
  363. {
  364. $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_RANK);
  365. $this->SetRankHome($optionalNodeValue);
  366. $this->SetRankNavigationMenu($optionalNodeValue);
  367. }
  368. // Home value
  369. $oOptionalNode = $oBrickSubNode->GetOptionalElement('home');
  370. if ($oOptionalNode !== null)
  371. {
  372. $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_RANK);
  373. $this->SetRankHome($optionalNodeValue);
  374. }
  375. // Navigation menu value
  376. $oOptionalNode = $oBrickSubNode->GetOptionalElement('navigation_menu');
  377. if ($oOptionalNode !== null)
  378. {
  379. $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_RANK);
  380. $this->SetRankNavigationMenu($optionalNodeValue);
  381. }
  382. break;
  383. case 'title':
  384. // Setting value from parent attribute
  385. $this->SetTitleHome($this->sTitle);
  386. $this->SetTitleNavigationMenu($this->sTitle);
  387. // Default value
  388. $oOptionalNode = $oBrickSubNode->GetOptionalElement('default');
  389. if ($oOptionalNode !== null)
  390. {
  391. $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_TITLE);
  392. $this->SetTitleHome($optionalNodeValue);
  393. $this->SetTitleNavigationMenu($optionalNodeValue);
  394. }
  395. // Home value
  396. $oOptionalNode = $oBrickSubNode->GetOptionalElement('home');
  397. if ($oOptionalNode !== null)
  398. {
  399. $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_TITLE);
  400. $this->SetTitleHome($optionalNodeValue);
  401. }
  402. // Navigation menu value
  403. $oOptionalNode = $oBrickSubNode->GetOptionalElement('navigation_menu');
  404. if ($oOptionalNode !== null)
  405. {
  406. $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_TITLE);
  407. $this->SetTitleNavigationMenu($optionalNodeValue);
  408. $this->SetTitle($optionalNodeValue);
  409. }
  410. break;
  411. case 'decoration_class':
  412. // Setting value from parent attribute
  413. $this->SetDecorationClassHome(static::DEFAULT_DECORATION_CLASS_HOME);
  414. $this->SetDecorationClassNavigationMenu(static::DEFAULT_DECORATION_CLASS_NAVIGATION_MENU);
  415. // Default value
  416. $oOptionalNode = $oBrickSubNode->GetOptionalElement('default');
  417. if ($oOptionalNode !== null)
  418. {
  419. $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_DECORATION_CLASS_NAVIGATION_MENU);
  420. $this->SetDecorationClassHome($optionalNodeValue);
  421. $this->SetDecorationClassNavigationMenu($optionalNodeValue);
  422. }
  423. // Home value
  424. $oOptionalNode = $oBrickSubNode->GetOptionalElement('home');
  425. if ($oOptionalNode !== null)
  426. {
  427. $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_DECORATION_CLASS_HOME);
  428. $this->SetDecorationClassHome($optionalNodeValue);
  429. }
  430. // Navigation menu value
  431. $oOptionalNode = $oBrickSubNode->GetOptionalElement('navigation_menu');
  432. if ($oOptionalNode !== null)
  433. {
  434. $optionalNodeValue = $oOptionalNode->GetText(static::DEFAULT_DECORATION_CLASS_NAVIGATION_MENU);
  435. $this->SetDecorationClassNavigationMenu($optionalNodeValue);
  436. }
  437. break;
  438. }
  439. }
  440. return $this;
  441. }
  442. }
  443. ?>