Ejemplo n.º 1
0
 public function edit($params)
 {
     $language = OW::getLanguage();
     $this->menu->getElement('index')->setActive(true);
     if (empty($params['bannerId'])) {
         $this->redirectToAction('index');
     }
     $bannerId = (int) $params['bannerId'];
     $banner = $this->adsService->findBannerById($bannerId);
     if ($banner === null) {
         $this->redirectToAction('index');
     }
     $form = $this->getAdsForm('banner_edit_form');
     $form->getSubmitElement('submit')->setValue($language->text('ads', 'ads_edit_banner_submit_label'));
     $form->getElement('title')->setValue($banner->getLabel());
     $form->getElement('code')->setValue($banner->getCode());
     if ($this->adsService->getLocationEnabled()) {
         $bannerLocations = $this->adsService->findBannerLocations($banner->getId());
         $locationCodes = array();
         if (!empty($bannerLocations)) {
             /* @var $bannerLocation ADS_BOL_BannerLocation */
             foreach ($bannerLocations as $bannerLocation) {
                 $locationCodes[] = $bannerLocation->getLocation();
             }
         }
         $form->getElement('select_country')->setValue($locationCodes);
     }
     $this->addForm($form);
     if (OW::getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $data = $form->getValues();
             $banner->setLabel($data['title']);
             $banner->setCode($data['code']);
             $this->adsService->saveBanner($banner);
             $this->adsService->resetBannerLocations($banner->getId());
             if ($data['select_country'] !== null && sizeof($data['select_country']) > 0) {
                 foreach ($data['select_country'] as $loc) {
                     $bannerLocation = new ADS_BOL_BannerLocation();
                     $bannerLocation->setBannerId($banner->getId());
                     $bannerLocation->setLocation($loc);
                     $this->adsService->saveBannerLocation($bannerLocation);
                 }
             }
             OW::getFeedback()->info($language->text('ads', 'ads_banner_edit_success_message'));
             $this->redirectToAction('index');
         }
     }
 }