public function updateCampaignAction()
 {
     if ($this->_request->getPost()) {
         $form_values = $this->_request->getPost();
         $id = $form_values['campaign_update_id'];
         $campaign = $this->_em->getRepository("Campaigns")->find($id);
         $campaign->setCampaignName($form_values['campaign_name']);
         $campaign->setDateFrom(new \DateTime(App_Controller_Functions::dateToDbFormat($form_values['date_from'])));
         $campaign->setDateTo(new \DateTime(App_Controller_Functions::dateToDbFormat($form_values['date_to'])));
         $campaign->setCatchUpDays($form_values['catch_up_days']);
         $campaign_type_id = $this->_em->find('CampaignTypes', $form_values['campaign_type_id']);
         $campaign->setCampaignType($campaign_type_id);
         $created_by = $this->_em->find('Users', $this->_userid);
         $campaign->setCreatedBy($created_by);
         $campaign->setCreatedDate(App_Tools_Time::now());
         $campaign->setModifiedBy($created_by);
         $campaign->setModifiedDate(App_Tools_Time::now());
         $this->_em->persist($campaign);
         $this->_em->flush();
         $last_id = $campaign->getPkId();
         $campaign_id = $this->_em->find('Campaigns', $last_id);
         $campaign_ip = $this->_em->getRepository("CampaignItemPackSizes")->findBy(array('campaign' => $id));
         foreach ($form_values['item_id'] as $item_id) {
             $campaign_ips = $this->_em->getRepository("CampaignItemPackSizes")->find($campaign_ip['0']->getPkId());
             // $campaign_ips = new CampaignItemPackSizes();
             $campaign_ips->setCampaign($campaign_id);
             $item_id_ips = $this->_em->find('ItemPackSizes', $item_id);
             $campaign_ips->setItemPackSize($item_id_ips);
             $campaign_ips->setModifiedBy($created_by);
             $campaign_ips->setModifiedDate(App_Tools_Time::now());
             $this->_em->persist($campaign_ips);
             $this->_em->flush();
         }
         $campaign_di = $this->_em->getRepository("CampaignDistricts")->findBy(array('campaign' => $id));
         foreach ($campaign_di as $cam_dis) {
             $campaign_dis = $this->_em->getRepository("CampaignDistricts")->find($cam_dis->getPkId());
             $this->_em->remove($campaign_dis);
             $this->_em->flush();
         }
         foreach ($form_values['districts'] as $district_id) {
             $campaign_d = new CampaignDistricts();
             $campaign_d->setCampaign($campaign_id);
             $district_location_id = $this->_em->find('Locations', $district_id);
             $campaign_d->setDistrict($district_location_id);
             $campaign_d->setCreatedBy($created_by);
             $campaign_d->setCreatedDate(App_Tools_Time::now());
             $campaign_d->setModifiedBy($created_by);
             $campaign_d->setModifiedDate(App_Tools_Time::now());
             $this->_em->persist($campaign_d);
             $this->_em->flush();
         }
         $this->redirect("/campaign/manage-campaigns/index?success=1");
     }
 }
示例#2
0
 public function addCampaign()
 {
     $campaign = new Campaigns();
     $campaign->setCampaignName($this->form_values['campaign_name']);
     $campaign->setDateFrom(App_Tools_Time::now());
     $campaign->setDateTo(App_Tools_Time::now());
     $campaign->setCatchUpDays($this->form_values['catch_up_days']);
     $campaign_type_id = $this->_em->find('CampaignTypes', $this->form_values['campaign_type_id']);
     $campaign->setCampaignType($campaign_type_id);
     $campaign->setIsClosed('0');
     $created_by = $this->_em->find('Users', $this->_user_id);
     $campaign->setCreatedBy($created_by);
     $campaign->setCreatedDate(App_Tools_Time::now());
     $campaign->setModifiedBy($created_by);
     $campaign->setModifiedDate(App_Tools_Time::now());
     $this->_em->persist($campaign);
     $this->_em->flush();
     $last_id = $campaign->getPkId();
     $campaign_id = $this->_em->find('Campaigns', $last_id);
     foreach ($this->form_values['item_id'] as $item_id) {
         $campaign_ips = new CampaignItemPackSizes();
         $campaign_ips->setCampaign($campaign_id);
         $item_id_ips = $this->_em->find('ItemPackSizes', $item_id);
         $campaign_ips->setItemPackSize($item_id_ips);
         $campaign_ips->setCreatedBy($created_by);
         $campaign_ips->setCreatedDate(App_Tools_Time::now());
         $campaign_ips->setModifiedBy($created_by);
         $campaign_ips->setModifiedDate(App_Tools_Time::now());
         $this->_em->persist($campaign_ips);
     }
     $this->_em->flush();
     //$district_ids = explode(',', $this->form_values['district_ids']);
     //App_Controller_Functions::pr($this->form_values['districts']);
     $created_by = $this->_em->find('Users', $this->_user_id);
     foreach ($this->form_values['districts'] as $district_id) {
         $campaign_d = new CampaignDistricts();
         $campaign_d->setCampaign($campaign_id);
         $district_location_id = $this->_em->find('Locations', $district_id);
         $campaign_d->setDistrict($district_location_id);
         $campaign_d->setCreatedBy($created_by);
         $campaign_d->setCreatedDate(App_Tools_Time::now());
         $campaign_d->setModifiedBy($created_by);
         $campaign_d->setModifiedDate(App_Tools_Time::now());
         $this->_em->persist($campaign_d);
     }
     $this->_em->flush();
     return $last_id;
 }