/** * Form initialization * * @return void */ public function init() { $url = Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => "flex", 'controller' => 'panel', 'action' => 'layout'), 'default'); $this->setAction($url)->setMethod('post'); $this->setLegend(sprintf(Zoo::_('Edit %s'), $this->target->name)); $settings_elements = $this->target->getLayout()->getSettingsFormElements(); $this->addElements($settings_elements); $settings = $this->target->getLayout()->settings; $settings['structure'] = json_encode($settings['structure']); $legend = Zoo::_('Layout options'); $this->addDisplayGroup($settings_elements, 'layout_settings', array('legend' => $legend)); $regions = $this->target->getLayout()->getAllRegions(); $allregions = array(); foreach (array_keys($regions) as $name) { $region = new Zend_Form_Element_Select('region_' . $name); $region->setLabel($name)->setMultiOptions($this->getRegionStyles()); $this->addElement($region); $allregions[] = 'region_' . $name; } $legend = Zoo::_('Region styles'); $this->addDisplayGroup($allregions, 'region_form', array('legend' => $legend)); $submit = new Zend_Form_Element_Submit('save'); $submit->setLabel('save')->setOrder(100); $this->addElement($submit); if ($this->target->id > 0) { $id_ele = new Zend_Form_Element_Hidden('id'); $id_ele->setValue(intval($this->target->id)); $this->addElement($id_ele); } $this->populate($settings); $this->populate($this->target->toArray()); }
/** * Render panel blocks * @return void */ public function dispatchLoopShutdown() { if (!Zend_Layout::getMvcInstance()->isEnabled()) { // No layout, no panel content return; } if (!$this->panel) { // No panel to display return; } $this->panel->loadBlocks()->render(); }
/** * 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; }
/** * 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); }
/** * Get block-specific options * @return Zend_Form_Subform */ function getOptionsForm() { $class = $this->target->type; $object = new $class($this->target->toArray()); return $object->getOptions(); }