public function saveCampaign(Campaign $campaign) { $data = $campaign->getFullData(); $id_campana = (int) $campaign->id_campana; if ($id_campana == 0) { $this->tableGateway->insert($data); } else { if ($this->getCampaign($id_campana)) { $this->tableGateway->update($data, array('ID_CAMPANA' => $id_campana)); } else { throw new \Exception('Form id does not exist'); } } }
public function addAction() { $form = new CampaignForm(); $user = $this->getUserTable()->getUserFromUserName($this->getUserLogued()); $form->get('ID_SPONSOR')->setValue($user->uid); $request = $this->getRequest(); if ($request->isPost()) { $campaign = new Campaign(); $form->setInputFilter($campaign->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $campaign->exchangeArray($form->getData()); $this->getCampaignTable()->saveCampaign($campaign); // Redirect to list of albums $this->addInfoMessage(GeneralMessages::CAMPAIGN_ADD_OK); return $this->redirect()->toRoute('myaccount/campaign'); } else { $this->addErrorMessage(GeneralMessages::FORM_ERROR); return $this->redirect()->toRoute('myaccount/campaign', array('action' => 'add')); } } return array('form' => $form); }