A Qcodo based CMS/ecommerce framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
10 KiB

12 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. /**
  4. * Class ContentBlockView - selects and renders items in a content block.
  5. *
  6. * This is the View class for display functionality of the ContentBlock class.
  7. * It provides a div based area for content with hierarchy, css id and class
  8. * and a relationship to the basic areas provided by PageView. It is to a
  9. * ContentBlock that a ContentItem, MenuItem or ActionItem is assigned. This
  10. * class will render any child ContentBlocks and all associated Items. These
  11. * associations may configured via the QuasiCMS administrative interface and
  12. * will then automatically be reflected in the associated PageView display.
  13. *
  14. * This class is created by PageView which passes a reference to the main parent
  15. * object and the ContentBlock object from the content_block table in the database.
  16. *
  17. *@author Erik Winn <erikwinnmail@yahoo.com>
  18. *
  19. *
  20. * $Id: ContentBlockView.class.php 127 2008-09-08 18:32:18Z erikwinn $
  21. *@version 0.1
  22. *
  23. *@copyright (C) 2008 by Erik Winn
  24. *@license GPL v.2
  25. This program is free software; you can redistribute it and/or modify
  26. it under the terms of the GNU General Public License as published by
  27. the Free Software Foundation; either version 2 of the License, or
  28. (at your option) any later version.
  29. This program is distributed in the hope that it will be useful,
  30. but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. GNU General Public License for more details.
  33. You should have received a copy of the GNU General Public License
  34. along with this program; if not, write to the Free Software
  35. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  36. *
  37. * @package Quasi
  38. * @subpackage Views
  39. *
  40. */
  41. class ContentBlockView extends QPanel
  42. {
  43. protected $objParentObject;
  44. protected $objContentBlock;
  45. ///Arrays of child blocks and content items and menus managed
  46. public $aryChildContentBlockViews = null;
  47. public $aryContentItemViews = null;
  48. public $aryMenuViews = null;
  49. public $aryModules = null;
  50. public $aryModuleViews = null;
  51. /// Metacontrol to handle title and description - maybe drop in favor of panels to optimize later.
  52. protected $mctContentBlock;
  53. /// Controls that allow the viewing of ContentBlock's individual data fields
  54. protected $pnlTitle;
  55. protected $pnlDescription;
  56. /// This ContentBlock's CSS id
  57. protected $strCssId;
  58. public function __construct($objParentObject, $objContentBlock, $strCssId)
  59. {
  60. //Parent must always be a child of QForm or Qcontrol
  61. $this->objParentObject = $objParentObject;
  62. $this->strCssId = $strCssId;
  63. $this->objContentBlock = $objContentBlock;
  64. try {
  65. parent::__construct($this->objParentObject, $this->strCssId);
  66. } catch (QCallerException $objExc) {
  67. $objExc->IncrementOffset();
  68. throw $objExc;
  69. }
  70. $this->initModuleViews();
  71. $this->initContentBlockViews();
  72. /*An idea:
  73. if(!$this->mctContentBlock || !$this->objContentBlock )
  74. $this->Template = 'BasicContentBlock.tpl.php';
  75. else
  76. switch( $this->objContentBlock->Type )
  77. {
  78. case 'Menu':
  79. $this->Template = 'MenuContentBlock.tpl.php';
  80. break;
  81. case 'MenuItem':
  82. $this->Template = 'MenuItemContentBlock.tpl.php';
  83. break;
  84. case 'Header':
  85. $this->Template = 'HeaderContentBlock.tpl.php';
  86. break;
  87. case 'RightPanel':
  88. $this->Template = 'RightPanelContentBlock.tpl.php';
  89. break;
  90. case 'LeftPanel':
  91. $this->Template = 'LeftPanelContentBlock.tpl.php';
  92. break;
  93. case 'CenterPanel':
  94. $this->Template = 'CenterPanelContentBlock.tpl.php';
  95. break;
  96. case 'Footer':
  97. $this->Template = 'FooterContentBlock.tpl.php';
  98. break;
  99. case 'BlockHeader':
  100. $this->Template = 'BlockHeaderContentBlock.tpl.php';
  101. break;
  102. case 'BlockFooter':
  103. $this->Template = 'BlockFooterContentBlock.tpl.php';
  104. break;
  105. default:
  106. $this->Template = 'BasicContentBlock.tpl.php';
  107. }*/
  108. }
  109. /**
  110. * This function handles rendering of "passive" content blocks. It is invoked if the
  111. * object passed to the constructor is of type ContentBlock. Passive content blocks
  112. * contain only data to be displayed and do not have any (overt) action controls.
  113. */
  114. protected function initContentBlockViews()
  115. {
  116. ///@todo drop the meta control to optimize later ..
  117. $this->mctContentBlock = new ContentBlockMetaControl($this, $this->objContentBlock);
  118. $this->pnlTitle = $this->mctContentBlock->pnlTitle_Create($this->CssId );
  119. $this->pnlTitle->CssClass = 'ContentBlockTitle';
  120. $this->pnlDescription = $this->mctContentBlock->pnlDescription_Create($this->CssId);
  121. $this->pnlDescription->CssClass = 'ContentBlockDescription';
  122. // Setup the Template
  123. $this->Template = __QUASI_CORE_TEMPLATES__ . '/ContentBlockView.tpl.php';
  124. foreach ( $this->objContentBlock->GetChildContentBlockArray(
  125. QQ::Clause (QQ::OrderBy(QQN::ContentBlock()->SortOrder) )
  126. ) as $childContentBlock )
  127. {
  128. $this->aryChildContentBlockViews[] = new ContentBlockView( $this, $childContentBlock, null);
  129. }
  130. foreach ( $this->objContentBlock->GetContentItemArray(
  131. QQ::Clause (QQ::OrderBy(QQN::ContentItem()->SortOrder) )
  132. ) as $objContentItem )
  133. {
  134. $objContentItemView = new ContentItemView( $this, $objContentItem );
  135. $objContentItemView->CssClass = $objContentItem->Type;
  136. $this->aryContentItemViews[] = $objContentItemView;
  137. }
  138. foreach ( $this->objContentBlock->GetMenuArray(
  139. QQ::Clause (QQ::OrderBy(QQN::Menu()->SortOrder) )
  140. ) as $objMenu )
  141. {
  142. $objMenuView = new MenuView( $this, $objMenu );
  143. $objMenuView->CssClass = $objMenu->Type;
  144. $this->aryMenuViews[] = $objMenuView;
  145. }
  146. return true;
  147. }
  148. protected function initModuleViews()
  149. {
  150. $this->aryModules = $this->objContentBlock->GetModuleArray();
  151. if(!$this->aryModules)
  152. return false;
  153. foreach($this->aryModules as $objModule)
  154. {
  155. $strModuleClassName = $objModule->ClassName;
  156. try{
  157. $objModuleView = new $strModuleClassName($this, $objModule);
  158. } catch (QCallerException $objExc) {
  159. $objExc->IncrementOffset();
  160. throw $objExc;
  161. }
  162. $this->aryModuleViews[] = $objModuleView;
  163. ///@todo - add module to the global list
  164. /* if(!IndexPage::$MainWindow->GetActiveModule($strModuleClassName) )
  165. IndexPage::$MainWindow->AddActiveModule ( $objModuleView );*/
  166. }
  167. }
  168. public function __get($strName)
  169. {
  170. switch ($strName)
  171. {
  172. case 'HasModules':
  173. return ! empty($this->aryModuleViews);
  174. case 'HasMenus':
  175. return ! empty($this->aryMenuViews);
  176. case 'HasContentItems':
  177. return ! empty($this->aryContentItemViews);
  178. case 'HasContentBlocks':
  179. return ! empty($this->aryChildContentBlockViews);
  180. case 'Title':
  181. return $this->objContentBlock->Title ;
  182. case 'Description':
  183. return $this->objContentBlock->Description ;
  184. case 'ShowTitle':
  185. return $this->objContentBlock->ShowTitle ;
  186. case 'ShowDescription':
  187. return $this->objContentBlock->ShowDescription ;
  188. case 'CssId':
  189. return $this->strCssId ;
  190. case 'TitlePanel':
  191. return $this->pnlTitle ;
  192. case 'DescriptionPanel':
  193. return $this->pnlDescription ;
  194. default:
  195. try {
  196. return parent::__get($strName);
  197. } catch (QCallerException $objExc) {
  198. $objExc->IncrementOffset();
  199. throw $objExc;
  200. }
  201. }
  202. }
  203. public function __set($strName, $mixValue)
  204. {
  205. switch ($strName)
  206. {
  207. case 'Title':
  208. try {
  209. return ($this->objContentBlock->Title = QType::Cast($mixValue, QType::String));
  210. } catch (QInvalidCastException $objExc) {
  211. $objExc->IncrementOffset();
  212. throw $objExc;
  213. }
  214. case 'Description':
  215. try {
  216. return ($this->objContentBlock->Description = QType::Cast($mixValue, QType::String));
  217. } catch (QInvalidCastException $objExc) {
  218. $objExc->IncrementOffset();
  219. throw $objExc;
  220. }
  221. default:
  222. try {
  223. return (parent::__set($strName, $mixValue));
  224. } catch (QCallerException $objExc) {
  225. $objExc->IncrementOffset();
  226. throw $objExc;
  227. }
  228. }
  229. }
  230. }
  231. ?>