public function save($data, $overwrite = false)
 {
     if (isset($data['vo_id']) && isset($data['idp_id']) && $data['idp_id'] == $data['org_idp_id'] && !$overwrite) {
         $vo_id = htmlentities($data['vo_id']);
         $idp_id = htmlentities($data['idp_id']);
         $idpService = new EngineBlock_Service_VirtualOrganisationIdp();
         $idp = $idpService->fetchById($vo_id, $idp_id);
     } else {
         $idp = new EngineBlock_Model_VirtualOrganisationIdp();
     }
     $idp->populate($data);
     $form = new EngineBlock_Form_VirtualOrganisationIdp();
     if (!$form->isValid($idp->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;
             }
         }
         $idp->errors = $modelErrors;
         return $idp;
     }
     $mapper = new EngineBlock_Model_Mapper_VirtualOrganisationIdp(new EngineBlock_Model_DbTable_VirtualOrganisationIdp());
     $isNewRecord = isset($data['org_idp_id']) && $idp->idp_id != $data['org_idp_id'];
     $mapper->save($idp, $isNewRecord);
     // if the PK changes, it is saved as a new record, so the original record should be deleted
     if ($isNewRecord) {
         $this->delete($data['vo_id'], $data['org_idp_id']);
     }
     return $idp;
 }
 public function idpaddAction()
 {
     $this->view->vo_id = htmlentities($this->_getParam('vo_id'));
     if (strlen($this->view->vo_id) > 0) {
         $virtualOrganisationIdp = new EngineBlock_Model_VirtualOrganisationIdp();
         $virtualOrganisationIdp->populate(array('vo_id' => $this->view->vo_id));
         $this->view->virtualOrganisationIdp = $virtualOrganisationIdp;
         $this->view->saveUrl = $this->view->url(array('action' => 'idpsave'));
         $this->view->listUrl = $this->view->url(array('action' => 'edit', 'vo_id' => $this->view->vo_id));
         $this->render('idpedit');
     } else {
         $this->_forward('edit');
     }
 }