223 $result =
new Entity\EventResult();
225 $primary =
$event->getParameter(
"primary");
228 $currentData = static::getByPrimary($primary);
229 $currentData = $currentData->fetch();
235 if($currentData[
'ENGINE_ID'] != $engine->getId())
238 static::getEntity()->getField(
'ENGINE_ID'),
239 Loc::getMessage(
"SEO_CAMPAIGN_ERROR_WRONG_ENGINE")
243 $ownerInfo = $engine->getCurrentUser();
245 if($currentData[
'OWNER_ID'] != $ownerInfo[
'id'])
248 static::getEntity()->getField(
'OWNER_ID'),
249 Loc::getMessage(
"SEO_CAMPAIGN_ERROR_WRONG_OWNER")
253 $data[
'OWNER_NAME'] = $ownerInfo[
'login'];
254 $data[
'XML_ID'] = $currentData[
'XML_ID'];
256 if(!static::$skipRemoteUpdate)
259 if(is_array(
$data[
"SETTINGS"][
'Phrases']))
261 $currentPhrases = $currentData[
"SETTINGS"][
"Phrases"];
263 foreach(
$data[
"SETTINGS"][
'Phrases'] as
$key => $phraseInfo)
265 foreach($currentPhrases as
$k => $currentPhrase)
267 if($currentPhrase[
'Phrase'] == $phraseInfo[
'Phrase'])
269 $data[
"SETTINGS"][
'Phrases'][
$key][
'PhraseID'] = $currentPhrase[
'PhraseID'];
270 unset($currentPhrases[
$k]);
279 if(!static::$skipRemoteUpdate &&
$result->getType() ==
Entity\EventResult::SUCCESS)
283 $engine->updateBanner(
$data[
"SETTINGS"]);
285 $bannerSettings = $engine->getBanners(
array(
$data[
'XML_ID']));
286 $data[
'SETTINGS'] = $bannerSettings[0];
292 static::getEntity()->getField(
'ENGINE_ID'),
378 $bannerParam =
array();
382 if(!empty(
$data[
"XML_ID"]))
385 $bannerParam[
"BannerID"] =
$data[
"XML_ID"];
388 if(!empty(
$data[
"CAMPAIGN_ID"]))
390 $dbRes = YandexCampaignTable::getByPrimary(
$data[
"CAMPAIGN_ID"]);
391 $campaign =
$dbRes->fetch();
394 $data[
'SETTINGS'][
'CampaignID'] = $campaign[
'XML_ID'];
399 static::getEntity()->getField(
'CAMPAIGN_ID'),
400 Loc::getMessage(
'SEO_BANNER_ERROR_CAMPAIGN_NOT_FOUND')
405 if($newBanner || isset(
$data[
'SETTINGS'][
'CampaignID']))
407 $bannerParam[
'CampaignID'] =
$data[
'SETTINGS'][
'CampaignID'];
410 if($newBanner || isset(
$data[
'SETTINGS'][
"Title"]))
412 $bannerParam[
"Title"] = trim(
$data[
'SETTINGS'][
"Title"]);
414 if($bannerParam[
"Title"] ==
'')
417 static::getEntity()->getField(
'NAME'),
418 Loc::getMessage(
'SEO_BANNER_ERROR_NO_NAME')
421 elseif(mb_strlen($bannerParam[
"Title"]) > static::MAX_TITLE_LENGTH)
424 static::getEntity()->getField(
'NAME'),
425 Loc::getMessage(
'SEO_BANNER_ERROR_LONG_NAME',
array(
426 "#MAX#" => static::MAX_TITLE_LENGTH,
432 if($newBanner || isset(
$data[
'SETTINGS'][
"Text"]))
434 $bannerParam[
"Text"] = trim(
$data[
'SETTINGS'][
"Text"]);
435 if($bannerParam[
"Text"] ==
'')
438 static::getEntity()->getField(
'SETTINGS'),
439 Loc::getMessage(
'SEO_BANNER_ERROR_NO_TEXT')
442 elseif(mb_strlen($bannerParam[
"Text"]) > static::MAX_TEXT_LENGTH)
445 static::getEntity()->getField(
'SETTINGS'),
446 Loc::getMessage(
'SEO_BANNER_ERROR_LONG_TEXT',
array(
447 "#MAX#" => static::MAX_TEXT_LENGTH,
453 if($newBanner || isset(
$data[
'SETTINGS'][
"Href"]))
455 $bannerParam[
"Href"] = trim(
$data[
'SETTINGS'][
"Href"]);
456 if($bannerParam[
"Href"] ==
'')
459 static::getEntity()->getField(
'SETTINGS'),
460 Loc::getMessage(
'SEO_BANNER_ERROR_NO_HREF')
466 if($newBanner || isset(
$data[
"SETTINGS"][
"Geo"]))
468 if(is_array(
$data[
"SETTINGS"][
"Geo"]))
470 $data[
"SETTINGS"][
"Geo"] = implode(
",",
$data[
"SETTINGS"][
"Geo"]);
473 $bannerParam[
"Geo"] =
$data[
"SETTINGS"][
"Geo"];
476 if($newBanner || isset(
$data[
"SETTINGS"][
"Phrases"]))
478 if(
$data[
"SETTINGS"][
"Geo"] ==
'')
481 static::getEntity()->getField(
'SETTINGS'),
482 Loc::getMessage(
'SEO_BANNER_ERROR_NO_GEO')
488 static::getEntity()->getField(
'SETTINGS'),
489 Loc::getMessage(
'SEO_BANNER_ERROR_NO_PHRASES')
494 $bannerParam[
"Phrases"] =
$data[
"SETTINGS"][
"Phrases"];
496 foreach($bannerParam[
"Phrases"] as
$key => $phraseInfo)
498 if(is_numeric($phraseInfo[
'AutoBudgetPriority']))
499 $phraseInfo[
'AutoBudgetPriority'] = static::$priorityList[intval($phraseInfo[
'AutoBudgetPriority'])];
501 $bannerParam[
"Phrases"][
$key] = $phraseInfo;
506 if($newBanner || isset(
$data[
"SETTINGS"][
"MinusKeywords"]))
508 if(!is_array(
$data[
"SETTINGS"][
"MinusKeywords"]))
510 if(
$data[
"SETTINGS"][
"MinusKeywords"] <>
'')
516 $data[
"SETTINGS"][
"MinusKeywords"] =
array(
$data[
"SETTINGS"][
"MinusKeywords"]);
520 $bannerParam[
"MinusKeywords"] =
$data[
"SETTINGS"][
"MinusKeywords"];
523 if(!$newBanner &&
$result->getType() ==
Entity\EventResult::SUCCESS)
527 $yandexBannerParam = $engine->getBanners(
array(
$data[
"XML_ID"]));
529 if(!is_array($yandexBannerParam) ||
count($yandexBannerParam) <= 0)
532 static::getEntity()->getField(
'XML_ID'),
534 'SEO_CAMPAIGN_ERROR_BANNER_NOT_FOUND',
541 $bannerParam = array_replace_recursive($yandexBannerParam[0], $bannerParam);
548 static::getEntity()->getField(
'ENGINE_ID'),