public static function checkSession()
 {
     $request = Main\Context::getCurrent()->getRequest();
     if (isset($request[static::URL_PARAM_CAMPAIGN]) && isset($request[static::URL_PARAM_BANNER])) {
         $dbRes = YandexBannerTable::getList(array('filter' => array('=XML_ID' => $request[static::URL_PARAM_BANNER], '=ENGINE.CODE' => YandexDirect::ENGINE_ID), 'select' => array('ID', 'CAMPAIGN_ID')));
         $banner = $dbRes->fetch();
         if ($banner) {
             $_SESSION['SEO_ADV'] = array("ENGINE" => YandexDirect::ENGINE_ID, "CAMPAIGN_ID" => $banner['CAMPAIGN_ID'], "BANNER_ID" => $banner['ID']);
         }
     }
 }
 public static function onGetAttributeTypes()
 {
     return array('seo_yandex_direct_source' => array('MODULE' => 'seo', 'GROUP' => 'source', 'SORT' => 5200, 'NAME' => Loc::getMessage('SEO_CONVERSION_ATTRIBUTE_YANDEX_DIRECT_NAME'), 'BG_COLOR' => '#4bbedb', 'GET_VALUES' => function (array $ids) {
         $dbRes = YandexBannerTable::getList(array('filter' => array("=XML_ID" => $ids), 'select' => array("XML_ID", "NAME"), 'order' => array('NAME' => 'ASC')));
         $bannerList = array();
         while ($banner = $dbRes->fetch()) {
             $bannerList[$banner['XML_ID']] = array("NAME" => array($banner["NAME"]));
         }
         return $bannerList;
     }, 'SPLIT_BY' => 'seo_yandex_direct_source'));
 }
Exemple #3
0
 protected static function checkSessionOrder($orderId)
 {
     if (isset($_SESSION['SEO_ADV']) && is_array($_SESSION['SEO_ADV']) && $_SESSION['SEO_ADV']['BANNER_ID'] > 0 && !in_array($orderId, static::$orderHandlerCalled) && Main\Loader::includeModule('sale') && Main\Loader::includeModule('catalog')) {
         static::$orderHandlerCalled[] = $orderId;
         $banner = null;
         switch ($_SESSION['SEO_ADV']['ENGINE']) {
             case YandexDirect::ENGINE_ID:
                 $dbRes = YandexBannerTable::getList(array('filter' => array('=XML_ID' => $_SESSION['SEO_ADV']['BANNER_ID'], '=ENGINE.CODE' => YandexDirect::ENGINE_ID), 'select' => array('ID', 'CAMPAIGN_ID', 'ENGINE_ID')));
                 $banner = $dbRes->fetch();
                 break;
         }
         if ($banner) {
             $linkedProductsList = static::getBannerLinkedProducts($banner['ID']);
             if (count($linkedProductsList) > 0) {
                 $basket = BasketTable::getList(array('filter' => array('=ORDER_ID' => $orderId), 'select' => array('PRODUCT_ID')));
                 $addEntry = false;
                 while ($item = $basket->fetch()) {
                     if (in_array($item['PRODUCT_ID'], $linkedProductsList)) {
                         $addEntry = true;
                         break;
                     } else {
                         $productInfo = \CCatalogSKU::GetProductInfo($item['PRODUCT_ID']);
                         if (is_array($productInfo) && in_array($productInfo['ID'], $linkedProductsList)) {
                             $addEntry = true;
                             break;
                         }
                     }
                 }
                 if ($addEntry) {
                     $entryData = array('ENGINE_ID' => $banner['ENGINE_ID'], 'CAMPAIGN_ID' => $banner['CAMPAIGN_ID'], 'BANNER_ID' => $banner['ID'], 'ORDER_ID' => $orderId, 'SUM' => 0, 'PROCESSED' => OrderTable::NOT_PROCESSED);
                     OrderTable::add($entryData);
                 }
             }
         }
     }
 }
}

$map = Adv\YandexBannerTable::getMap();

unset($map['GROUP']);
unset($map['CAMPAIGN']);

