public function save($data)
 {
     if (isset($data['id']) && intval($data['id']) > 0) {
         $gpService = new EngineBlock_Service_GroupProvider();
         $gp = $gpService->fetchById(intval($data['id']));
     } else {
         $gp = new EngineBlock_Model_GroupProvider();
     }
     $gp->populate($data);
     $form = new EngineBlock_Form_GroupProvider();
     if (!$form->isValid($gp->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;
             }
         }
         $gp->errors = $modelErrors;
     } else {
         $mapper = new EngineBlock_Model_Mapper_GroupProvider(new EngineBlock_Model_DbTable_GroupProvider());
         $gp = $mapper->save($gp, !(intval($data['id']) > 0));
     }
     return $gp;
 }
 public function editAction()
 {
     $this->view->id = htmlentities($this->_getParam('id'));
     $service = new EngineBlock_Service_GroupProvider();
     $this->view->groupProvider = $service->fetchById($this->view->id);
     // rebuild clean urls to prevent "/group_provider_id/..." in the urls when returning from editing:
     $this->view->saveUrl = $this->view->url(array('module' => 'engineblock', 'controller' => 'group-provider', 'action' => 'save'), null, true);
     $this->view->listUrl = $this->view->url(array('module' => 'engineblock', 'controller' => 'group-provider', 'action' => 'list'), null, true);
     $this->view->gridData = array();
     $this->view->mode = 'edit';
 }