'All Pages', App_SideBlock_Obj::PAGE_CUSTOM => 'Custom Pages' ); public static $linkTypeTitles = array( App_SideBlock_Obj::LINK_NONE => 'None', App_SideBlock_Obj::LINK_URL => 'Url', App_SideBlock_Obj::LINK_PAGE => 'Site Page', ); public static $blockTypeTitles = array( App_SideBlock_Obj::TYPE_HTML => 'Html', App_SideBlock_Obj::TYPE_RECENT_NEWS => 'Recent News', // App_SideBlock_Obj::TYPE_NEWSLETTERS => 'Newsletters', App_SideBlock_Obj::TYPE_CONTACT_FORM => 'Contact Form', App_SideBlock_Obj::TYPE_VOLUNTEER_OPPORTUNITIES => 'Volunteer Opportunities', App_SideBlock_Obj::TYPE_UPCOMING_EVENTS => 'Upcoming Events', ); /** * Additional block handlers should implement App_SideBlock_Item_Interface * @var array Type Title => Class Name */ public static $blockTypes = array( App_SideBlock_Obj::TYPE_RECENT_NEWS => 'App_News_View', // App_SideBlock_Obj::TYPE_NEWSLETTERS => 'App_Newsletter_View', App_SideBlock_Obj::TYPE_CONTACT_FORM => 'App_Form_Contact_View', App_SideBlock_Obj::TYPE_VOLUNTEER_OPPORTUNITIES => 'App_Volunteer_View', App_SideBlock_Obj::TYPE_UPCOMING_EVENTS => '\\App\\Event\\Upcoming\\View', ); protected $_actions = array('list'); protected $_listOptions = array('defaultOrderBy' => 'id', 'isDisabledLimit' => true); protected $_externalItems = array(); protected $_itemsGroup = 'RIGHT_ITEMS'; public function exec() { $this->_getDataObj()->setIdPage($this->_doc->getOption('id')); return parent::exec(); } protected function _doList() { $this->_addListItem(); $this->_postList(); return $this; } protected function _getListItem($list = null) { $item = parent::_getListItem($list); $this->_prepareExternalItems($item); if (Qs_Constant::get('DEBUG')) { Zend_Registry::set('_pageSideBlocks', $item['list']); } return ($item['list']) ? $item : null; } protected function _addListItem($list = null) { if (($item = $this->_getListItem($list))) { $this->_doc->addItem($item, $this->_itemsGroup); } return $this; } public function setIdPage($id) { $this->_getDataObj()->setIdPage($id); return $this; } public function getItem() { return $this->_getListItem(); } protected function _prepareExternalItems(&$item) { foreach ($item['list'] as &$block) { $blockType = $block['blockType']; if (App_SideBlock_Obj::TYPE_HTML !== $blockType && array_key_exists($blockType, App_SideBlock_View::$blockTypes) ) { $block['externalItem'] = $this->_getExternalItem($block); } } unset($block); foreach ($item['list'] as $key => $block) { if (array_key_exists('externalItem', $block) && empty($block['externalItem'])) { unset($item['list'][$key]); } } return $this; } protected function _getExternalItem($block) { $blockType = $block['blockType']; if (!isset($this->_externalItems[$blockType])) { $itemClass = App_SideBlock_View::$blockTypes[$blockType]; $options = $this->_getExternalItemOptions($blockType); /** @var $view Qs_ViewController|App_SideBlock_Item_Interface */ $view = new $itemClass($options); if (!method_exists($view, 'getSideBlockItem')) { throw new Qs_Exception('Method ' . $itemClass . '::getSideBlockItem() is undefined'); } $view->setDoc($this->_doc); $item = $view->getSideBlockItem($block); if (!empty($item)) { $this->_externalItems[$blockType] = new Qs_Doc_Item($item); } else { $this->_externalItems[$blockType] = null; } } return $this->_externalItems[$blockType]; } protected function _getExternalItemOptions($blockType) { $options = array(); switch ($blockType) { case App_SideBlock_Obj::TYPE_RECENT_NEWS: $options['config'] = array('type' => 'small'); break; // case App_SideBlock_Obj::TYPE_NEWSLETTERS: // $options['config'] = array('type' => 'small'); // break; case App_SideBlock_Obj::TYPE_VOLUNTEER_OPPORTUNITIES: $options['config'] = array('type' => 'small'); break; } return $options; } }