$campaignList = Adv\YandexBannerTable::getList(array(
	'order' => array($by => $order),
	'filter' => array(
		"=ENGINE_ID" => $engine->getId(),
		"=CAMPAIGN_ID" => $campaign['ID'],
		'=ACTIVE' => $archive ? Adv\YandexBannerTable::INACTIVE : Adv\YandexBannerTable::ACTIVE,
	),
	"select" => array_keys($map),
/*
	'runtime' => array(
		new Entity\ExpressionField(
			'BANNER_CNT',
			'COUNT(%s)',
			"\\Bitrix\\Seo\\Adv\\YandexBannerTable:CAMPAIGN.ID"
		),
	)
*/
));

$data = new \CAdminResult($campaignList, $tableID);
$data->NavStart();

$arHeaders = array(
	array("id"=>"ID", "content"=>Loc::getMessage("SEO_BANNER_ID"), "sort"=>"ID", "default"=>true),
	//array("id"=>"ONLINE", "content"=>"", "default"=>true),
Exemple #5
0
							),
							'text' => $campaign['NAME'],
							'module_id' => 'seo',
							'dynamic' => true,
							'items_id' => "seo_search_adv_items/".$campaign['ID'],
							'items' => array(),
						);
					}

					if(count($yandexAdvCampaigns) > 0)
					{
						$dbRes = Adv\YandexBannerTable::getList(array(
							'order' => array('NAME' => 'ASC'),
							'filter' => array(
								'=ENGINE_ID' => $engine->getId(),
								'=CAMPAIGN_ID' => array_keys($yandexAdvCampaigns),
								'=ACTIVE' => Adv\YandexBannerTable::ACTIVE,
							),
							'select' => array('ID', 'CAMPAIGN_ID', 'NAME'),
						));
						while($banner = $dbRes->fetch())
						{
							$yandexAdvItem['items'][$yandexAdvCampaigns[$banner['CAMPAIGN_ID']]]['items'][] = array(
								'url' => 'seo_search_yandex_direct_banner_edit.php?lang='.LANGUAGE_ID.'&campaign='.$banner['CAMPAIGN_ID'].'&ID='.$banner['ID'],
								'text' => $banner['NAME'],
								'parent_menu' => "seo_search_adv_items/".$banner['CAMPAIGN_ID'],
								'items_id' => "seo_search_adv_items/".$banner['CAMPAIGN_ID']."/".$banner['ID']
							);
						}
					}
				}
                        }
                    } 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']);
