Exemple #1
0
 public static function onBeforeDelete(Entity\Event $event)
 {
     $result = new Entity\EventResult();
     $primary = $event->getParameter("primary");
     if (intval($primary['ID']) > 0) {
         $dbRes = \Bitrix\Sale\Internals\ShipmentExtraServiceTable::getList(array('filter' => array('=EXTRA_SERVICE_ID' => $primary['ID'])));
         if ($row = $dbRes->fetch()) {
             $result->addError(new Entity\EntityError(str_replace('#ID#', $primary['ID'], Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_ERROR_DELETE'))));
         }
     }
     return $result;
 }
Exemple #2
0
 /**
  * Handler of before delete event
  * @param Entity\Event $event
  * @return Entity\EventResult
  */
 public static function onBeforeDelete(Entity\Event $event)
 {
     $result = new Entity\EventResult();
     $data = $event->getParameters();
     $chainListDb = MailingChainTable::getList(array('select' => array('ID', 'SUBJECT', 'MAILING_ID', 'MAILING_NAME' => 'MAILING.NAME'), 'filter' => array('TEMPLATE_TYPE' => 'USER', 'TEMPLATE_ID' => $data['primary']['ID']), 'order' => array('MAILING_NAME' => 'ASC', 'ID')));
     if ($chainListDb->getSelectedRowsCount() > 0) {
         $template = static::getRowById($data['primary']['ID']);
         $messageList = array();
         while ($chain = $chainListDb->fetch()) {
             $messageList[$chain['MAILING_NAME']] = '[' . $chain['ID'] . '] ' . htmlspecialcharsbx($chain['SUBJECT']) . "\n";
         }
         $message = Loc::getMessage('SENDER_ENTITY_TEMPLATE_DELETE_ERROR_TEMPLATE', array('#NAME#' => $template['NAME'])) . "\n";
         foreach ($messageList as $mailingName => $messageItem) {
             $message .= Loc::getMessage('SENDER_ENTITY_TEMPLATE_DELETE_ERROR_MAILING', array('#NAME#' => $mailingName)) . "\n" . $messageItem . "\n";
         }
         $result->addError(new Entity\EntityError($message));
     }
     return $result;
 }
Exemple #3
0
	/**
	 * Checks banner data before sending it to Yandex.
	 *
	 * $data array format:
	 *
	 * <ul>
	 * <li>ID
	 * <li>XML_ID
	 * <li>NAME
	 * <li>SETTINGS<ul>
	 *    <li>BannerID
	 *    <li>CampaignID *
	 *    <li>Title *
	 *    <li>Text *
	 *    <li>Href *
	 *    <li>Geo - comma-separated list of yandex location IDs
	 *    <li>Phrases *
	 *    <li>MinusKeywords
	 *  </ul>
	 * </ul>
	 *
	 * @param Engine\YandexDirect $engine Engine object.
	 * @param array $data Banner data.
	 * @param Entity\EventResult $result Event result object.
	 *
	 * @return array
	 * @see http://api.yandex.ru/direct/doc/reference/CreateOrUpdateBanner.xml
	 */
	protected static function createParam(Engine\YandexDirect $engine, array $data, Entity\EventResult $result)
	{
		$bannerParam = array();

		$newBanner = true;

		if(!empty($data["XML_ID"]))
		{
			$newBanner = false;
			$bannerParam["BannerID"] = $data["XML_ID"];
		}

		if(!empty($data["CAMPAIGN_ID"]))
		{
			$dbRes = YandexCampaignTable::getByPrimary($data["CAMPAIGN_ID"]);
			$campaign = $dbRes->fetch();
			if($campaign)
			{
				$data['SETTINGS']['CampaignID'] = $campaign['XML_ID'];
			}
			else
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('CAMPAIGN_ID'),
					Loc::getMessage('SEO_BANNER_ERROR_CAMPAIGN_NOT_FOUND')
				));
			}
		}

		if($newBanner || isset($data['SETTINGS']['CampaignID']))
		{
			$bannerParam['CampaignID'] = $data['SETTINGS']['CampaignID'];
		}

		if($newBanner || isset($data['SETTINGS']["Title"]))
		{
			$bannerParam["Title"] = trim($data['SETTINGS']["Title"]);

			if(strlen($bannerParam["Title"]) <= 0)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('NAME'),
					Loc::getMessage('SEO_BANNER_ERROR_NO_NAME')
				));
			}
			elseif(strlen($bannerParam["Title"]) > static::MAX_TITLE_LENGTH)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('NAME'),
					Loc::getMessage('SEO_BANNER_ERROR_LONG_NAME', array(
						"#MAX#" => static::MAX_TITLE_LENGTH,
					))
				));
			}
		}

		if($newBanner || isset($data['SETTINGS']["Text"]))
		{
			$bannerParam["Text"] = trim($data['SETTINGS']["Text"]);
			if(strlen($bannerParam["Text"]) <= 0)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('SETTINGS'),
					Loc::getMessage('SEO_BANNER_ERROR_NO_TEXT')
				));
			}
			elseif(strlen($bannerParam["Text"]) > static::MAX_TEXT_LENGTH)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('SETTINGS'),
					Loc::getMessage('SEO_BANNER_ERROR_LONG_TEXT', array(
						"#MAX#" => static::MAX_TEXT_LENGTH,
					))
				));
			}
		}

		if($newBanner || isset($data['SETTINGS']["Href"]))
		{
			$bannerParam["Href"] = trim($data['SETTINGS']["Href"]);
			if(strlen($bannerParam["Href"]) <= 0)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('SETTINGS'),
					Loc::getMessage('SEO_BANNER_ERROR_NO_HREF')
				));
			}
		}

		if($newBanner || isset($data["SETTINGS"]["Geo"]))
		{
			if(is_array($data["SETTINGS"]["Geo"]))
			{
				$data["SETTINGS"]["Geo"] = implode(",", $data["SETTINGS"]["Geo"]);
			}

			$bannerParam["Geo"] = $data["SETTINGS"]["Geo"];
		}

		if($newBanner || isset($data["SETTINGS"]["Phrases"]))
		{
			if(!is_array($data["SETTINGS"]["Phrases"]) || count($data["SETTINGS"]["Phrases"]) <= 0)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('SETTINGS'),
					Loc::getMessage('SEO_BANNER_ERROR_NO_PHRASES')
				));
			}
			else
			{
				$bannerParam["Phrases"] = $data["SETTINGS"]["Phrases"];

				foreach($bannerParam["Phrases"] as $key => $phraseInfo)
				{
					$phraseInfo['AutoBudgetPriority'] = static::$priorityList[intval($phraseInfo['AutoBudgetPriority'])];

					$bannerParam["Phrases"][$key] = $phraseInfo;
				}
			}
		}

		if($newBanner || isset($data["SETTINGS"]["MinusKeywords"]))
		{
			if(!is_array($data["SETTINGS"]["MinusKeywords"]))
			{
				if(strlen($data["SETTINGS"]["MinusKeywords"]) > 0)
				{
					$data["SETTINGS"]["MinusKeywords"] = array();
				}
				else
				{
					$data["SETTINGS"]["MinusKeywords"] = array($data["SETTINGS"]["MinusKeywords"]);
				}
			}

			$bannerParam["MinusKeywords"] = $data["SETTINGS"]["MinusKeywords"];
		}

		if(!$newBanner && $result->getType() == Entity\EventResult::SUCCESS)
		{
			try
			{
				$yandexBannerParam = $engine->getBanners(array($data["XML_ID"]));

				if(!is_array($yandexBannerParam) || count($yandexBannerParam) <= 0)
				{
					$result->addError(new Entity\FieldError(
						static::getEntity()->getField('XML_ID'),
						Loc::getMessage(
							'SEO_CAMPAIGN_ERROR_BANNER_NOT_FOUND',
							array('#ID#' => $data["XML_ID"])
						)
					));
				}
				else
				{
					$bannerParam = array_replace_recursive($yandexBannerParam[0], $bannerParam);
				}
			}
			catch(Engine\YandexDirectException $e)
			{
				$result->addError(
					new Entity\FieldError(
						static::getEntity()->getField('ENGINE_ID'),
						$e->getMessage(),
						$e->getCode()
					)
				);
			}
		}

		return $bannerParam;
	}
