Пример #1
0
 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));
 }
Пример #2
0
 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);
 }
Пример #3
0
 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);
 }