158 $result =
new Entity\EventResult();
160 $data = $event->getParameter(
"fields");
163 $ownerInfo = $engine->getCurrentUser();
165 if(!static::$skipRemoteUpdate)
168 $data[
"XML_ID"] =
'Error';
172 $data[
"XML_ID"] = $data[
"SETTINGS"][
"BannerID"];
175 $data[
"NAME"] = $data[
"SETTINGS"][
"Title"];
176 $data[
"ENGINE_ID"] = $engine->getId();
178 $data[
'OWNER_ID'] = $ownerInfo[
'id'];
179 $data[
'OWNER_NAME'] = $ownerInfo[
'login'];
181 if(!static::$skipRemoteUpdate && $result->getType() ==
Entity\EventResult::SUCCESS)
185 $data[
"XML_ID"] = $engine->addBanner($data[
"SETTINGS"]);
187 $bannerSettings = $engine->getBanners(array($data[
'XML_ID']));
188 $data[
'SETTINGS'] = $bannerSettings[0];
193 static::getEntity()->getField(
'ENGINE_ID'),
201 $data[
'ACTIVE'] = $data[
'SETTINGS'][
'StatusArchive'] == Engine\YandexDirect::BOOL_YES
205 $result->modifyFields($data);
223 $result =
new Entity\EventResult();
225 $primary = $event->getParameter(
"primary");
226 $data = $event->getParameter(
"fields");
228 $currentData = static::getByPrimary($primary);
229 $currentData = $currentData->fetch();
235 if($currentData[
'ENGINE_ID'] != $engine->getId())
238 static::getEntity()->getField(
'ENGINE_ID'),
243 $ownerInfo = $engine->getCurrentUser();
245 if($currentData[
'OWNER_ID'] != $ownerInfo[
'id'])
248 static::getEntity()->getField(
'OWNER_ID'),
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]);
277 $data[
"NAME"] = $data[
"SETTINGS"][
"Title"];
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'),
301 $data[
'ACTIVE'] = $data[
'SETTINGS'][
'StatusArchive'] == Engine\YandexDirect::BOOL_YES
305 $result->modifyFields($data);
324 if(!static::$skipRemoteUpdate)
326 $primary = $event->getParameter(
"primary");
330 $dbRes = static::getList(array(
333 '=ENGINE_ID' => $engine->getId(),
336 'XML_ID',
'CAMPAIGN_XML_ID' =>
'CAMPAIGN.XML_ID',
339 $banner = $dbRes->fetch();
343 $engine->deleteBanners($banner[
'CAMPAIGN_XML_ID'], array($banner[
'XML_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'),
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'),
421 elseif(mb_strlen($bannerParam[
"Title"]) > static::MAX_TITLE_LENGTH)
424 static::getEntity()->getField(
'NAME'),
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'),
442 elseif(mb_strlen($bannerParam[
"Text"]) > static::MAX_TEXT_LENGTH)
445 static::getEntity()->getField(
'SETTINGS'),
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'),
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'),
485 elseif(!is_array($data[
"SETTINGS"][
"Phrases"]) || count($data[
"SETTINGS"][
"Phrases"]) <= 0)
488 static::getEntity()->getField(
'SETTINGS'),
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"] <>
'')
512 $data[
"SETTINGS"][
"MinusKeywords"] = array();
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',
535 array(
'#ID#' => $data[
"XML_ID"])
541 $bannerParam = array_replace_recursive($yandexBannerParam[0], $bannerParam);
548 static::getEntity()->getField(
'ENGINE_ID'),
561 if(count($idList) > 0)
563 $connection = Main\Application::getConnection();
564 $sqlHelper = $connection->getSqlHelper();
566 $idList = array_map(
"intval", $idList);
568 $update = $sqlHelper->prepareUpdate(static::getTableName(), array(
569 "AUTO_QUANTITY_OFF" => static::MARKED,
572 $connection->queryExecute(
573 "UPDATE ".static::getTableName().
" SET ".$update[0].
" WHERE ID IN (".implode(
",", $idList).
")"
580 if(count($idList) > 0)
582 $connection = Main\Application::getConnection();
583 $sqlHelper = $connection->getSqlHelper();
585 $idList = array_map(
"intval", $idList);
587 $update = $sqlHelper->prepareUpdate(static::getTableName(), array(
588 "AUTO_QUANTITY_ON" => static::MARKED,
591 $connection->queryExecute(
592 "UPDATE ".static::getTableName().
" SET ".$update[0].
" WHERE ID IN (".implode(
",", $idList).
")"
599 if(count($idList) > 0)
601 $connection = Main\Application::getConnection();
602 $sqlHelper = $connection->getSqlHelper();
604 $idList = array_map(
"intval", $idList);
606 $update = $sqlHelper->prepareUpdate(static::getTableName(), array(
607 "AUTO_QUANTITY_OFF" => static::ACTIVE,
610 $connection->queryExecute(
611 "UPDATE ".static::getTableName().
" SET ".$update[0].
" WHERE ID IN (".implode(
",", $idList).
")"
618 if(count($idList) > 0)
620 $connection = Main\Application::getConnection();
621 $sqlHelper = $connection->getSqlHelper();
623 $idList = array_map(
"intval", $idList);
625 $update = $sqlHelper->prepareUpdate(static::getTableName(), array(
626 "AUTO_QUANTITY_ON" => static::ACTIVE,
629 $connection->queryExecute(
630 "UPDATE ".static::getTableName().
" SET ".$update[0].
" WHERE ID IN (".implode(
",", $idList).
")"