public function addAction()
 {
     $access_rights = $this->getSubModuleAccessRights(27);
     extract($access_rights);
     if (isset($add_action)) {
         $form = new CompanyForm($this->serviceLocator());
         $request = $this->getRequest();
         if ($request->isPost()) {
             $company = new Company();
             $form->setInputFilter($company->getInputFilter());
             $form->setData($request->getPost());
             if ($form->isValid()) {
                 $company->exchangeArray($form->getData());
                 if ($this->noRecordExists('companies', 'company_name')) {
                     $id = $this->getCompanyTable()->saveCompany($company);
                     $from = $this->getRequest()->getPost()->toArray();
                     $industry = (array) $this->getIndustryTable()->getIndustry($from['industry_id']);
                     unset($from['submit'], $from['companies_id'], $from['industry_id']);
                     $added = $this->prepare_added_data($from);
                     $this->save_to_audit_trail($from['company_name'], $added . 'industry=' . $industry['industry_name'], '--', 'add', 27);
                     $this->flashMessenger()->addMessage(['content' => $request->getPost('company_name') . ' has been successfully saved', '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 add', 'type' => 'danger']);
     }
     $this->redirect()->toRoute('company_industry');
 }
Beispiel #2
0
 /**
  * Inserts a company into the datebase, and initializes the given 
  * translations as empty translations for them
  *
  * @param mixed $languages
  */
 public function insert($languages)
 {
     $company = new CompanyModel($this->em);
     $companiesBySameSlugName = $this->findEditableCompaniesBySlugName($company->getSlugName(), false);
     // Only for testing, logo will be implemented in a later issue, and it will be validated before it comes here, so this will never be called in production code. TODO: remove this when implemented logo and logo validation
     foreach ($languages as $language) {
         $translation = new CompanyI18n($language, $company);
         if (is_null($translation->getLogo())) {
             $translation->setLogo('');
         }
         $this->em->persist($translation);
         $company->addTranslation($translation);
     }
     $company->setHidden(false);
     $this->em->persist($company);
     return $company;
 }
 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);
 }