コード例 #1
0
 public function addCampaignAction()
 {
     $disticts = array();
     $form = new Form_Campaigns_AddCampaign();
     $campaigns = new Model_Campaigns();
     $all_districts = $campaigns->allDistricts();
     $action = 'add-campaign';
     $btn_txt = 'Add New Campaign';
     $page_heading = 'Add New Campaign';
     if ($this->_request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $district_ids = $this->_request->getParam('district_id', '');
             $campaigns->form_values = $this->_request->getPost();
             //$form->getValues();
             $campaigns->form_values['district_ids'] = $district_ids;
             $last_id = $campaigns->addCampaign();
             $doEdit = App_Controller_Functions::encrypt('edit|' . $last_id);
             $this->redirect("/campaign/manage-campaigns/add-campaign?id={$doEdit}");
         }
     }
     $id = $this->_request->getParam('id', '');
     if (!empty($id)) {
         $arr = explode('|', App_Controller_Functions::decrypt($id));
         $action = $arr[0];
         $id = $arr[1];
         // $campaigns->form_values['campaign_id'] = $id;
         $campaign = $this->_em->getRepository("Campaigns")->find($id);
         $form->campaign_type_id->setValue($campaign->getCampaignType()->getPkId());
         $form->campaign_name->setValue($campaign->getCampaignName());
         $form->date_from->setValue($campaign->getDateFrom()->format('d/m/Y'));
         $form->date_to->setValue($campaign->getDateTo()->format('d/m/Y'));
         $form->catch_up_days->setValue($campaign->getCatchUpDays());
         $form->campaign_id->setValue($campaign->getPkId());
         $campaign_ips = $this->_em->getRepository("CampaignItemPackSizes")->findBy(array('campaign' => $id));
         foreach ($campaign_ips as $cam_ips) {
             $arr_ips[] = $cam_ips->getItemPackSize()->getPkId();
             //$cam_ips->getItemPackSize()->getPkId()
         }
         //App_Controller_Functions::pr($arr_ips,'flase');
         $form->item_id->setValue($arr_ips);
         $campaign_districts = $this->_em->getRepository("CampaignDistricts")->findBy(array('campaign' => $id));
         foreach ($campaign_districts as $cam_dis) {
             $disticts[] = $cam_dis->getDistrict()->getPkId();
             //$cam_ips->getItemPackSize()->getPkId()
         }
         $this->view->disticts = count($disticts) > 0 ? implode(',', $disticts) : "";
         $form->campaign_update_id->setValue($id);
         $action = 'update-campaign';
         $btn_txt = 'Update Campaign';
         $page_heading = 'Update Campaign';
         $campaigns = new Model_Campaigns();
         $campaigns->form_values['campaign_id'] = $id;
         $district_data = $campaigns->allDistrictsData();
         $this->view->district_data = $district_data;
     }
     $base_url = Zend_Registry::get('baseurl');
     $this->view->inlineScript()->appendFile($base_url . '/js/iadmin/manage-stakeholders/ajax-get-items.js');
     $this->view->inlineScript()->appendFile($base_url . '/js/jquery.multi-select.min.js');
     $this->view->headLink()->appendStylesheet($base_url . '/common/theme/css/select.css');
     $this->view->headLink()->appendStylesheet($base_url . '/common/theme/css/multiselect.css');
     $this->view->form = $form;
     $this->view->action = $action;
     $this->view->btn_txt = $btn_txt;
     $this->view->page_heading = $page_heading;
     $this->view->all_districts = $all_districts;
 }