public function save($data, $overwrite = false) { if (isset($data['vo_id']) && !$overwrite) { $id = $data['vo_id']; $voService = new EngineBlock_Service_VirtualOrganisation(); $vo = $voService->fetchById($id); } else { $vo = new EngineBlock_Model_VirtualOrganisation(); } $vo->populate($data); $form = new EngineBlock_Form_VirtualOrganisation(); if (!$form->isValid($vo->toArray())) { $formErrors = $form->getErrors(); $modelErrors = array(); foreach ($formErrors as $fieldName => $fieldErrors) { foreach ($fieldErrors as $fieldError) { switch ($fieldError) { case 'isEmpty': $error = 'Field is obligatory, but no input given'; break; default: $error = $fieldError; } if (!isset($modelErrors[$fieldName])) { $modelErrors[$fieldName] = array(); } $modelErrors[$fieldName][] = $error; } } $vo->errors = $modelErrors; return $vo; } $mapper = new EngineBlock_Model_Mapper_VirtualOrganisation(new EngineBlock_Model_DbTable_VirtualOrganisation()); $vo = $mapper->save($vo, $data['vo_id'] != $data['org_vo_id']); // if the PK changes (vo_id), it is saved as a new record, so the groups and idps must be updated and the original record should be deleted if (empty($vo->errors) && isset($data['org_vo_id']) && $vo->vo_id != $data['org_vo_id']) { // update group records $groupService = new EngineBlock_Service_VirtualOrganisationGroup(); $groupService->updateVOId($data['org_vo_id'], $data['vo_id']); // update idp records $idpService = new EngineBlock_Service_VirtualOrganisationIdp(); $idpService->updateVOId($data['org_vo_id'], $data['vo_id']); // delete old vo $this->delete($data['org_vo_id']); } return $vo; }
public function saveAction() { $this->view->listUrl = $this->view->url(array('action' => 'list')); $service = new EngineBlock_Service_VirtualOrganisation(); $virtualOrganisation = $service->save($this->_getAllParams(), true); if (empty($virtualOrganisation->errors)) { $listAllVosUrl = $this->view->url(array('module' => 'engineblock', 'controller' => 'virtual-organisation', 'action' => 'list'), null, true); $this->_redirect($listAllVosUrl); } else { $virtualOrganisation->vo_id = $this->_getParam('org_vo_id'); $this->view->virtualOrganisation = $virtualOrganisation; $this->render('edit'); } }