}

	$bannerSettings['MinusKeywords'] = preg_split("/[\\n,;]+\\s*/", $bannerSettings['MinusKeywords']);

	$bannerFields = array(
		"CAMPAIGN_ID" => $campaignId,
		"SETTINGS" => $bannerSettings
	);

	if($ID > 0)
	{
		$result = Adv\YandexBannerTable::update($ID, $bannerFields);
	}
	else
	{
		$result = Adv\YandexBannerTable::add($bannerFields);
	}


	/*
	var_dump($result->isSuccess());
		echo '<pre>'; print_r($bannerFields); echo '</pre>';
		echo '<pre>'; print_r($result); echo '</pre>';
		echo '<pre>'; print_r($request); echo '</pre>';
	die();
	*/

	if($result->isSuccess())
	{
		if($ID <= 0 && $elementId > 0)
		{
예제 #2
0
 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;
 }