public function filter()
 {
     \Bitrix\Main\Loader::includeModule('sale');
     $daysBasketForgotten = $this->getFieldValue('DAYS_BASKET_FORGOTTEN');
     if (!is_numeric($daysBasketForgotten)) {
         $daysBasketForgotten = 90;
     }
     $dateFrom = new \Bitrix\Main\Type\DateTime();
     $dateTo = new \Bitrix\Main\Type\DateTime();
     $dateFrom->setTime(0, 0, 0)->add('-' . $daysBasketForgotten . ' days');
     $dateTo->setTime(0, 0, 0)->add('1 days')->add('-' . $daysBasketForgotten . ' days');
     if ($this->isRunForOldData()) {
         $filter = array('<MIN_DATE_INSERT' => $dateTo->format(\Bitrix\Main\UserFieldTable::MULTIPLE_DATETIME_FORMAT));
     } else {
         $filter = array('>MIN_DATE_INSERT' => $dateFrom->format(\Bitrix\Main\UserFieldTable::MULTIPLE_DATETIME_FORMAT), '<MIN_DATE_INSERT' => $dateTo->format(\Bitrix\Main\UserFieldTable::MULTIPLE_DATETIME_FORMAT));
     }
     $filter = $filter + array('!FUSER.USER_ID' => null, '=ORDER_ID' => null, '=LID' => $this->getSiteId());
     $userListDb = \Bitrix\Sale\BasketTable::getList(array('select' => array('USER_ID' => 'FUSER.USER_ID', 'EMAIL' => 'FUSER.USER.EMAIL', 'FUSER_USER_NAME' => 'FUSER.USER.NAME'), 'filter' => $filter, 'runtime' => array(new \Bitrix\Main\Entity\ExpressionField('MIN_DATE_INSERT', 'MIN(%s)', 'DATE_INSERT')), 'order' => array('USER_ID' => 'ASC')));
     if ($userListDb->getSelectedRowsCount() > 0) {
         $userListDb->addFetchDataModifier(array($this, 'getFetchDataModifier'));
         $this->recipient = $userListDb;
         return true;
     } else {
         return false;
     }
 }
예제 #2
0
 public function filter()
 {
     $daysDontAuth = $this->getFieldValue('DAYS_DONT_AUTH');
     if (!is_numeric($daysDontAuth)) {
         $daysDontAuth = 90;
     }
     $dateFrom = new \Bitrix\Main\Type\DateTime();
     $dateTo = new \Bitrix\Main\Type\DateTime();
     $dateFrom->setTime(0, 0, 0)->add('-' . $daysDontAuth . ' days');
     $dateTo->setTime(0, 0, 0)->add('1 days')->add('-' . $daysDontAuth . ' days');
     if ($this->isRunForOldData()) {
         $filter = array('!LAST_LOGIN' => null, '<LAST_LOGIN' => $dateTo);
     } else {
         $filter = array('>LAST_LOGIN' => $dateFrom, '<LAST_LOGIN' => $dateTo);
     }
     $filter['=ACTIVE'] = true;
     $userListDb = \Bitrix\Main\UserTable::getList(array('select' => array('EMAIL', 'ID', 'NAME'), 'filter' => $filter, 'order' => array('ID' => 'ASC')));
     if ($userListDb->getSelectedRowsCount() > 0) {
         $userListDb->addFetchDataModifier(array($this, 'getFetchDataModifier'));
         $this->recipient = $userListDb;
         return true;
     } else {
         return false;
     }
 }