$campaignList = Adv\YandexBannerTable::getList(array('order' => array($by => $order), 'filter' => array("=ENGINE_ID" => $engine->getId(), "=CAMPAIGN_ID" => $campaign['ID'], '=ACTIVE' => $archive ? Adv\YandexBannerTable::INACTIVE : Adv\YandexBannerTable::ACTIVE), "select" => array_keys($map)));
$data = new \CAdminResult($campaignList, $tableID);
$data->NavStart();
$arHeaders = array(array("id" => "ID", "content" => Loc::getMessage("SEO_BANNER_ID"), "sort" => "ID", "default" => true), array("id" => "ISACTIVE", "content" => Loc::getMessage('SEO_ISACTIVE'), "default" => true), array("id" => "NAME", "content" => Loc::getMessage('SEO_BANNER_NAME'), "sort" => "NAME", "default" => true), array("id" => "XML_ID", "content" => Loc::getMessage('SEO_BANNER_XML_ID'), "sort" => "XML_ID", "default" => true), array("id" => "SHOW", "content" => Loc::getMessage('SEO_STATUS_SHOW'), "default" => true), array("id" => "MODERATE", "content" => Loc::getMessage('SEO_STATUS_MODERATE'), "default" => true), array("id" => "PHRASES_MODERATE", "content" => Loc::getMessage('SEO_STATUS_PHRASES_MODERATE'), "default" => true), array("id" => "LAST_UPDATE", "content" => Loc::getMessage('SEO_BANNER_LAST_UPDATE'), "sort" => "LAST_UPDATE", "default" => true));
if ($request["mode"] != 'excel') {
    $arHeaders[] = array("id" => "UPDATE", "content" => "", "default" => true);
}
$adminList->AddHeaders($arHeaders);
$adminList->NavText($data->GetNavPrint(Loc::getMessage("PAGES")));
while ($banner = $data->NavNext()) {
    $editUrl = "seo_search_yandex_direct_banner_edit.php?lang=" . LANGUAGE_ID . "&campaign=" . $campaign['ID'] . "&ID=" . $banner["ID"];
    $row =& $adminList->AddRow($banner["ID"], $banner, $editUrl, Loc::getMessage("SEO_BANNER_EDIT_TITLE", array("#ID#" => $banner["ID"], "#XML_ID#" => $banner["XML_ID"])));
    $row->AddViewField("ID", $banner['ID']);
    $row->AddField("NAME", '<a href="' . Converter::getHtmlConverter()->encode($editUrl) . '" title="' . Loc::getMessage("SEO_BANNER_EDIT_TITLE", array("#ID#" => $banner["ID"], "#XML_ID#" => $banner["XML_ID"])) . '">' . Converter::getHtmlConverter()->encode($banner['NAME']) . '</a>');
    $row->AddViewField('LAST_UPDATE', $banner['LAST_UPDATE'] ? $banner['LAST_UPDATE'] : Loc::getMessage('SEO_UPDATE_NEVER'));
    $active = '';
 protected function processStatsResult($campaignId, array $result, YandexDirectLive $liveEngine)
 {
     if ($result['Stat']) {
         $bannerIds = array();
         foreach ($result['Stat'] as $statEntry) {
             $bannerIds[] = $statEntry['BannerID'];
         }
         if (count($bannerIds) > 0) {
             $dbRes = YandexBannerTable::getList(array('filter' => array('=XML_ID' => array_values(array_unique($bannerIds)), '=ENGINE_ID' => $liveEngine->getId()), 'select' => array('ID', 'XML_ID')));
             $bannerList = array();
             while ($bannerData = $dbRes->fetch()) {
                 $bannerList[$bannerData['XML_ID']] = $bannerData['ID'];
             }
             if (count($bannerList) > 0) {
                 foreach ($result['Stat'] as $statEntry) {
                     if (array_key_exists($statEntry['BannerID'], $bannerList)) {
                         static::add(array('CAMPAIGN_ID' => $campaignId, 'BANNER_ID' => $bannerList[$statEntry['BannerID']], 'DATE_DAY' => new Date($statEntry['StatDate'], 'Y-m-d'), 'CURRENCY' => $result['Currency'], 'SUM' => $statEntry['Sum'], 'SUM_SEARCH' => $statEntry['SumSearch'], 'SUM_CONTEXT' => $statEntry['SumContext'], 'CLICKS' => $statEntry['Clicks'], 'CLICKS_SEARCH' => $statEntry['ClicksSearch'], 'CLICKS_CONTEXT' => $statEntry['ClicksContext'], 'SHOWS' => $statEntry['Shows'], 'SHOWS_SEARCH' => $statEntry['ShowsSearch'], 'SHOWS_CONTEXT' => $statEntry['ShowsContext']));
                     }
                 }
             }
         }
     }
 }
Exemple #8
0
 public static function updateAgent()
 {
     $engine = new self();
     if ($engine->getAuthSettings()) {
         try {
             $dbRes = YandexCampaignTable::getList(array('filter' => array('<LAST_UPDATE' => DateTime::createFromTimestamp(time() - YandexCampaignTable::CACHE_LIFETIME), '=ENGINE_ID' => $engine->getId()), 'select' => array('CNT'), 'runtime' => array(new ExpressionField('CNT', 'COUNT(*)'))));
             $res = $dbRes->fetch();
             if ($res['CNT'] > 0) {
                 $engine->updateCampaignManual();
             }
             $availableCampaigns = array();
             $campaignList = $engine->getCampaignList();
             foreach ($campaignList as $campaignInfo) {
                 $availableCampaigns[] = $campaignInfo['CampaignID'];
             }
             if (count($availableCampaigns) > 0) {
                 $dbRes = YandexBannerTable::getList(array('group' => array('CAMPAIGN_ID'), 'filter' => array('<LAST_UPDATE' => DateTime::createFromTimestamp(time() - YandexBannerTable::CACHE_LIFETIME), '=ENGINE_ID' => $engine->getId(), '=CAMPAIGN.XML_ID' => $availableCampaigns), 'select' => array('CAMPAIGN_ID')));
                 $campaignId = array();
                 while ($res = $dbRes->fetch()) {
                     $campaignId[] = $res['CAMPAIGN_ID'];
                 }
                 if (count($campaignId) > 0) {
                     $engine->updateBannersManual($campaignId);
                 }
             }
         } catch (YandexDirectException $e) {
         }
     }
     return __CLASS__ . "::updateAgent();";
 }
Exemple #9
0
 /**
  * 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);
 }
Exemple #10
0
 public static function checkQuantityAgent()
 {
     if (!IsModuleInstalled("catalog")) {
         return __CLASS__ . "::checkQuantityAgent();";
     }
     $dbRes = YandexBannerTable::getList(array('filter' => array(array('=AUTO_QUANTITY_ON' => YandexBannerTable::MARKED), array('=AUTO_QUANTITY_OFF' => YandexBannerTable::MARKED), 'LOGIC' => "OR"), 'select' => array('ID', 'XML_ID', 'CAMPAIGN_ID', 'CAMPAIGN_XML_ID' => 'CAMPAIGN.XML_ID', 'AUTO_QUANTITY_ON', 'AUTO_QUANTITY_OFF')));
     $engine = new YandexDirect();
     $bannersListToStop = array();
     $bannersListToResume = array();
     $bannersListToUnMarkStopped = array();
     $bannersListToUnMarkResumed = array();
     $bannersLogData = array();
     while ($banner = $dbRes->fetch()) {
         if ($banner["AUTO_QUANTITY_ON"] == YandexBannerTable::MARKED) {
             if (!isset($bannersListToResume[$banner["CAMPAIGN_XML_ID"]])) {
                 $bannersListToResume[$banner["CAMPAIGN_XML_ID"]] = array();
             }
             $bannersListToResume[$banner["CAMPAIGN_XML_ID"]][$banner["ID"]] = $banner["XML_ID"];
             $causeCode = AutologTable::CODE_QUANTITY_ON;
             if ($banner["AUTO_QUANTITY_OFF"] == YandexBannerTable::MARKED) {
                 $bannersListToUnMarkStopped[] = $banner["ID"];
             }
         } else {
             if (!isset($bannersListToResume[$banner["CAMPAIGN_XML_ID"]])) {
                 $bannersListToStop[$banner["CAMPAIGN_XML_ID"]] = array();
             }
             $bannersListToStop[$banner["CAMPAIGN_XML_ID"]][$banner["ID"]] = $banner["XML_ID"];
             $causeCode = AutologTable::CODE_QUANTITY_OFF;
             if ($banner["AUTO_QUANTITY_ON"] == YandexBannerTable::MARKED) {
                 $bannersListToUnMarkResumed[] = $banner["ID"];
             }
         }
         $bannersLogData[$banner["ID"]] = array('CAMPAIGN_ID' => $banner['CAMPAIGN_ID'], 'CAMPAIGN_XML_ID' => $banner['CAMPAIGN_XML_ID'], 'BANNER_ID' => $banner['ID'], 'BANNER_XML_ID' => $banner['XML_ID'], 'CAUSE_CODE' => $causeCode);
     }
     if (count($bannersLogData) > 0) {
         foreach ($bannersListToResume as $campaignId => $bannersList) {
             if (count($bannersList) > 0) {
                 $success = true;
                 try {
                     $engine->resumeBanners($campaignId, array_values($bannersList));
                 } catch (YandexDirectException $e) {
                     $success = false;
                 }
                 foreach ($bannersList as $bannerId => $bannerXmlId) {
                     $logEntry = $bannersLogData[$bannerId];
                     $logEntry['ENGINE_ID'] = $engine->getId();
                     $logEntry['SUCCESS'] = $success ? AutologTable::SUCCESS : AutologTable::FAILURE;
                     AutologTable::add($logEntry);
                 }
                 $bannersListToUnMarkResumed = array_merge($bannersListToUnMarkResumed, array_keys($bannersList));
             }
         }
         foreach ($bannersListToStop as $campaignId => $bannersList) {
             if (count($bannersList) > 0) {
                 $success = true;
                 try {
                     $engine->stopBanners($campaignId, array_values($bannersList));
                 } catch (YandexDirectException $e) {
                     $success = false;
                 }
                 foreach ($bannersList as $bannerId => $bannerXmlId) {
                     $logEntry = $bannersLogData[$bannerId];
                     $logEntry['ENGINE_ID'] = $engine->getId();
                     $logEntry['SUCCESS'] = $success ? AutologTable::SUCCESS : AutologTable::FAILURE;
                     AutologTable::add($logEntry);
                 }
                 $bannersListToUnMarkStopped = array_merge($bannersListToUnMarkStopped, array_keys($bannersList));
             }
         }
         if (count($bannersListToUnMarkStopped) > 0) {
             YandexBannerTable::unMarkStopped($bannersListToUnMarkStopped);
         }
         if (count($bannersListToUnMarkResumed) > 0) {
             YandexBannerTable::unMarkResumed($bannersListToUnMarkResumed);
         }
     }
     return __CLASS__ . "::checkQuantityAgent();";
 }
     } else {
         $res = array("session" => $loadingSession, "amount" => $_SESSION[$loadingSession]['ORIGINAL_CNT'], "left" => count($_SESSION[$loadingSession]["GAPS"]));
     }
     break;
 case 'banner_stat_detail':
     $res = array('error' => array('message' => 'Wrong banners list'));
     $bSale = \Bitrix\Main\ModuleManager::isModuleInstalled('sale') && \Bitrix\Main\ModuleManager::isModuleInstalled('catalog') && Loader::includeModule('currency');
     $bannerId = $_REQUEST['banner'];
     if ($bannerId) {
         $bSingle = !is_array($bannerId);
         if ($bSingle) {
             $bannerId = array($bannerId);
         }
         array_map('intval', $bannerId);
         if (count($bannerId) > 0) {
             $dbBanners = Adv\YandexBannerTable::getList(array('filter' => array('@ID' => $bannerId, '=ENGINE_ID' => $engine->getId(), '=ACTIVE' => Adv\YandexBannerTable::ACTIVE), 'select' => array('ID', 'CAMPAIGN_ID', 'SETTINGS')));
             $bannerList = array();
             $campaignList = array();
             while ($banner = $dbBanners->fetch()) {
                 $campaignList[] = $banner['CAMPAIGN_ID'];
                 $bannerList[$banner['ID']] = $banner;
             }
             $campaignList = array_unique($campaignList);
             if (count($campaignList) > 0) {
                 $dbCampaigns = Adv\YandexCampaignTable::getList(array('filter' => array('@ID' => $campaignList, '=ENGINE_ID' => $engine->getId(), '=ACTIVE' => Adv\YandexCampaignTable::ACTIVE), 'select' => array('ID', 'SETTINGS')));
                 $campaignList = array();
                 while ($campaign = $dbCampaigns->fetch()) {
                     $campaignList[$campaign['ID']] = $campaign;
                 }
                 $dateFinish = new Date();
                 $bannerListToCheck = array();
				}

			break;

			case 'banners_get':
				$campaignId = intval($_REQUEST['campaign']);

				if($campaignId > 0)
				{
					$res = array();
					$dbRes = Adv\YandexBannerTable::getList(array(
						'filter' => array(
							'=CAMPAIGN_ID' => $campaignId,
							'=ACTIVE' => Adv\YandexBannerTable::ACTIVE,
							'=ENGINE_ID' => $engine->getId(),
						),
						'order' => array(
							'NAME' => 'ASC',
						),
						'select' => array('ID', 'NAME', 'XML_ID')
					));
					while($banner = $dbRes->fetch())
					{
						$res[] = $banner;
					}
				}

			break;

			case 'banner_stats':
				$res = array();