public static function SetIdle($userId, $result) { $date = null; if ($result) { $date = new Bitrix\Main\Type\DateTime(); $date->add('-10 MINUTE'); } CIMStatus::Set($userId, array('IDLE' => $date)); }
public static function SetIdle($userId, $result = true, $min = 10) { $date = null; $min = intval($min); if ($result && $min > 0) { $date = new Bitrix\Main\Type\DateTime(); $date->add('-' . $min . ' MINUTE'); } CIMStatus::Set($userId, array('IDLE' => $date)); }
/** * The agent function. Moves reserved quantity back to the quantity field for each product * for orders which were placed earlier than specific date * * @return agent name string */ public static function ClearProductReservedQuantity() { global $DB, $USER; if (!is_object($USER)) { $USER = new CUser(); } $days_ago = (int) COption::GetOptionString("sale", "product_reserve_clear_period"); if ($days_ago > 0) { $shipmentList = array(); $date = new \Bitrix\Main\Type\DateTime(); $filter = array('filter' => array("<=DATE_INSERT" => $date->add('-' . $days_ago . ' day'), "=SHIPMENT.RESERVED" => "Y", "=SHIPMENT.DEDUCTED" => "N", "=SHIPMENT.MARKED" => "N", "=SHIPMENT.ALLOW_DELIVERY" => "N", "=PAYED" => "N", "=CANCELED" => "N"), 'select' => array("ID", "SHIPMENT_ID" => "SHIPMENT.ID", "SHIPMENT_RESERVED" => "SHIPMENT.RESERVED", "SHIPMENT_DEDUCTED" => "SHIPMENT.DEDUCTED", "DATE_INSERT", "PAYED", "CANCELED", "MARKED")); $res = \Bitrix\Sale\Internals\OrderTable::getList($filter); while ($data = $res->fetch()) { if (!array_key_exists($data['ID'], $shipmentList)) { $shipmentList[$data['ID']] = array(); } if (in_array($data['SHIPMENT_ID'], $shipmentList[$data['ID']])) { continue; } $shipmentList[$data['ID']][] = $data['SHIPMENT_ID']; } if (!empty($shipmentList)) { foreach ($shipmentList as $orderId => $shipmentData) { /** @var Sale\Order $order */ $order = Sale\Order::load($orderId); $orderSaved = false; $errors = array(); try { /** @var Sale\ShipmentCollection $shipmentCollection */ if ($shipmentCollection = $order->getShipmentCollection()) { foreach ($shipmentData as $shipmentId) { /** @var Sale\Shipment $shipment */ if ($shipment = $shipmentCollection->getItemById($shipmentId)) { $r = $shipment->tryUnreserve(); if (!$r->isSuccess()) { if (!$shipment->isMarked()) { $shipment->setField('MARKED', 'Y'); if (is_array($r->getErrorMessages())) { $oldErrorText = $shipment->getField('REASON_MARKED'); foreach ($r->getErrorMessages() as $error) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error; } $shipment->setField('REASON_MARKED', $oldErrorText); } } } } } } $r = $order->save(); if ($r->isSuccess()) { $orderSaved = true; } else { $errors = $r->getErrorMessages(); } } catch (Exception $e) { $errors[] = $e->getMessage(); } if (!$orderSaved) { if (!empty($errors)) { $oldErrorText = $order->getField('REASON_MARKED'); foreach ($errors as $error) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error; } Sale\Internals\OrderTable::update($order->getId(), array("MARKED" => "Y", "REASON_MARKED" => $oldErrorText)); } } } } } return "CSaleOrder::ClearProductReservedQuantity();"; }
public static function RemoveTmpFileAgent() { $storageModel = self::GetStorage(); if (!$storageModel) { return "CIMDisk::RemoveTmpFileAgent();"; } $date = new \Bitrix\Main\Type\DateTime(); $date->add('YESTERDAY'); $fileModels = \Bitrix\Disk\File::getModelList(array('filter' => array('GLOBAL_CONTENT_VERSION' => 1, 'STORAGE_ID' => $storageModel->getId(), '<CREATE_TIME' => $date), 'limit' => 200)); foreach ($fileModels as $fileModel) { $fileModel->delete(\Bitrix\Disk\SystemUser::SYSTEM_USER_ID); } return "CIMDisk::RemoveTmpFileAgent();"; }
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)); } }
public static function CheckNumberForBlackList($number) { $blackListTime = Bitrix\Main\Config\Option::get("voximplant", "blacklist_time", 5); $blackListCount = Bitrix\Main\Config\Option::get("voximplant", "blacklist_count", 5); $minTime = new Bitrix\Main\Type\DateTime(); $minTime->add('-' . $blackListTime . ' minutes'); $dbData = VI\StatisticTable::getList(array('filter' => array("PHONE_NUMBER" => $number, '>CALL_START_DATE' => $minTime), 'select' => array('ID'))); $callsCount = 0; while ($dbData->fetch()) { $callsCount++; if ($callsCount >= $blackListCount) { $number = substr($number, 0, 20); VI\BlacklistTable::add(array("PHONE_NUMBER" => $number)); $messageUserId = Bitrix\Main\Config\Option::get("voximplant", "blacklist_user_id", ""); CVoxImplantHistory::SendMessageToChat($messageUserId, $number, CVoxImplantMain::CALL_INCOMING, GetMessage("BLACKLIST_NUMBER")); return true; } } return false; }
if ($siteCapacity['daily'] > 0) { $rem = $abtest['MIN_AMOUNT'] - min($testCapacity); $est = $rem > 0 ? $rem / ($siteCapacity['daily'] / 2) : 0; $estDays = ceil(100 * $est / $abtest['PORTION']); } } $end_date = null; if ($abtest['ACTIVE'] == 'Y' && $abtest['DURATION'] != 0) { if ($abtest['DURATION'] > 0) { $end = clone $abtest['START_DATE']; $end->add(intval($abtest['DURATION']) . ' days'); $end_date = $end->format(Bitrix\Main\Type\Date::convertFormatToPhp($arLang['FORMAT_DATE'])); } else { if (isset($estDays)) { $end = new Bitrix\Main\Type\DateTime(); $end->add($estDays . ' days'); $end_date = $end->format(Bitrix\Main\Type\Date::convertFormatToPhp($arLang['FORMAT_DATE'])); } else { $end_date = getMessage('ABTEST_DURATION_NA'); } } } function pvalue($p1, $p2, $n1, $n2) { $dx = array(1.0, 0.049867347, 0.0211410061, 0.0032776263, 3.80036E-5, 4.88906E-5, 5.383E-6); $stdError = sqrt($p1 * (1 - $p1) / $n1 + $p2 * (1 - $p2) / $n2); $zval = abs($p2 - $p1) / $stdError; for ($pval = 0, $i = 6; $i >= 0; $i--) { $pval = $pval * $zval + $dx[$i]; } $pval = pow($pval, -16);
if ($abtest['ACTIVE'] == 'Y') { $start_date = $abtest['START_DATE']->format(Bitrix\Main\Type\Date::convertFormatToPhp($arLang['FORMAT_DATE'])); $end_date = null; if ($abtest['DURATION'] != 0) { if ($abtest['DURATION'] > 0) { $end = clone $abtest['START_DATE']; $end->add(intval($abtest['DURATION']) . ' days'); $end_date = $end->format(Bitrix\Main\Type\Date::convertFormatToPhp($arLang['FORMAT_DATE'])); } else { $siteCapacity = Bitrix\ABTest\AdminHelper::getSiteCapacity($abtest['SITE_ID']); $testCapacity = Bitrix\ABTest\AdminHelper::getTestCapacity($abtest['ID']); if ($abtest['MIN_AMOUNT'] > 0 && $abtest['PORTION'] > 0 && $siteCapacity['daily'] > 0) { $rem = $abtest['MIN_AMOUNT'] - min($testCapacity); $est = $rem > 0 ? $rem / ($siteCapacity['daily'] / 2) : 0; $end = new Bitrix\Main\Type\DateTime(); $end->add(ceil(100 * $est / $abtest['PORTION']) . ' days'); $end_date = $end->format(Bitrix\Main\Type\Date::convertFormatToPhp($arLang['FORMAT_DATE'])); } else { $end_date = getMessage('ABTEST_DURATION_NA'); } } } $user_name = CUser::formatName(CSite::getNameFormat(), array('TITLE' => $abtest['USER_TITLE'], 'NAME' => $abtest['USER_NAME'], 'SECOND_NAME' => $abtest['USER_SECOND_NAME'], 'LAST_NAME' => $abtest['USER_LAST_NAME'], 'LOGIN' => $abtest['USER_LOGIN']), true, true); $status = '<table style="width: 100%; border-spacing: 0px; "><tr>'; $status .= '<td style="width: 1px; padding: 0px; vertical-align: top; "><img src="/bitrix/images/abtest/ab-test-on.gif"></td>'; $status .= '<td style="padding: 0px 10px; vertical-align: top; ">'; $status .= '<span style="white-space: nowrap; color: #729e00; font-weight: bold; ">' . getMessage('ABTEST_STATE_STARTED') . '</span><br>'; $status .= '<span style="white-space: nowrap; ">' . getMessage('ABTEST_START_DATE') . ': ' . $start_date . '</span><br>'; if ($end_date) { $status .= '<span style="white-space: nowrap; ">' . getMessage('ABTEST_STOP_DATE2') . ': ' . $end_date . '</span><br>'; }
public static function EnqueueDeactivatePhoneNumber($number) { $result = VI\ConfigTable::getList(array('select' => array('ID'), 'filter' => array('=SEARCH_ID' => (string) $number))); $config = $result->fetch(); if (!$config) { return false; } $viHttp = new CVoxImplantHttp(); $result = $viHttp->DeactivatePhoneNumber($number); if (!$result) { return false; } $date = new Bitrix\Main\Type\DateTime(); $date->add('23 HOUR'); VI\ConfigTable::update($config['ID'], array('TO_DELETE' => 'Y', 'DATE_DELETE' => $date)); CAgent::AddAgent("CVoxImplantPhone::CheckDeleteAgent(" . $config['ID'] . ");", "voximplant", "N", 82810, "", "Y", $date); return $result; }