本文整理汇总了PHP中Bitrix\Main\Event类的典型用法代码示例。如果您正苦于以下问题:PHP Event类的具体用法?PHP Event怎么用?PHP Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getInstance
private static function getInstance()
{
if (self::$instance) {
return self::$instance;
}
$loader = new BitrixLoader($_SERVER['DOCUMENT_ROOT']);
$c = Configuration::getInstance();
$config = $c->get('maximaster');
$twigConfig = (array) $config['tools']['twig'];
$defaultConfig = array('debug' => false, 'charset' => SITE_CHARSET, 'cache' => $_SERVER['DOCUMENT_ROOT'] . '/bitrix/cache/maximaster/tools.twig', 'auto_reload' => isset($_GET['clear_cache']) && strtoupper($_GET['clear_cache']) == 'Y', 'autoescape' => false);
$twigOptions = array_merge($defaultConfig, $twigConfig);
$twig = new \Twig_Environment($loader, $twigOptions);
if ($twig->isDebug()) {
$twig->addExtension(new \Twig_Extension_Debug());
}
$twig->addExtension(new BitrixExtension());
$twig->addExtension(new CustomFunctionsExtension());
$event = new Event('', 'onAfterTwigTemplateEngineInited', array($twig));
$event->send();
if ($event->getResults()) {
foreach ($event->getResults() as $evenResult) {
if ($evenResult->getType() == \Bitrix\Main\EventResult::SUCCESS) {
$twig = current($evenResult->getParameters());
}
}
}
return self::$instance = $twig;
}
开发者ID:mlavrinenko,项目名称:tools.twig,代码行数:28,代码来源:TemplateEngine.php
示例2: onExecuteStartWriting
function onExecuteStartWriting(\Bitrix\Main\Event $event)
{
$parameters = $event->getParameters();
$userId = $parameters[0];
$dialogId = $parameters[1] . $parameters[2];
if ($userId > 0) {
if (!\Bitrix\Main\Loader::includeModule('pull')) {
return;
}
\CPushManager::DeleteFromQueueBySubTag($userId, 'IM_MESS');
if (intval($dialogId) > 0) {
\CPullStack::AddByUser($dialogId, array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)));
} elseif (substr($dialogId, 0, 4) == 'chat') {
$chatId = substr($dialogId, 4);
$arRelation = \CIMChat::GetRelationById($chatId);
unset($arRelation[$userId]);
$pullMessage = array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId));
\CPullStack::AddByUsers(array_keys($arRelation), $pullMessage);
$orm = \Bitrix\Im\ChatTable::getById($chatId);
$chat = $orm->fetch();
if ($chat['TYPE'] == IM_MESSAGE_OPEN) {
\CPullWatch::AddToStack('IM_PUBLIC_' . $chatId, $pullMessage);
}
}
}
}
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:26,代码来源:startwritinghandler.php
示例3: initClassesList
public static function initClassesList()
{
if (static::$classes !== null) {
return true;
}
$classes = array('\\Bitrix\\Sale\\Delivery\\ExtraServices\\Enum' => 'lib/delivery/extra_services/enum.php', '\\Bitrix\\Sale\\Delivery\\ExtraServices\\Store' => 'lib/delivery/extra_services/store.php', '\\Bitrix\\Sale\\Delivery\\ExtraServices\\String' => 'lib/delivery/extra_services/string.php', '\\Bitrix\\Sale\\Delivery\\ExtraServices\\Checkbox' => 'lib/delivery/extra_services/checkbox.php');
\Bitrix\Main\Loader::registerAutoLoadClasses('sale', $classes);
unset($classes['\\Bitrix\\Sale\\Delivery\\ExtraServices\\Store']);
static::$classes = array_keys($classes);
$event = new Event('sale', 'onSaleDeliveryExtraServicesClassNamesBuildList');
$event->send();
$resultList = $event->getResults();
if (is_array($resultList) && !empty($resultList)) {
$customClasses = array();
foreach ($resultList as $eventResult) {
/** @var EventResult $eventResult*/
if ($eventResult->getType() != EventResult::SUCCESS) {
throw new SystemException("Can't add custom tracking class successfully");
}
$params = $eventResult->getParameters();
if (!empty($params) && is_array($params)) {
$customClasses = array_merge($customClasses, $params);
}
}
if (!empty($customClasses)) {
\Bitrix\Main\Loader::registerAutoLoadClasses(null, $customClasses);
$classes = array_merge($customClasses, $classes);
}
}
static::$classes = array_merge(array_keys($classes), static::$classes);
return static::$classes;
}
开发者ID:webgksupport,项目名称:alpina,代码行数:32,代码来源:manager.php
示例4: isSuccess
public static function isSuccess(\Bitrix\Main\Event $event)
{
foreach ($event->getResults() as $result) {
if ($result->getType() === EventResult::ERROR) {
return false;
}
}
return true;
}
开发者ID:irpsv,项目名称:juggernaut.bitrix,代码行数:9,代码来源:Event.php
示例5: clearCollection
public function clearCollection()
{
/** @var Main\Entity\Event $event */
$event = new Main\Event('sale', 'OnBeforeCollectionClear', array('COLLECTION' => $this->collection));
$event->send();
/** @var CollectableEntity $item */
foreach ($this->collection as $item) {
$item->delete();
}
}
开发者ID:Satariall,项目名称:izurit,代码行数:10,代码来源:entitycollection.php
示例6: onFileRewrite
/**
* Defines if page file should be overridden
*
* @param \Bitrix\Main\Event $event Event.
* @return string|null
*/
public static function onFileRewrite(\Bitrix\Main\Event $event)
{
$path = $event->getParameter('path');
$result = null;
if ($context = Helper::getContext()) {
if ($context['section'] == 'B') {
$result = Helper::getAlternative('page', $path);
}
}
return $result;
}
开发者ID:webgksupport,项目名称:alpina,代码行数:17,代码来源:eventhandler.php
示例7: handleEvent
/**
* @param \Bitrix\Main\Event $event
* @return mixed
*/
public static function handleEvent(Event $event)
{
$eventData = $event->getParameters();
$eventData = $eventData[0];
$eventName = $eventData['EVENT_NAME'];
$fields = is_array($eventData['C_FIELDS']) ? $eventData['C_FIELDS'] : array();
if (static::isPreventable($eventName, $fields)) {
// error
$result = new EventResult(EventResult::ERROR);
} else {
// success
$result = new EventResult(EventResult::SUCCESS);
}
return $result;
}
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:19,代码来源:maileventhandler.php
示例8: getList
/**
* @return array
*/
public static function getList()
{
$resultList = array();
$event = new Event('sender', 'OnPresetMailBlockList');
$event->send();
foreach ($event->getResults() as $eventResult) {
if ($eventResult->getType() == EventResult::ERROR) {
continue;
}
$eventResultParameters = $eventResult->getParameters();
if (!empty($eventResultParameters)) {
$resultList = array_merge($resultList, $eventResultParameters);
}
}
return $resultList;
}
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:19,代码来源:mailblock.php
示例9: testUseHandlerClassParams
public function testUseHandlerClassParams()
{
$eventType = EventType::createByParams("ws.tools", "test");
$this->manager()->subscribe($eventType, $handler = new TestHandler(array('init params')));
$this->manager()->trigger($eventType, array('process params'));
$history = $handler->getHistory();
$this->assertEquals($history[0], array('identity', array('init params'), array('process params')));
$this->assertEquals($history[1], array('process', array('init params'), array('process params')));
$this->manager()->trigger($eventType, array('process2 params'));
$history = $handler->getHistory();
$this->assertEquals($history[3], array('process', array('init params'), array('process2 params')));
$e = new Event("ws.tools", "test", array('process3 params'));
$e->send($this);
$history = $handler->getHistory();
$this->assertEquals($history[5], array('process', array('init params'), array('process3 params')));
}
开发者ID:Under5,项目名称:bitrix-module-tools,代码行数:16,代码来源:eventmanagertestcase.php
示例10: __construct
/**
* @param string $eventName
* @param array $parameters
*/
public function __construct($eventName, array $parameters = array())
{
if (FormEvents::BUILD != $eventName && FormEvents::PRE_STORAGE != $eventName && FormEvents::STORAGE != $eventName) {
throw new \InvalidArgumentException('Invalid event name, see FormEvents');
}
parent::__construct(self::MODULE_ID, $eventName, $parameters);
}
开发者ID:ASDAFF,项目名称:citfact.form,代码行数:11,代码来源:Event.php
示例11: addExtensions
/**
* Добавляет расширения, в том числе расширение для битрикса,
* в котором добавляются нужные глобальные переменные и т.п.
*/
private function addExtensions()
{
$this->getEnvironment()->addExtension(new \Twig_Extension_Debug());
$this->getEnvironment()->addExtension(new BitrixExtension());
$event = new Event('wlbl.twigrix', 'onAddExtensions');
$event->send();
foreach ($event->getResults() as $result) {
if ($result->getType() == EventResult::SUCCESS) {
foreach ($result->getParameters() as $extension) {
if ($extension instanceof \Twig_Extension) {
$this->getEnvironment()->addExtension($extension);
}
}
}
}
}
开发者ID:wlbl,项目名称:twigrix,代码行数:20,代码来源:templateengine.php
示例12: __construct
protected function __construct()
{
$event = new Main\Event("main", "OnApplicationsBuildList");
$event->send();
foreach ($event->getResults() as $eventResult) {
$result = $eventResult->getParameters();
if (is_array($result)) {
if (!is_array($result[0])) {
$result = array($result);
}
foreach ($result as $app) {
$this->applications[$app["ID"]] = $app;
}
}
}
Main\Type\Collection::sortByColumn($this->applications, "SORT");
}
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:17,代码来源:applicationmanager.php
示例13: generateInitEvent
/**
* Создается событие для внесения в Twig изменения из проекта
*/
private function generateInitEvent()
{
$eventName = 'onAfterTwigTemplateEngineInited';
$event = new Event('', $eventName, array($this->engine));
$event->send();
if ($event->getResults()) {
foreach ($event->getResults() as $evenResult) {
if ($evenResult->getType() == \Bitrix\Main\EventResult::SUCCESS) {
$twig = current($evenResult->getParameters());
if (!$twig instanceof \Twig_Environment) {
throw new \LogicException("Событие '{$eventName}' должно возвращать экземпляр класса '\\Twig_Environment' при успешной отработке");
}
$this->engine = $twig;
}
}
}
}
开发者ID:maximaster,项目名称:tools.twig,代码行数:20,代码来源:TemplateEngine.php
示例14: onStartUserReplication
public function onStartUserReplication(\Bitrix\Main\Event $event)
{
$parameters = $event->getParameters();
$userId = $parameters[0];
$domain = $parameters[2];
$domainId = getNameByDomain($domain);
if (!$domainId) {
return;
}
$mapper = \Bitrix\Replica\Mapper::getInstance();
$map = $mapper->getByPrimaryValue("b_user.ID", false, $userId);
if (!$map) {
return;
}
$guid = key($map);
$event = array("operation" => "im_status_bind", "guid" => $guid);
\Bitrix\Replica\Log\Client::getInstance()->write(array($domainId), $event);
\Bitrix\Replica\Mapper::getInstance()->add("b_im_status.USER_ID", $userId, $domainId, $event["guid"]);
}
开发者ID:Satariall,项目名称:izurit,代码行数:19,代码来源:statushandler.php
示例15: onExecuteStartWriting
function onExecuteStartWriting(\Bitrix\Main\Event $event)
{
$parameters = $event->getParameters();
$userId = $parameters[0];
$dialogId = $parameters[1] . $parameters[2];
if ($userId > 0) {
if (!\Bitrix\Main\Loader::includeModule('pull')) {
return;
}
\CPushManager::DeleteFromQueueBySubTag($userId, 'IM_MESS');
if (intval($dialogId) > 0) {
\CPullStack::AddByUser($dialogId, array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)));
} elseif (substr($dialogId, 0, 4) == 'chat') {
$arRelation = \CIMChat::GetRelationById(substr($dialogId, 4));
foreach ($arRelation as $rel) {
if ($rel['USER_ID'] == $userId) {
continue;
}
\CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)));
}
}
}
}
开发者ID:Satariall,项目名称:izurit,代码行数:23,代码来源:startwritinghandler.php
示例16: save
/**
* @return Entity\AddResult|Entity\UpdateResult
* @throws ArgumentException
* @throws ArgumentNullException
* @throws \Exception
*/
public function save()
{
$id = $this->getId();
$changedFields = $this->fields->getChangedValues();
$isNew = $id <= 0;
if (!empty($changedFields)) {
/** @var array $oldEntityValues */
$oldEntityValues = $this->fields->getOriginalValues();
/** @var Event $event */
$event = new Event('sale', EventActions::EVENT_ON_BASKET_ITEM_BEFORE_SAVED, array('ENTITY' => $this, 'IS_NEW' => $isNew, 'VALUES' => $oldEntityValues));
$event->send();
if ($event->getResults()) {
$result = new Result();
/** @var EventResult $eventResult */
foreach ($event->getResults() as $eventResult) {
if ($eventResult->getType() == EventResult::ERROR) {
$errorMsg = new ResultError(Loc::getMessage('SALE_EVENT_ON_BEFORE_BASKET_ITEM_SAVED'), 'SALE_EVENT_ON_BEFORE_BASKET_ITEM_SAVED');
if (isset($eventResultData['ERROR']) && $eventResultData['ERROR'] instanceof ResultError) {
$errorMsg = $eventResultData['ERROR'];
}
$result->addError($errorMsg);
}
}
if (!$result->isSuccess()) {
return $result;
}
}
}
$fields = $this->fields->getValues();
if ($this->isBundleParent()) {
$bundleBasketCollection = $this->getBundleCollection();
}
if ($id > 0) {
$fields = $changedFields;
if (!isset($fields["ORDER_ID"]) || intval($fields["ORDER_ID"]) == 0) {
$orderId = null;
if ($this->getParentOrderId() > 0) {
$orderId = $this->getParentOrderId();
}
if ($this->isBundleChild() && $orderId === null) {
/** @var BasketItem $parentBasket */
if (!($parentBasket = $this->getParentBasketItem())) {
throw new ObjectNotFoundException('Entity parent "BasketItem" not found');
}
$orderId = $parentBasket->getParentOrderId();
}
if (intval($orderId) > 0 && $this->getField('ORDER_ID') != $orderId) {
$fields['ORDER_ID'] = $orderId;
}
}
if (!empty($fields) && is_array($fields)) {
if (isset($fields["QUANTITY"]) && floatval($fields["QUANTITY"]) == 0) {
return new Entity\UpdateResult();
}
$fields['DATE_UPDATE'] = new DateTime();
$this->setFieldNoDemand('DATE_UPDATE', $fields['DATE_UPDATE']);
$r = Internals\BasketTable::update($id, $fields);
if (!$r->isSuccess()) {
return $r;
}
}
$result = new Entity\UpdateResult();
} else {
$fields['ORDER_ID'] = $this->getParentOrderId();
$fields['DATE_INSERT'] = new DateTime();
$fields['DATE_UPDATE'] = new DateTime();
$this->setFieldNoDemand('DATE_INSERT', $fields['DATE_INSERT']);
$this->setFieldNoDemand('DATE_UPDATE', $fields['DATE_UPDATE']);
if (!$this->isBundleChild() && (!isset($fields["FUSER_ID"]) || intval($fields["FUSER_ID"]) <= 0)) {
/** @var Basket $basket */
if (!($basket = $this->getCollection())) {
throw new ObjectNotFoundException('Entity "Basket" not found');
}
$fields["FUSER_ID"] = intval($basket->getFUserId());
}
/** @var Basket $basket */
if (!($basket = $this->getCollection())) {
throw new ObjectNotFoundException('Entity "Basket" not found');
}
/** @var Order $order */
if ($order = $basket->getOrder()) {
if (!isset($fields["LID"]) || strval($fields["LID"]) == '') {
$fields['LID'] = $order->getField('LID');
}
} else {
if ($siteId = $basket->getSiteId()) {
$fields['LID'] = $siteId;
}
}
if ($this->isBundleChild()) {
if (!($parentBasketItem = $this->getParentBasketItem())) {
throw new ObjectNotFoundException('Entity parent "BasketItem" not found');
}
$fields['LID'] = $parentBasketItem->getField('LID');
//.........这里部分代码省略.........
开发者ID:andy-profi,项目名称:bxApiDocs,代码行数:101,代码来源:basketitem.php
示例17: microtime
$bCanEdit = false;
}
//need fm_lpa for every .php file, even with no php code inside
if ($bCanEdit && !$USER->CanDoOperation('edit_php') && in_array(GetFileExtension($currentFilePath), GetScriptFileExt()) && !$USER->CanDoFileOperation('fm_lpa', array(SITE_ID, $currentFilePath))) {
$bCanEdit = false;
}
if ($bCanEdit && IsModuleInstalled("fileman") && !($USER->CanDoOperation("fileman_admin_files") && $USER->CanDoOperation("fileman_edit_existent_files"))) {
$bCanEdit = false;
}
if ($bCanEdit) {
echo $APPLICATION->IncludeStringBefore();
$BX_GLOBAL_AREA_EDIT_ICON = true;
}
}
}
define("START_EXEC_PROLOG_AFTER_2", microtime());
$GLOBALS["BX_STATE"] = "WA";
$APPLICATION->RestartWorkarea(true);
//magically replacing the current file with another one
$event = new Main\Event("main", "OnFileRewrite", array("path" => Main\Context::getCurrent()->getRequest()->getScriptFile()));
$event->send();
foreach ($event->getResults() as $evenResult) {
if (($result = $evenResult->getParameters()) != '') {
$file = new Main\IO\File($_SERVER["DOCUMENT_ROOT"] . $result);
if ($file->isExists()) {
//only the first result matters
include $file->getPhysicalPath();
die;
}
}
}
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:31,代码来源:prolog_after.php
示例18: moderate
public function moderate($show)
{
if ($this->message === null) {
$this->errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_ERR_COMMENT_IS_LOST3"), self::ERROR_MESSAGE_IS_NULL));
} else {
$fields = array("APPROVED" => $show ? "Y" : "N");
if ($this->message["ID"] == $fields["APPROVED"] || ($mid = \CForumMessage::Update($this->message["ID"], $fields)) > 0) {
$this->setComment($this->message["ID"]);
/***************** Events ******************************************/
/***************** Event onMessageModerate *************************/
$event = new Event("forum", "onMessageModerate", array($this->message["ID"], $show ? "SHOW" : "HIDE", $this->message, $this->topic));
$event->send();
/***************** Events OnAfterCommentUpdate *********************/
$fields = array($this->entity->getType(), $this->entity->getId(), array("TOPIC_ID" => $this->topic["ID"], "MESSAGE_ID" => $this->message["ID"], "MESSAGE" => $this->getComment(), "ACTION" => $show ? "SHOW" : "HIDE", "PARAMS" => $fields));
$event = new Event("forum", "OnAfterCommentUpdate", $fields);
$event->send();
/***************** Events OnCommentModerate ************************/
$event = new Event("forum", "OnCommentModerate", $fields);
$event->send();
/***************** /Events *****************************************/
$res = serialize(array("ID" => $this->message["ID"], "AUTHOR_NAME" => $this->message["AUTHOR_NAME"], "POST_MESSAGE" => $this->message["POST_MESSAGE"], "TITLE" => $this->topic["TITLE"], "TOPIC_ID" => $this->topic["ID"], "FORUM_ID" => $this->topic["FORUM_ID"]));
\CForumMessage::SendMailMessage($this->message["ID"], array(), false, $show ? "NEW_FORUM_MESSAGE" : "EDIT_FORUM_MESSAGE");
\CForumEventLog::Log("message", $show ? "approve" : "unapprove", $this->message["ID"], $res);
return $this->getComment();
} else {
$text = Loc::getMessage("FORUM_CM_ERR_MODERATE");
if (($ex = $this->getApplication()->getException()) && $ex) {
$text = $ex->getString();
}
$this->errorCollection->addOne(new Error($text, self::ERROR_PARAMS_MESSAGE));
}
}
return false;
}
开发者ID:rasuldev,项目名称:torino,代码行数:34,代码来源:comment.php
示例19: save
/**
* @return Entity\AddResult|Entity\UpdateResult
* @throws Main\ArgumentOutOfRangeException
* @throws Main\ObjectNotFoundException
* @throws \Exception
*/
public function save()
{
$id = $this->getId();
$fields = $this->fields->getValues();
if ($id > 0) {
$fields = $this->fields->getChangedValues();
if (!empty($fields) && is_array($fields)) {
// $fields['DATE_UPDATE'] = new Main\Type\DateTime();
$r = Internals\ShipmentTable::update($id, $fields);
if (!$r->isSuccess()) {
return $r;
}
}
$result = new Entity\UpdateResult();
if (!empty($fields['TRACKING_NUMBER'])) {
$oldEntityValues = $this->fields->getOriginalValues();
/** @var Main\Event $event */
$event = new Main\Event('sale', EventActions::EVENT_ON_SHIPMENT_TRACKING_NUMBER_CHANGE, array('ENTITY' => $this, 'VALUES' => $oldEntityValues));
$event->send();
}
} else {
$fields['ORDER_ID'] = $this->getParentOrderId();
$fields['DATE_INSERT'] = new Main\Type\DateTime();
$fields['SYSTEM'] = $fields['SYSTEM'] ? 'Y' : 'N';
$r = Internals\ShipmentTable::add($fields);
if (!$r->isSuccess()) {
return $r;
}
$id = $r->getId();
$this->setFieldNoDemand('ID', $id);
$result = new Entity\AddResult();
/** @var ShipmentItemCollection $shipmentItemCollection */
if (!($shipmentItemCollection = $this->getShipmentItemCollection())) {
throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
}
/** @var Shipment $shipment */
if (!($shipment = $shipmentItemCollection->getShipment())) {
throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
}
/** @var ShipmentCollection $shipmentCollection */
if (!($shipmentCollection = $shipment->getCollection())) {
throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
}
/** @var Order $order */
if (!($order = $shipmentCollection->getOrder())) {
throw new Main\ObjectNotFoundException('Entity "Order" not found');
}
if ($order->getId() > 0 && !$this->isSystem()) {
OrderHistory::addAction('SHIPMENT', $order->getId(), 'SHIPMENT_ADDED', $id, $this);
}
}
if ($result->isSuccess() && !$this->isSystem()) {
$this->saveExtraServices();
$this->saveStoreId();
}
/** @var ShipmentItemCollection $shipmentItemCollection */
if (!($shipmentItemCollection = $this->getShipmentItemCollection())) {
throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
}
$r = $shipmentItemCollection->save();
if (!$r->isSuccess()) {
$result->addErrors($r->getErrors());
}
if ($result->isSuccess()) {
/** @var Shipment $shipment */
if (!($shipment = $shipmentItemCollection->getShipment())) {
throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
}
/** @var ShipmentCollection $shipmentCollection */
if (!($shipmentCollection = $shipment->getCollection())) {
throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
}
/** @var Order $order */
if (!($order = $shipmentCollection->getOrder())) {
throw new Main\ObjectNotFoundException('Entity "Order" not found');
}
if (!$this->isSystem()) {
OrderHistory::collectEntityFields('SHIPMENT', $order->getId(), $id);
}
}
return $result;
}
开发者ID:andy-profi,项目名称:bxApiDocs,代码行数:88,代码来源:shipment.php
示例20: send
/**
* @param $id
* @param int $timeout
* @param int $maxMailCount
* @return bool|string
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\DB\Exception
* @throws \Bitrix\Main\Db\SqlQueryException
* @throws \Exception
*/
public static function send($id, $timeout = 0, $maxMailCount = 0)
{
$start_time = getmicrotime();
@set_time_limit(0);
static::$emailSentPerIteration = 0;
$postingDb = PostingTable::getList(array('select' => array('ID', 'STATUS', 'MAILING_ID', 'MAILING_CHAIN_ID', 'MAILING_CHAIN_REITERATE' => 'MAILING_CHAIN.REITERATE', 'MAILING_CHAIN_IS_TRIGGER' => 'MAILING_CHAIN.IS_TRIGGER'), 'filter' => array('ID' => $id, 'MAILING.ACTIVE' => 'Y', 'MAILING_CHAIN.STATUS' => MailingChainTable::STATUS_SEND)));
$postingData = $postingDb->fetch();
// posting not found
if (!$postingData) {
return static::SEND_RESULT_ERROR;
}
// if posting in new status, then import recipients from groups and set right status for sending
$isInitGroupRecipients = false;
$isChangeStatusToPart = false;
if ($postingData["STATUS"] == PostingTable::STATUS_NEW) {
$isInitGroupRecipients = true;
$isChangeStatusToPart = true;
}
if ($postingData["STATUS"] != PostingTable::STATUS_PART && $postingData["MAILING_CHAIN_IS_TRIGGER"] == 'Y') {
$isInitGroupRecipients = false;
$isChangeStatusToPart = true;
}
if ($isInitGroupRecipients) {
PostingTable::initGroupRecipients($postingData['ID']);
}
if ($isChangeStatusToPart) {
PostingTable::update(array('ID' => $postingData['ID']), array('STATUS' => PostingTable::STATUS_PART));
$postingData["STATUS"] = PostingTable::STATUS_PART;
}
// posting not in right status
if ($postingData["STATUS"] != PostingTable::STATUS_PART) {
return static::SEND_RESULT_ERROR;
}
// lock posting for exclude double parallel sending
if (static::lockPosting($id) === false) {
throw new \Bitrix\Main\DB\Exception(Loc::getMessage('SENDER_POSTING_MANAGER_ERR_LOCK'));
}
// select all recipients of posting, only not processed
$recipientDataDb = PostingRecipientTable::getList(array('filter' => array('POSTING_ID' => $postingData['ID'], 'STATUS' => PostingRecipientTable::SEND_RESULT_NONE), 'limit' => $maxMailCount));
while ($recipientData = $recipientDataDb->fetch()) {
// create name from email
$recipientEmail = $recipientData["EMAIL"];
if (empty($recipientData["NAME"])) {
$recipientEmailParts = explode('@', $recipientEmail);
$recipientName = $recipientEmailParts[0];
} else {
$recipientName = $recipientData["NAME"];
}
// prepare params for send
$sendParams = array('FIELDS' => array('EMAIL_TO' => $recipientEmail, 'NAME' => $recipientName, 'USER_ID' => $recipientData["USER_ID"], 'SENDER_CHAIN_CODE' => 'sender_chain_item_' . $postingData["MAILING_CHAIN_ID"], 'UNSUBSCRIBE_LINK' => Subscription::getLinkUnsub(array('MAILING_ID' => $postingData['MAILING_ID'], 'EMAIL' => $recipientEmail, 'RECIPIENT_ID' => $recipientData["ID"]))), 'TRACK_READ' => array('MODULE_ID' => "sender", 'FIELDS' => array('RECIPIENT_ID' => $recipientData["ID"])), 'TRACK_CLICK' => array('MODULE_ID' => "sender", 'FIELDS' => array('RECIPIENT_ID' => $recipientData["ID"]), 'URL_PARAMS' => array('bx_sender_conversion_id' => $recipientData["ID"])));
if (is_array($recipientData['FIELDS']) && count($recipientData) > 0) {
$sendParams['FIELDS'] = $sendParams['FIELDS'] + $recipientData['FIELDS'];
}
// set sending result to recipient
$mailSendResult = static::sendInternal($postingData['MAILING_CHAIN_ID'], $sendParams);
PostingRecipientTable::update(array('ID' => $recipientData["ID"]), array('STATUS' => $mailSendResult, 'DATE_SENT' => new Type\DateTime()));
// send event
$eventData = array('SEND_RESULT' => $mailSendResult == PostingRecipientTable::SEND_RESULT_SUCCESS, 'RECIPIENT' => $recipientData, 'POSTING' => $postingData);
$event = new Event('sender', 'OnAfterPostingSendRecipient', array($eventData));
$event->send();
// limit executing script by time
if ($timeout > 0 && getmicrotime() - $start_time >= $timeout) {
break;
}
// increment sending statistic
static::$emailSentPerIteration++;
}
//set status and delivered and error emails
$statusList = PostingTable::getRecipientCountByStatus($id);
if (!array_key_exists(PostingRecipientTable::SEND_RESULT_NONE, $statusList)) {
if (array_key_exists(PostingRecipientTable::SEND_RESULT_ERROR, $statusList)) {
$STATUS = PostingTable::STATUS_SENT_WITH_ERRORS;
} else {
$STATUS = PostingTable::STATUS_SENT;
}
$DATE = new Type\DateTime();
} else {
$STATUS = PostingTable::STATUS_PART;
$DATE = null;
}
// unlock posting for exclude double parallel sending
static::unlockPosting($id);
// update status of posting
PostingTable::update(array('ID' => $id), array('STATUS' => $STATUS, 'DATE_SENT' => $DATE));
// return status to continue or end of sending
if ($STATUS == PostingTable::STATUS_PART) {
return static::SEND_RESULT_CONTINUE;
} else {
return static::SEND_RESULT_SENT;
}
//.........这里部分代码省略.........
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:101,代码来源:postingmanager.php
注:本文中的Bitrix\Main\Event类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论