public function editAction() { $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('company', array('action' => 'add')); } try { $company = $this->getCompanyList()->getCompany($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('company', array('action' => 'index')); } $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); $form = new CompanyForm($dbAdapter); $form->bind($company); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($company->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $this->getCompanyList()->saveCompany($company); // Redirect to list of companys return $this->redirect()->toRoute('company'); } } return array('id' => $id, 'form' => $form); }
public function editAction() { $access_rights = $this->getSubModuleAccessRights(27); extract($access_rights); if (isset($edit_action)) { $id = (int) $this->params()->fromRoute('id'); try { $company = $this->getCompanyTable()->getCompany($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('company_industry', array('action' => 'index')); } $form = new CompanyForm($this->serviceLocator()); $form->bind($company); $request = $this->getRequest(); if ($request->isPost()) { //prepare audit trail parameters $from = (array) $company; $to = $this->getRequest()->getPost()->toArray(); $diff = array_diff_assoc($to, $from); if ($this->noRecordExists('companies', 'company_name') || $from['company_name'] == $to['company_name']) { if (array_key_exists("industry_id", $diff)) { $industry = (array) $this->getIndustryTable()->getIndustry($diff['industry_id']); $diff['industry_name'] = $industry['industry_name']; $industry_pre = (array) $this->getIndustryTable()->getIndustry($to['industry_id']); $to['industry_name'] = $industry_pre['industry_name']; $industry_post = (array) $this->getIndustryTable()->getIndustry($from['industry_id']); $from['industry_name'] = $industry_post['industry_name']; } unset($diff['submit'], $diff['industry_id']); $changes = $this->prepare_modified_data($from, $to, $diff); // end audit trail parameters $form->setInputFilter($company->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $this->getCompanyTable()->saveCompany($company); $this->save_to_audit_trail($to['company_name'], $changes['pre'], $changes['post'], 'edit', 27); $this->flashMessenger()->addMessage(['content' => $request->getPost('company_name') . ' has been successfully modified', 'type' => 'success']); } } else { $this->flashMessenger()->addMessage(['content' => $request->getPost('company_name') . ' already exists!', 'type' => 'danger']); } } } else { $this->flashMessenger()->addMessage(['content' => 'You do not have permission to modify record', 'type' => 'danger']); } $this->redirect()->toRoute('company_industry'); }