Пример #1
0
 /**
  * Delete a block
  * @return void
  */
 public function deleteAction()
 {
     $factory = new Flex_Block_Factory();
     $id = $this->getRequest()->getParam('id');
     $item = $factory->find($id)->current();
     if ($item) {
         $item->delete();
         try {
             Zoo::getService('cache')->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('node_' . $item->id, 'nodelist'));
         } catch (Zoo_Exception_Service $e) {
             // Cache service
         }
     }
 }
Пример #2
0
 /**
  * Get all blocks for a given panel, including blocks that fall down from parent panels
  * ordered by region
  *
  * @param Flex_Panel $panel
  * @return array
  */
 function getPanelBlocks($panel)
 {
     $ret = array();
     $panel_blocks = $this->fetchAll($this->select()->where("panel_id = ?", $panel->id)->order('weight'));
     $blockids = array();
     foreach ($panel_blocks as $block) {
         $blockids[] = $block->block_id;
     }
     $parents = $panel->getAllParents();
     $parent_blocks = array();
     if ($parents) {
         $parentids = array();
         foreach ($parents as $parent) {
             $parentids[] = $parent->id;
         }
         // Fetch from parent panel where falldown is true
         $parent_blocks = $this->fetchAll($this->select()->where("panel_id IN (?)", $parentids)->where('falldown = ?', 1)->order('weight'));
         foreach ($parent_blocks as $block) {
             $blockids[] = $block->block_id;
         }
     }
     $block_factory = new Flex_Block_Factory();
     $block_instances = $block_factory->getBlocks($blockids);
     // Parent blocks go first
     foreach ($parent_blocks as $block) {
         if (isset($block_instances[$block->block_id])) {
             $block_instances[$block->block_id]->panel = $panel;
             $block_instances[$block->block_id]->panel_block = $block;
             $ret[$block->region][] = $block_instances[$block->block_id];
         }
     }
     foreach ($panel_blocks as $block) {
         if (isset($block_instances[$block->block_id])) {
             $block_instances[$block->block_id]->panel = $panel;
             $block_instances[$block->block_id]->panel_block = $block;
             $ret[$block->region][] = $block_instances[$block->block_id];
         }
     }
     // Post-fetch hook
     Zoo::getService('hook')->trigger('panel', 'blocks', $panel, $ret);
     return $ret;
 }
Пример #3
0
 /**
  * Configure content for a panel
  */
 public function contentAction()
 {
     $this->view->jQuery()->enable()->uiEnable();
     if ($this->getRequest()->isPost()) {
         $blocks = $this->getRequest()->getParam('block', array());
         $panel_block_factory = new Flex_Panel_Block_Factory();
         if ($blocks) {
             $regions = array();
             $block_factory = new Flex_Block_Factory();
             $block_options = $this->getRequest()->getParam('options', array());
             foreach ($blocks as $block) {
                 if (!is_numeric($block) && substr($block, 0, 4) != "new-") {
                     // region
                     $current_region = $block;
                     $regions[$current_region] = array();
                 } else {
                     if (is_numeric($block)) {
                         $block_obj = $block_factory->find($block)->current();
                         $panel_block = $panel_block_factory->fetchRow($panel_block_factory->select()->where('panel_id = ?', $this->panel->id)->where('block_id = ?', $block_obj->id));
                     } else {
                         $block_obj = $block_factory->createRow();
                         $block_obj->save();
                         $panel_block = $panel_block_factory->createRow(array('panel_id' => $this->panel->id, 'block_id' => $block_obj->id));
                     }
                     $regions[$current_region][] = $panel_block;
                 }
             }
             foreach ($regions as $region => $blocks) {
                 foreach ($blocks as $key => $block) {
                     $block->region = $region;
                     $block->weight = $key;
                     $block->save();
                 }
             }
         } else {
             // Remove all blocks from panel
             $panel_block_factory->delete("panel_id = " . $this->panel->id);
         }
         // Clear cache for panel
         Zoo::getService('cache')->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('panel_' . $this->panel->id));
     }
     // Render blocks on the panel in admin view
     $layout = $this->panel->loadBlocks()->getLayout();
     $layout->is_admin_page = true;
     $this->view->content = $layout->render($this->panel->blocks);
 }
Пример #4
0
 /**
  * Fetch and assign block content to view
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!Zend_Layout::getMvcInstance()->isEnabled()) {
         // No layout, no blocks
         return;
     }
     if (Zend_Layout::getMvcInstance()->getInflectorTarget() == ':script/popup.:suffix') {
         // If using popups, no block
         /**
          * @todo change this to be more generic - something like ZfApplication::hasBlocks()... but where should this method be?
          */
         return;
     }
     // Retrieve blocks to be shown on this page
     $factory = new Flex_Block_Factory();
     $blocks = $factory->getBlocks();
     if (!$blocks) {
         // No blocks to show
         return;
     }
     $rendered_blocks = array();
     $view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
     /* @var $view Zend_View_Abstract */
     foreach (array_keys($blocks) as $position) {
         foreach ($blocks[$position] as $block) {
             $cacheid = $block->getCacheId();
             if ($cacheid) {
                 try {
                     $content = Zoo::getService("cache")->load($cacheid);
                 } catch (Zoo_Exception_Service $e) {
                     // Cache unavailable, set content to empty string
                     $content = "";
                 }
                 if (!$content) {
                     if (!isset($blockview)) {
                         // Don't clone the view until it is needed
                         $blockview = clone $view;
                     }
                     $blockview->clearVars();
                     $this->resetViewScripts($blockview, $block);
                     $this->addLanguage($block->module);
                     $vars = $block->getTemplateVars();
                     if ($vars !== false) {
                         $blockview->assign($block->getTemplateVars());
                         $content .= $blockview->render($block->template);
                     }
                     if ($block->cache_time > 0) {
                         try {
                             Zoo::getService('cache')->save($content, $cacheid, array_merge(array('block', 'block_' . $block->id, 'block_' . get_class($block)), $block->getCacheTags()), $block->cache_time);
                         } catch (Zoo_Exception_Service $e) {
                             // Cache service not available, do nothing
                         }
                     }
                 }
                 if (!$content) {
                     // Still no content to show, skip to next block
                     continue;
                 }
                 $block_arr['content'] = $content;
                 $block_arr['title'] = $block->title;
                 $block_arr['block'] = $block;
                 $view->blocks[$position][] = $block_arr;
                 unset($block_arr);
             }
         }
     }
     return;
 }