A QCodo powered CMS
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.

228 lines
7.5 KiB

  1. <?php
  2. if(!defined('QUINTACMS') ) die("No quinta.");
  3. /**
  4. * Class ContentBlockController - 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 PageController. 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 QuintaCMS administrative interface and
  12. * will then automatically be reflected in the associated PageController display.
  13. *
  14. * This class is created by PageController 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 <sidewalksoftware@gmail.com>
  18. *
  19. *@version 0.3
  20. *
  21. * @package Quinta
  22. * @subpackage Controllers
  23. */
  24. class ContentBlockController extends QPanel{
  25. protected $objParentObject;
  26. protected $objContentBlock;
  27. ///Arrays of child blocks and content items and menus managed
  28. public $aryChildContentBlockControllers = null;
  29. public $aryContentItemControllers = null;
  30. public $aryMenuControllers = null;
  31. public $aryModules = null;
  32. public $aryModuleViews = null;
  33. /// Metacontrol to handle title and description - maybe drop in favor of panels to optimize later.
  34. protected $mctContentBlock;
  35. /// Controls that allow the viewing of ContentBlock's individual data fields
  36. protected $pnlTitle;
  37. protected $pnlDescription;
  38. /// This ContentBlock's CSS id
  39. protected $strCssId;
  40. public function __construct($objParentObject, $objContentBlock, $strCssId){
  41. //Parent must always be a child of QForm or Qcontrol
  42. $this->objParentObject = $objParentObject;
  43. $this->strCssId = $strCssId;
  44. $this->objContentBlock = $objContentBlock;
  45. try {
  46. parent::__construct($this->objParentObject, $this->strCssId);
  47. } catch (QCallerException $objExc) {
  48. $objExc->IncrementOffset();
  49. throw $objExc;
  50. }
  51. $this->initModuleViews();
  52. $this->initContentBlockControllers();
  53. /*An idea:
  54. if(!$this->mctContentBlock || !$this->objContentBlock )
  55. $this->Template = 'BasicContentBlock.tpl.php';
  56. else
  57. switch( $this->objContentBlock->Type )
  58. {
  59. case 'Menu':
  60. $this->Template = 'MenuContentBlock.tpl.php';
  61. break;
  62. case 'MenuItem':
  63. $this->Template = 'MenuItemContentBlock.tpl.php';
  64. break;
  65. case 'Header':
  66. $this->Template = 'HeaderContentBlock.tpl.php';
  67. break;
  68. case 'RightPanel':
  69. $this->Template = 'RightPanelContentBlock.tpl.php';
  70. break;
  71. case 'LeftPanel':
  72. $this->Template = 'LeftPanelContentBlock.tpl.php';
  73. break;
  74. case 'CenterPanel':
  75. $this->Template = 'CenterPanelContentBlock.tpl.php';
  76. break;
  77. case 'Footer':
  78. $this->Template = 'FooterContentBlock.tpl.php';
  79. break;
  80. case 'BlockHeader':
  81. $this->Template = 'BlockHeaderContentBlock.tpl.php';
  82. break;
  83. case 'BlockFooter':
  84. $this->Template = 'BlockFooterContentBlock.tpl.php';
  85. break;
  86. default:
  87. $this->Template = 'BasicContentBlock.tpl.php';
  88. }*/
  89. }
  90. /**
  91. * This function handles rendering of "passive" content blocks. It is invoked if the
  92. * object passed to the constructor is of type ContentBlock. Passive content blocks
  93. * contain only data to be displayed and do not have any (overt) action controls.
  94. */
  95. protected function initContentBlockControllers(){
  96. ///@todo drop the meta control to optimize later ..
  97. $this->mctContentBlock = new ContentBlockMetaControl($this, $this->objContentBlock);
  98. $this->pnlTitle = $this->mctContentBlock->pnlTitle_Create($this->CssId );
  99. $this->pnlTitle->CssClass = 'ContentBlockTitle';
  100. $this->pnlDescription = $this->mctContentBlock->pnlDescription_Create($this->CssId);
  101. $this->pnlDescription->CssClass = 'ContentBlockDescription';
  102. // Setup the Template
  103. $this->Template = __QUINTA_CORE_VIEWS__ . '/ContentBlockView.tpl.php';
  104. // foreach ( $this->objContentBlock->GetChildContentBlockArray(
  105. foreach ( ContentBlock::LoadArrayByParentContentBlockId($this->objContentBlock->Id,
  106. QQ::Clause (QQ::OrderBy(QQN::ContentBlock()->SortOrder) )
  107. ) as $childContentBlock )
  108. {
  109. $this->aryChildContentBlockControllers[] = new ContentBlockController( $this, $childContentBlock, null);
  110. }
  111. foreach ( $this->objContentBlock->GetContentItemArray(
  112. QQ::Clause (QQ::OrderBy(QQN::ContentItem()->SortOrder) )
  113. ) as $objContentItem )
  114. {
  115. $objContentItemController = new ContentItemController( $this, $objContentItem );
  116. $objContentItemController->CssClass = $objContentItem->Type;
  117. $this->aryContentItemControllers[] = $objContentItemController;
  118. }
  119. foreach ( $this->objContentBlock->GetMenuArray(
  120. QQ::Clause (QQ::OrderBy(QQN::Menu()->SortOrder) )
  121. ) as $objMenu )
  122. {
  123. $objMenuController = new MenuController( $this, $objMenu );
  124. $objMenuController->CssClass = $objMenu->Type;
  125. $this->aryMenuControllers[] = $objMenuController;
  126. }
  127. return true;
  128. }
  129. protected function initModuleViews(){
  130. $this->aryModules = $this->objContentBlock->GetModuleArray();
  131. if(!$this->aryModules)
  132. return false;
  133. foreach($this->aryModules as $objModule){
  134. $strModuleClassName = $objModule->ClassName;
  135. try{
  136. $objModuleView = new $strModuleClassName($this, $objModule);
  137. } catch (QCallerException $objExc) {
  138. $objExc->IncrementOffset();
  139. throw $objExc;
  140. }
  141. $this->aryModuleViews[] = $objModuleView;
  142. ///@todo - add module to the global list?
  143. /* if(!IndexPage::$MainWindow->GetActiveModule($strModuleClassName) )
  144. IndexPage::$MainWindow->AddActiveModule ( $objModuleView );*/
  145. }
  146. }
  147. public function __get($strName){
  148. switch ($strName){
  149. case 'HasModules':
  150. return ! empty($this->aryModuleViews);
  151. case 'HasMenus':
  152. return ! empty($this->aryMenuControllers);
  153. case 'HasContentItems':
  154. return ! empty($this->aryContentItemControllers);
  155. case 'HasContentBlocks':
  156. return ! empty($this->aryChildContentBlockControllers);
  157. case 'Title':
  158. return $this->objContentBlock->Title ;
  159. case 'Description':
  160. return $this->objContentBlock->Description ;
  161. case 'ShowTitle':
  162. return $this->objContentBlock->ShowTitle ;
  163. case 'ShowDescription':
  164. return $this->objContentBlock->ShowDescription ;
  165. case 'CssId':
  166. return $this->strCssId ;
  167. case 'TitlePanel':
  168. return $this->pnlTitle ;
  169. case 'DescriptionPanel':
  170. return $this->pnlDescription ;
  171. default:
  172. try {
  173. return parent::__get($strName);
  174. } catch (QCallerException $objExc) {
  175. $objExc->IncrementOffset();
  176. throw $objExc;
  177. }
  178. }
  179. }
  180. public function __set($strName, $mixValue){
  181. switch ($strName){
  182. case 'Title':
  183. try {
  184. return ($this->objContentBlock->Title = QType::Cast($mixValue, QType::String));
  185. } catch (QInvalidCastException $objExc) {
  186. $objExc->IncrementOffset();
  187. throw $objExc;
  188. }
  189. case 'Description':
  190. try {
  191. return ($this->objContentBlock->Description = QType::Cast($mixValue, QType::String));
  192. } catch (QInvalidCastException $objExc) {
  193. $objExc->IncrementOffset();
  194. throw $objExc;
  195. }
  196. default:
  197. try {
  198. return (parent::__set($strName, $mixValue));
  199. } catch (QCallerException $objExc) {
  200. $objExc->IncrementOffset();
  201. throw $objExc;
  202. }
  203. }
  204. }
  205. }
  206. ?>