예제 #3
0
 public static function Delete($ID, $checkPerms = true, $regEvent = true, $options = array())
 {
     $ID = intval($ID);
     if (!is_array($options)) {
         $options = array();
     }
     $events = GetModuleEvents('crm', 'OnBeforeActivityDelete');
     while ($event = $events->Fetch()) {
         if (ExecuteModuleEventEx($event, array($ID)) === false) {
             return false;
         }
     }
     $ary = isset($options['ACTUAL_ITEM']) && is_array($options['ACTUAL_ITEM']) ? $options['ACTUAL_ITEM'] : self::GetByID($ID, $checkPerms);
     if (!is_array($ary)) {
         return false;
         //is not found
     }
     $arBindings = isset($options['ACTUAL_BINDINGS']) && is_array($options['ACTUAL_BINDINGS']) ? $options['ACTUAL_BINDINGS'] : self::GetBindings($ID);
     if (!self::InnerDelete($ID, $options)) {
         return false;
     }
     self::UnregisterLiveFeedEvent($ID);
     CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Activity, $ID);
     // Synchronize user activity -->
     $skipUserActivitySync = isset($options['SKIP_USER_ACTIVITY_SYNC']) ? $options['SKIP_USER_ACTIVITY_SYNC'] : false;
     if (!$skipUserActivitySync) {
         $responsibleID = isset($ary['RESPONSIBLE_ID']) ? intval($ary['RESPONSIBLE_ID']) : 0;
         if ($responsibleID > 0 && is_array($arBindings)) {
             foreach ($arBindings as &$arBinding) {
                 self::SynchronizeUserActivity($arBinding['OWNER_TYPE_ID'], $arBinding['OWNER_ID'], $responsibleID);
                 self::SynchronizeUserActivity($arBinding['OWNER_TYPE_ID'], $arBinding['OWNER_ID'], 0);
             }
             unset($arBinding);
         }
     }
     // <-- Synchronize user activity
     if (is_array($arBindings)) {
         if ($regEvent) {
             foreach ($arBindings as &$arBinding) {
                 self::RegisterRemoveEvent($arBinding['OWNER_TYPE_ID'], $arBinding['OWNER_ID'], $ary, $checkPerms);
             }
             unset($arBinding);
         }
         $skipStatistics = isset($options['SKIP_STATISTICS']) ? $options['SKIP_STATISTICS'] : false;
         if (!$skipStatistics) {
             $completed = isset($ary['COMPLETED']) && $ary['COMPLETED'] === 'Y';
             $deadline = isset($ary['DEADLINE']) ? $ary['DEADLINE'] : '';
             if ($completed && $deadline) {
                 $deadline = new \Bitrix\Main\Type\DateTime($deadline);
                 $deadline->setTime(0, 0, 0);
                 foreach ($arBindings as &$arBinding) {
                     $curOwnerTypeID = isset($arBinding['OWNER_TYPE_ID']) ? intval($arBinding['OWNER_TYPE_ID']) : 0;
                     $curOwnerID = isset($arBinding['OWNER_ID']) ? intval($arBinding['OWNER_ID']) : 0;
                     if ($curOwnerTypeID === CCrmOwnerType::Deal && $curOwnerID > 0) {
                         Bitrix\Crm\Statistics\DealActivityStatisticEntry::register($curOwnerID, null, array('DATE' => $deadline));
                     }
                 }
                 unset($arBinding);
             }
         }
     }
     $skipAssocEntity = isset($options['SKIP_ASSOCIATED_ENTITY']) ? (bool) $options['SKIP_ASSOCIATED_ENTITY'] : false;
     if (!$skipAssocEntity && isset($ary['TYPE_ID']) && isset($ary['ASSOCIATED_ENTITY_ID'])) {
         switch (intval($ary['TYPE_ID'])) {
             case CCrmActivityType::Call:
             case CCrmActivityType::Meeting:
                 self::DeleteCalendarEvent($ary);
                 break;
             case CCrmActivityType::Task:
                 self::DeleteTask($ary);
                 break;
             case CCrmActivityType::Email:
                 //do nothing
                 break;
         }
     }
     $rsEvents = GetModuleEvents('crm', 'OnActivityDelete');
     while ($arEvent = $rsEvents->Fetch()) {
         ExecuteModuleEventEx($arEvent, array($ID));
     }
     if (defined("BX_COMP_MANAGED_CACHE")) {
         $GLOBALS["CACHE_MANAGER"]->ClearByTag("CRM_ACTIVITY_" . $ID);
     }
     return true;
 }
예제 #4
0
 public static function actualizeHandlers($chainId, array $fieldsNew = null, array $fieldsOld = null)
 {
     $settingsNew = null;
     $settingsOld = null;
     if ($fieldsNew) {
         $settingsNew = new TriggerSettings($fieldsNew);
     }
     if ($fieldsOld) {
         $settingsOld = new TriggerSettings($fieldsOld);
     }
     // if old item was closed trigger
     if ($settingsOld && $settingsOld->isClosedTrigger()) {
         // delete agent
         $agentName = TriggerManager::getClosedEventAgentName($settingsOld->getEventModuleId(), $settingsOld->getEventType(), $chainId);
         $agent = new \CAgent();
         $agentListDb = $agent->GetList(array(), array('MODULE_ID' => 'sender', 'NAME' => $agentName));
         while ($agentItem = $agentListDb->Fetch()) {
             $agent->Delete($agentItem['ID']);
         }
     }
     // if new item is closed trigger
     if ($settingsNew && $settingsNew->isClosedTrigger()) {
         // check active state of mailing
         $chainDb = MailingChainTable::getList(array('select' => array('ID'), 'filter' => array('=ID' => $chainId, '=MAILING.ACTIVE' => 'Y')));
         if (!$chainDb->fetch()) {
             return;
         }
         // add new agent
         $agentName = TriggerManager::getClosedEventAgentName($settingsNew->getEventModuleId(), $settingsNew->getEventType(), $chainId);
         // set date of next exec
         $agentTime = $settingsNew->getClosedTriggerTime();
         $agentInterval = $settingsNew->getClosedTriggerInterval();
         if ($agentInterval <= 0) {
             $agentInterval = 1440;
         }
         $agentTimeArray = explode(":", $agentTime);
         $agentDate = new \Bitrix\Main\Type\DateTime();
         $agentDate->setTime((int) $agentTimeArray[0], (int) $agentTimeArray[1]);
         // set next exec on next day if exec was today
         if ($agentDate->getTimestamp() < time()) {
             $agentDate->add("1 days");
         }
         // add agent
         $agent = new \CAgent();
         $agent->AddAgent($agentName, 'sender', 'N', $agentInterval * 60, '', 'Y', $agentDate->toString());
         return;
     }
     // actualize deleted/changed event
     if ($settingsOld && !$settingsOld->isClosedTrigger() && $settingsOld->getFullEventType()) {
         // if delete operation(no the NEW)
         // or change operation(the NEW is not equal to the OLD)
         if (!$settingsNew || $settingsOld->getFullEventType() != $settingsNew->getFullEventType()) {
             TriggerManager::actualizeHandler(array('MODULE_ID' => $settingsOld->getEventModuleId(), 'EVENT_TYPE' => $settingsOld->getEventType(), 'CALLED_BEFORE_CHANGE' => true));
         }
     }
     // actualize new event
     if ($settingsNew && $settingsNew->getFullEventType()) {
         $calledBeforeChange = $fieldsOld ? false : true;
         TriggerManager::actualizeHandler(array('MODULE_ID' => $settingsNew->getEventModuleId(), 'EVENT_TYPE' => $settingsNew->getEventType(), 'CALLED_BEFORE_CHANGE' => $calledBeforeChange));
     }
 }