/** * 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); }
/** * Load blocks for this panel * * @return Flex_Panel */ function loadBlocks() { $ret = array(); $groups = array(0); try { $groups = array_keys(Zoo::getService('user')->getCurrentUser()->getGroups()); } catch (Zoo_Exception_Service $e) { // Do nothing } $cacheid = "Flex_panel_" . $this->id . "_" . implode("_", $groups); try { $ret = Zoo::getService("cache")->load($cacheid); } catch (Zoo_Exception_Service $e) { // @todo: Remove this comment: I'm beginning to tire of writing try-catch for services } if (!$ret) { $factory = new Flex_Panel_Block_Factory(); $ret = $factory->getPanelBlocks($this); try { // If no cache service available, no need to do cache tag processing $cache = Zoo::getService('cache'); $tags = array('panel', 'panel_' . $this->id); foreach ($ret as $region => $blocks) { foreach ($blocks as $block) { $tags[] = "block_" . $block->id; } } $cache->save($ret, $cacheid, $tags, null); } catch (Zoo_Exception_Service $e) { // No caching available } } $this->blocks = $ret; // Allow for method chaining return $this; }