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 indexAction() { $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); $form = new CompanyForm($dbAdapter); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $company = new Company(); $form->setInputFilter($company->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $company->exchangeArray($form->getData()); $this->getCompanyList()->saveCompany($company); // Redirect to list of companys return $this->redirect()->toRoute('company'); } } return array('form' => $form); }
function addAction() { $errors = array(); $countryArr = array(); $stateid = ''; $logo = ''; $companyid = $this->params()->fromRoute('companyid', null); $companyForm = new CompanyForm(); $countries = $this->getTable($this->countryTable, 'Application\\Model\\CountryTable')->fetchAll(); foreach ($countries as $country) { $countryArr[$country->id] = $country->name; } $companyForm->get('country_id')->setValueOptions($countryArr); if ($companyid) { $company = $this->getTable($this->companyTable, 'Company\\Model\\CompanyTable')->find($companyid); $companyForm->get('country_id')->setValue($company->country_id); $companyForm->get('name')->setValue($company->name); $companyForm->get('phone_no')->setValue($company->phone_no); $companyForm->get('mobile_no')->setValue($company->mobile_no); $companyForm->get('address')->setValue($company->address); $companyForm->get('city')->setValue($company->city); $companyForm->get('pincode')->setValue($company->pincode); $companyForm->get('status')->setValue($company->status); $stateid = $company->state_id; $logo = $company->logo; } $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); $companyForm->setInputFilter(new CompanyFilter()); $companyForm->setData($data); if ($companyForm->isValid()) { $files = $request->getFiles()->toArray(); if (!empty($files['logo']['name'])) { $upload = new Upload(); $destination = "C:/xampp/htdocs/lokhit/public/uploads/company"; $fileinfo = $upload->uploadFile('logo', $destination); $uniqueName = $fileinfo['uniqueName']; $data['logo'] = $uniqueName; } $companyId = $this->getTable($this->companyTable, 'Company\\Model\\CompanyTable')->save($data, $companyid); if ($companyId) { $this->flashMessenger()->addMessage('Company Created successfully!', 'success'); $this->redirect()->toRoute('company-list'); } else { $this->flashMessenger()->addMessage(array('error' => 'Company Not Created!')); } } else { $errors = $companyForm->getMessages(); } } return new ViewModel(array('companyForm' => $companyForm, 'stateid' => $stateid, 'logo' => $logo, 'errors' => $errors)); }
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'); }