/**
  * @return \Zend\Http\Response|ViewModel
  */
 public function detailAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     $action = $this->params()->fromQuery('action', '');
     $helper = new StaffHelper($this->getDbAdapter());
     $form = $helper->getForm($this->userCombos(), $this->positionCombos(), $this->currencyCombo(), $this->statusCombo());
     $staff = $this->staffTable()->getStaff($id);
     $isEdit = true;
     if (!$staff) {
         $isEdit = false;
         $staff = new Staff();
     }
     if ($action == 'clone') {
         $isEdit = false;
         $id = 0;
         $staff->setStaffId(0);
     }
     $form->bind($staff);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post_data = $request->getPost()->toArray();
         $form->setData($post_data);
         $form->setInputFilter($helper->getInputFilter($id));
         if ($form->isValid()) {
             $this->staffTable()->saveStaff($staff);
             $this->flashMessenger()->addSuccessMessage('Save Successful');
             return $this->redirect()->toRoute('hr_staff');
         } else {
             $this->flashMessenger()->addErrorMessage($form->getMessages());
         }
     }
     return new ViewModel(array('form' => $form, 'id' => $id, 'isEdit' => $isEdit, 'departments' => $this->departments()));
 }
 /**
  * @param Staff $staff
  * @return Staff
  */
 public function saveStaff(Staff $staff)
 {
     $id = $staff->getStaffId();
     $data = $staff->getArrayCopy();
     if ($id > 0) {
         $this->update($data, array('staffId' => $id));
     } else {
         unset($data['staffId']);
         $this->insert($data);
     }
     if (!$staff->getStaffId()) {
         $staff->setStaffId($this->getLastInsertValue());
     }
     return $staff;
 }