/** * @return void */ public function editExtendAction() { $form = $this->getLocator()->get('ZlySysmap\\Form\\Extend'); $params = $this->getRequest()->getMetadata(); $form->populate($params); if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->post()->toArray())) { try { $this->model->saveExtension($form->getValues()); return $this->redirect(array())->toRoute('default', array('controller' => 'sysmap-admin', 'action' => 'list')); } catch (\Exception $e) { $form->setErrors(array($e->getMessage())); } } } else { $hash = $this->getRequest()->getMetadata('hash'); if (!empty($hash)) { $values = $this->model->getNodeByHash($hash); if ($values instanceof Model\Mapper\Extend) { $values = $values->toArray(); } if ($values->params instanceof \Zend\Config\Config) { $values->params = $values->params->toArray(); } if (!empty($values)) { $values->sysmap_id = $this->model->getParentByHash($hash)->hash; $form->populate((array) $values); } } } return array('editExtensionForm' => $form); }
/** * Set up values from array * @param array $values * @return Zend_Form */ public function populate(array $values) { if (!empty($values['sysmap_id'])) { $this->_appendParamsSubform($values['sysmap_id']); } elseif (!empty($values['hash'])) { $mapitem = $this->model->getParentByHash($values['hash']); $this->_appendParamsSubform($mapitem->hash); } return parent::populate($values); }
/** * Return sysmap tree parents by child identifier * @param string $id * @return array() */ public function getItemParentsByIdentifier($id) { $parentsHashes = array(); if (!empty($id)) { $parentsNodes = $this->model->getParentByHash($id, true); if (!empty($parentsNodes)) { foreach ($parentsNodes as $node) { if (!empty($node)) { $parentsHashes[] = new \Zend\Acl\Resource\GenericResource($node->hash); } } } } return $parentsHashes; }