Exemple #4
0
 public static function onBeforeDelete(Entity\Event $event)
 {
     $result = new Entity\EventResult();
     $primary = $event->getParameter("primary");
     if (self::isDeliveryInOrders($primary["ID"])) {
         $result->addError(new Entity\FieldError($event->getEntity()->getField('ID'), Loc::getMessage('DELIVERY_SERVICE_ENTITY_ERROR_DELETE_IN_ORDERS_EXIST')));
     } else {
         $dbRes = self::getList(array('filter' => array("PARENT_ID" => $primary["ID"]), 'select' => array("ID")));
         while ($child = $dbRes->fetch()) {
             if (self::isDeliveryInOrders($child["ID"])) {
                 $result->addError(new Entity\FieldError($event->getEntity()->getField('ID'), Loc::getMessage('DELIVERY_SERVICE_ENTITY_ERROR_DELETE_IN_ORDERS_EXIST_CHLD')));
                 break;
             }
         }
     }
     return $result;
 }
Exemple #5
0
 /**
  * Checks campaign data before sending it to Yandex
  *
  * $data array format:
  *
  * <ul>
  * <li>ID
  * <li>XML_ID
  * <li>NAME
  * <li>SETTINGS<ul>
  *    <li>FIO
  *    <li>StartDate
  *    <li>Strategy<ul>
  *        <li>StrategyName
  *        <li>MaxPrice
  *        <li>AveragePrice
  *        <li>WeeklySumLimit
  *        <li>ClicksPerWeek
  *    </ul>
  *    <li>EmailNotification<ul>
  *        <li>Email
  *        <li>WarnPlaceInterval
  *        <li>MoneyWarningValue
  *    </ul>
  *  </ul>
  * </ul>
  *
  * @param Engine\YandexDirect $engine Engine object.
  * @param array $data Campaign data.
  * @param Entity\EventResult $result Event result object.
  *
  * @return array
  * @see http://api.yandex.ru/direct/doc/reference/CreateOrUpdateCampaign.xml
  */
 protected static function createParam(Engine\YandexDirect $engine, array $data, Entity\EventResult $result)
 {
     $settings = $engine->getSettings();
     $campaignParam = array("Login" => $settings["AUTH_USER"]["login"]);
     $newCampaign = true;
     if (!empty($data["XML_ID"])) {
         $newCampaign = false;
         $campaignParam["CampaignID"] = $data["XML_ID"];
     }
     if ($newCampaign || isset($data['SETTINGS']["Name"])) {
         $campaignParam["Name"] = trim($data['SETTINGS']["Name"]);
         if (strlen($campaignParam["Name"]) <= 0) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('NAME'), Loc::getMessage('SEO_CAMPAIGN_ERROR_NO_NAME')));
         }
     }
     if ($newCampaign || isset($data["SETTINGS"]["FIO"])) {
         $campaignParam["FIO"] = trim($data["SETTINGS"]["FIO"]);
         if (strlen($campaignParam["FIO"]) <= 0) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_NO_FIO')));
         }
     }
     if (is_array($data["SETTINGS"]) && array_key_exists("StartDate", $data["SETTINGS"])) {
         if (is_a($data["SETTINGS"]["StartDate"], "Bitrix\\Main\\Type\\Date")) {
             $campaignParam["StartDate"] = $data["SETTINGS"]["StartDate"]->convertFormatToPhp("Y-m-d");
         } elseif (is_string($data["SETTINGS"]["StartDate"])) {
             if (preg_match("/^\\d{4}-\\d{2}-\\d{2}\$/", $data["SETTINGS"]["StartDate"])) {
                 $campaignParam["StartDate"] = $data["SETTINGS"]["StartDate"];
             } else {
                 $ts = MakeTimeStamp($data["SETTINGS"]["StartDate"], FORMAT_DATE);
                 if ($ts > 0) {
                     $campaignParam["StartDate"] = date('Y-m-d', $ts);
                 }
             }
         }
         if (!$campaignParam["StartDate"]) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_NO_START_DATE')));
         }
     }
     if ($newCampaign || isset($data["SETTINGS"]["Strategy"])) {
         if (empty($data["SETTINGS"]["Strategy"]) || !is_array($data["SETTINGS"]["Strategy"]) || empty($data["SETTINGS"]["Strategy"]["StrategyName"])) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_NO_STRATEGY')));
         }
         if (array_key_exists($data["SETTINGS"]["Strategy"]["StrategyName"], self::$strategyConfig)) {
             $strategy = $data["SETTINGS"]["Strategy"]["StrategyName"];
             $config = self::$strategyConfig[$strategy];
             $campaignParam["Strategy"] = array("StrategyName" => $strategy);
             foreach ($data["SETTINGS"]["Strategy"] as $param => $value) {
                 if ($param !== "StrategyName") {
                     if (array_key_exists($param, $config)) {
                         $campaignParam["Strategy"][$param] = $value;
                     } else {
                         $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_STRATEGY_PARAM_NOT_SUPPORTED', array('#PARAM#' => $param, '#STRATEGY#' => $strategy))));
                     }
                 }
             }
             foreach ($config as $key => $def) {
                 if ($def['mandatory'] || isset($campaignParam["Strategy"][$key])) {
                     switch ($def['type']) {
                         case 'int':
                             $campaignParam["Strategy"][$key] = intval($campaignParam["Strategy"][$key]);
                             break;
                         case 'float':
                             $campaignParam["Strategy"][$key] = doubleval($campaignParam["Strategy"][$key]);
                             break;
                     }
                     if (!$def['mandatory'] && empty($campaignParam["Strategy"][$key])) {
                         unset($campaignParam["Strategy"][$key]);
                     }
                 }
                 if ($def['mandatory'] && empty($campaignParam["Strategy"][$key])) {
                     $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_STRATEGY_PARAM_MANDATORY', array('#PARAM#' => Loc::getMessage('SEO_CAMPAIGN_STRATEGY_PARAM_' . ToUpper($key)), '#STRATEGY#' => Loc::getMessage('SEO_CAMPAIGN_STRATEGY_' . $strategy)))));
                 }
             }
         } else {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_STRATEGY_NOT_SUPPORTED', array('#STRATEGY#' => $data["SETTINGS"]["Strategy"]["StrategyName"]))));
         }
     }
     if ($newCampaign || !empty($data["SETTINGS"]["EmailNotification"])) {
         if (empty($data["SETTINGS"]["EmailNotification"]) || !is_array($data["SETTINGS"]["EmailNotification"]) || !check_email($data["SETTINGS"]["EmailNotification"]['Email'])) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_WRONG_EMAIL')));
         }
         $campaignParam["EmailNotification"] = array("Email" => trim($data["SETTINGS"]["EmailNotification"]['Email']), "WarnPlaceInterval" => intval($data["SETTINGS"]["EmailNotification"]['WarnPlaceInterval']), "MoneyWarningValue" => intval($data["SETTINGS"]["EmailNotification"]['MoneyWarningValue']), "SendWarn" => intval($data["SETTINGS"]["EmailNotification"]['SendWarn']));
         if ($campaignParam["EmailNotification"]['SendWarn'] === true || $campaignParam["EmailNotification"]['SendWarn'] === 1 || $campaignParam["EmailNotification"]['SendWarn'] === 'Y') {
             $campaignParam["EmailNotification"]['SendWarn'] = Engine\YandexDirect::BOOL_YES;
         }
         if ($campaignParam["EmailNotification"]['SendWarn'] === false || $campaignParam["EmailNotification"]['SendWarn'] === 0 || $campaignParam["EmailNotification"]['SendWarn'] === 'N') {
             $campaignParam["EmailNotification"]['SendWarn'] = Engine\YandexDirect::BOOL_NO;
         }
         if (!in_array($campaignParam["EmailNotification"]["WarnPlaceInterval"], self::$allowedWarnPlaceIntervalValues)) {
             if ($campaignParam["EmailNotification"]['SendWarn'] == Engine\YandexDirect::BOOL_YES) {
                 $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_WRONG_INTERVAL', array('#VALUES#' => implode(',', self::$allowedWarnPlaceIntervalValues)))));
             } else {
                 $campaignParam["EmailNotification"]["WarnPlaceInterval"] = self::MONEY_WARN_PLACE_INTERVAL_DEFAULT;
             }
         }
         if ($campaignParam["EmailNotification"]["MoneyWarningValue"] < self::$allowedMoneyWarningInterval[0] || $campaignParam["EmailNotification"]["MoneyWarningValue"] > self::$allowedMoneyWarningInterval[1]) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_WRONG_WARNING', array('#MIN#' => self::$allowedMoneyWarningInterval[0], '#MAX#' => self::$allowedMoneyWarningInterval[1]))));
         }
     }
     if ($newCampaign || isset($data["SETTINGS"]["MinusKeywords"])) {
         if (!is_array($data["SETTINGS"]["MinusKeywords"])) {
             if (strlen($data["SETTINGS"]["MinusKeywords"]) > 0) {
                 $data["SETTINGS"]["MinusKeywords"] = array();
             } else {
                 $data["SETTINGS"]["MinusKeywords"] = array($data["SETTINGS"]["MinusKeywords"]);
             }
         }
         $campaignParam["MinusKeywords"] = $data["SETTINGS"]["MinusKeywords"];
     }
     if (!$newCampaign && $result->getType() == Entity\EventResult::SUCCESS) {
         try {
             $yandexCampaignParam = $engine->getCampaign($data["XML_ID"]);
             if (!is_array($yandexCampaignParam) || count($yandexCampaignParam) <= 0) {
                 $result->addError(new Entity\FieldError(static::getEntity()->getField('XML_ID'), Loc::getMessage('SEO_CAMPAIGN_ERROR_CAMPAIGN_NOT_FOUND', array('#ID#' => $data["XML_ID"]))));
             } else {
                 $campaignParam = array_replace_recursive($yandexCampaignParam[0], $campaignParam);
             }
         } catch (Engine\YandexDirectException $e) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('ENGINE_ID'), $e->getMessage(), $e->getCode()));
         }
     }
     return $campaignParam;
 }