Пример #1
0
 public function editAction()
 {
     $request = $this->getRequest();
     $bannerId = $request->getParam('banner_id');
     $banner = Modules_Ad_Services_Banner::getById($bannerId);
     if (null == $banner) {
         throw new Exception('Banner with id : ' . $bannerId . ' was not found');
     }
     $zones = Modules_Ad_Services_Zone::getAllZones(true);
     $this->view->zones = $zones;
     $pages = Modules_Core_Services_Page::dbPages();
     $this->view->pages = $pages;
     $bannerPagesAssoc = Modules_Ad_Services_BannerPageAssoc::getBannerPageAssoc($bannerId);
     $items = array('title' => array(), 'route' => array(), 'zone_id' => array(), 'zone_code' => array(), 'url' => array());
     if ($bannerPagesAssoc) {
         foreach ($bannerPagesAssoc as $index => $page) {
             $items['title'][] = $page['page_title'];
             $items['route'][] = $page['route'];
             $items['zone_id'][] = $page['zone_id'];
             $items['zone_code'][] = $page['code'];
             $items['url'][] = $page['page_url'];
         }
     }
     $bannerData = $banner;
     $bannerData['items'] = $items;
     $this->view->bannerData = $bannerData;
     if ($request->isPost()) {
         $bannerData = $request->getPost('banner');
         $bannerData = Modules_Ad_Services_Banner::validate($bannerData);
         $items = $request->getPost('items');
         $bannerData['items'] = $items;
         $bannerData['banner_id'] = $bannerId;
         if (isset($bannerData['messages_error']) && $bannerData['messages_error']) {
             $this->view->errorMessages = $bannerData['messages'];
             $this->view->bannerData = $bannerData;
             return;
         }
         $banner = array('banner_id' => $bannerData['banner_id'], 'name' => $this->view->STRING->escape($bannerData['name']), 'description' => null, 'mode' => $this->view->STRING->escape($bannerData['mode']), 'format' => $this->view->STRING->escape($bannerData['format']), 'width' => (int) $bannerData['width'], 'height' => (int) $bannerData['height'], 'html_code' => $this->view->STRING->escape($bannerData['html_code']), 'url' => $this->view->STRING->escape($bannerData['url']), 'file_url' => $this->view->STRING->escape($bannerData['file_url']), 'status' => $this->view->STRING->escape($bannerData['status']));
         $bannerId = Modules_Ad_Services_Banner::update($banner, $items);
         Gio_Core_Messenger::getInstance()->addMessage($this->view->TRANSLATOR->translator('banner_edit_action_success'));
         $this->redirect($this->view->url('ad_banner_edit', $banner));
     }
 }
Пример #2
0
 public static function update($banner, $items = array())
 {
     $conn = Gio_Db_Connection::getConnection();
     $bannerDao = new Modules_Ad_Models_Mysql_Banner();
     $bannerDao->setConnection($conn);
     $bannerDao->update($banner);
     /**
      * Delete banner page assoc by banner id
      */
     Modules_Ad_Services_BannerPageAssoc::deleteByBannerId($banner['banner_id']);
     if (isset($items['route']) && $items['route']) {
         foreach ($items['route'] as $index => $route) {
             $bannerPageAssoc = array('banner_id' => $banner['banner_id'], 'zone_id' => $items['zone_id'][$index], 'route' => $route, 'page_url' => $items['url'][$index], 'page_title' => $items['title'][$index]);
             Modules_Ad_Services_BannerPageAssoc::add($bannerPageAssoc);
         }
     }
 }