public function updateBannersManual($campaignId, $bannerId = null) { $res = array('added' => 0, 'updated' => 0, 'error' => 0); if (!is_array($bannerId) && $bannerId > 0) { $bannerId = array($bannerId); } $bannerList = array(); if (is_array($bannerId) && count($bannerId) > 0) { $dbRes = YandexBannerTable::getList(array('filter' => array('=ID' => $bannerId, '=ENGINE_ID' => $this->getId()), 'select' => array('XML_ID'))); while ($banner = $dbRes->fetch()) { $keys[] = $banner['XML_ID']; } $bannerList = $this->getBanners($keys); } else { $dbCampaigns = YandexCampaignTable::getList(array('filter' => array('=ID' => $campaignId, '=ENGINE_ID' => $this->getId()), 'select' => array('ID', 'XML_ID'))); while ($campaign = $dbCampaigns->fetch()) { $campaignIndex[$campaign['XML_ID']] = $campaign['ID']; } if (count($campaignIndex) > 0) { $bannerList = $this->getCampaignBanners(array_keys($campaignIndex)); } } if (count($bannerList) > 0) { $bannerListSorted = array(); foreach ($bannerList as $bannerInfo) { $bannerListSorted[$bannerInfo['BannerID']] = $bannerInfo; } $dbBanners = YandexBannerTable::getList(array('filter' => array('=XML_ID' => array_keys($bannerListSorted), '=ENGINE_ID' => $this->getId()))); YandexBannerTable::setSkipRemoteUpdate(true); while ($banner = $dbBanners->fetch()) { if (isset($bannerListSorted[$banner['XML_ID']])) { $result = YandexBannerTable::update($banner['ID'], array("SETTINGS" => $bannerListSorted[$banner['XML_ID']])); unset($bannerListSorted[$banner['XML_ID']]); if ($result->isSuccess()) { $res['updated']++; } else { $res['error']++; } } } foreach ($bannerListSorted as $bannerId => $bannerInfo) { $result = YandexBannerTable::add(array("CAMPAIGN_ID" => $campaignIndex[$bannerInfo['CampaignID']], "SETTINGS" => $bannerInfo)); if ($result->isSuccess()) { $res['added']++; } else { $res['error']++; } } YandexBannerTable::setSkipRemoteUpdate(false); } return $res; }
} } else { $adminList->AddGroupError( Loc::getMessage( 'SEO_ERROR_BANNER_UPDATE', array( '#ID#' => $bannerId, '#XML_ID#' => $bannerXmlId, ) ) ); } } Adv\YandexBannerTable::setSkipRemoteUpdate(false); } catch(Engine\YandexDirectException $e) { $adminList->AddGroupError($e->getCode().': '.$e->getMessage()); } } } } $map = Adv\YandexBannerTable::getMap(); unset($map['GROUP']); unset($map['CAMPAIGN']);
/** * Deletes all campaign banners. * * @param Entity\Event $event Event data. * * @return void * * @throws Main\ArgumentException */ public static function onAfterDelete(Entity\Event $event) { $primary = $event->getParameter("primary"); $engine = self::getEngine(); $dbRes = YandexBannerTable::getList(array('filter' => array('=CAMPAIGN_ID' => $primary, '=ENGINE_ID' => $engine->getId()), 'select' => array('ID'))); YandexBannerTable::setSkipRemoteUpdate(true); while ($banner = $dbRes->fetch()) { YandexBannerTable::delete($banner['ID']); } YandexBannerTable::setSkipRemoteUpdate(false); }