public static function getList($userId, $taskId, array $parameters = array()) { $data = array(); $task = static::getTask($userId, $taskId); if ($task !== null && $task->checkCanRead()) { $res = \CTaskLog::GetList(array('CREATED_DATE' => 'DESC'), array('TASK_ID' => $taskId)); $tzDisabled = !\CTimeZone::enabled(); if ($tzDisabled) { \CTimeZone::enable(); } $tzOffset = \CTimeZone::getOffset(); if ($tzDisabled) { \CTimeZone::disable(); } while (true) { if ($parameters['ESCAPE_DATA']) { $item = $res->GetNext(); } else { $item = $res->fetch(); } if (!$item) { break; } // Adjust unix timestamps to "bitrix timestamps" if (isset(\CTaskLog::$arComparedFields[$item['FIELD']]) && \CTaskLog::$arComparedFields[$item['FIELD']] === 'date') { $item['TO_VALUE'] = $item['TO_VALUE'] + $tzOffset; $item['FROM_VALUE'] = $item['FROM_VALUE'] + $tzOffset; } $data[] = $item; } } return array('DATA' => $data, 'CAN' => array()); }
/** * Returns product data. * * @param array &$productData Product data. * @param array $entityData Entity data. * @param array $iblockData Iblock list data. * @return void */ protected static function getProductData(&$productData, $entityData, $iblockData) { if (!empty($iblockData['iblockElement'])) { $productList = array_keys($productData); if (!empty($entityData['iblockFields'])) { $elementIterator = Iblock\ElementTable::getList(array('select' => array_merge(array('ID'), array_keys($entityData['iblockFields'])), 'filter' => array('@ID' => $productList))); while ($element = $elementIterator->fetch()) { $element['ID'] = (int) $element['ID']; $fields = array(); foreach ($entityData['iblockFields'] as $key => $alias) { $fields[$alias] = $element[$key]; } unset($key, $alias); $productData[$element['ID']] = empty($productData[$element['ID']]) ? $fields : array_merge($productData[$element['ID']], $fields); unset($fields); } } if ($entityData['sections']) { $productSection = array_fill_keys($productList, array()); $elementSectionIterator = Iblock\SectionElementTable::getList(array('select' => array('*'), 'filter' => array('@IBLOCK_ELEMENT_ID' => $productList))); while ($elementSection = $elementSectionIterator->fetch()) { $elementSection['IBLOCK_ELEMENT_ID'] = (int) $elementSection['IBLOCK_ELEMENT_ID']; $elementSection['IBLOCK_SECTION_ID'] = (int) $elementSection['IBLOCK_SECTION_ID']; $elementSection['ADDITIONAL_PROPERTY_ID'] = (int) $elementSection['ADDITIONAL_PROPERTY_ID']; if ($elementSection['ADDITIONAL_PROPERTY_ID'] > 0) { continue; } $productSection[$elementSection['IBLOCK_ELEMENT_ID']][$elementSection['IBLOCK_SECTION_ID']] = true; $parentSectionIterator = \CIBlockSection::getNavChain(0, $elementSection['IBLOCK_SECTION_ID'], array('ID')); while ($parentSection = $parentSectionIterator->fetch()) { $parentSection['ID'] = (int) $parentSection['ID']; $productSection[$elementSection['IBLOCK_ELEMENT_ID']][$parentSection['ID']] = true; } unset($parentSection, $parentSectionIterator); } unset($elementSection, $elementSectionIterator); foreach ($productSection as $element => $sections) { $productData[$element]['SECTION_ID'] = array_keys($sections); } unset($element, $sections, $productSection); } if (!empty($entityData['needProperties'])) { $propertyValues = array_fill_keys($productList, array()); foreach ($entityData['needProperties'] as $iblock => $propertyList) { if (empty($iblockData['iblockElement'][$iblock])) { continue; } $filter = array('ID' => $iblockData['iblockElement'][$iblock], 'IBLOCK_ID' => $iblock); \CTimeZone::disable(); \CIBlockElement::getPropertyValuesArray($propertyValues, $iblock, $filter, array('ID' => $propertyList)); \CTimeZone::enable(); } unset($filter, $iblock, $propertyList); self::convertProperties($productData, $propertyValues, $entityData, $iblockData); } if (!empty($entityData['catalogFields'])) { $productIterator = Catalog\ProductTable::getList(array('select' => array_merge(array('ID'), array_keys($entityData['catalogFields'])), 'filter' => array('@ID' => $productList))); while ($product = $productIterator->fetch()) { $product['ID'] = (int) $product['ID']; $fields = array(); foreach ($entityData['catalogFields'] as $key => $alias) { $fields[$alias] = $product[$key]; } unset($key, $alias); $productData[$product['ID']] = empty($productData[$product['ID']]) ? $fields : array_merge($productData[$product['ID']], $fields); unset($fields); } unset($product, $productIterator); } if (!empty($iblockData['skuIblockList'])) { self::getParentProducts($productData, $entityData, $iblockData); } } }
private static function convertDateStringToTimestamp($operation, $value) { switch ($operation) { case self::OP_DATE_TODAY: case self::OP_DATE_YESTERDAY: case self::OP_DATE_TOMORROW: case self::OP_DATE_CUR_WEEK: case self::OP_DATE_PREV_WEEK: case self::OP_DATE_NEXT_WEEK: case self::OP_DATE_CUR_MONTH: case self::OP_DATE_PREV_MONTH: case self::OP_DATE_NEXT_MONTH: $value = ''; break; case self::OP_DATE_LAST_DAYS: case self::OP_DATE_NEXT_DAYS: $value = (int) $value; break; default: case self::OP_EQUAL: case self::OP_NOT_EQUAL: case self::OP_STRICTLY_LESS: case self::OP_STRICTLY_GREATER: case self::OP_LESS_OR_EQUAL: case self::OP_GREATER_OR_EQUAL: $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } // get correct UnixTimestamp $value = (int) MakeTimeStamp($value) - CTimeZone::getOffset(); if ($bTzWasDisabled) { CTimeZone::disable(); } break; } return $value; }
function tasksFormatDate($in_date) { $date = $in_date; $strDate = false; if (!is_int($in_date)) { $date = MakeTimeStamp($in_date); } if ($date === false || $date === -1 || $date === 0) { $date = MakeTimeStamp($in_date); } // It can be other date on server (relative to client), ... $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } $ts = time() + CTimeZone::getOffset(); // ... so shift cur timestamp to compensate it. if ($bTzWasDisabled) { CTimeZone::disable(); } $curDateStrAtClient = date('d.m.Y', $ts); $yesterdayDateStrAtClient = date('d.m.Y', strtotime('-1 day', $ts)); if ($curDateStrAtClient === date('d.m.Y', $date)) { $strDate = FormatDate("today", $date); } elseif ($yesterdayDateStrAtClient === date('d.m.Y', $date)) { $strDate = FormatDate("yesterday", $date); } else { if (defined('FORMAT_DATE')) { $strDate = FormatDate(CDatabase::DateFormatToPHP(FORMAT_DATE), $date); } else { $strDate = FormatDate("d.m.Y", $date); } } return $strDate; }
$arResult['LEARNING_GROUP_ACTIVE_FROM'] = $arGroupsPeriods['ACTIVE_FROM']; $arResult['LEARNING_GROUP_ACTIVE_TO'] = $arGroupsPeriods['ACTIVE_TO']; $activeFromMap = CLearnAccessMacroses::getActiveLearningChaptersPeriod($courseLessonId, $USER->getId()); if ($activeFromMap !== false) { $arResult['LEARNING_GROUP_CHAPTERS_ACTIVE_FROM'] = $activeFromMap; } $oPath = new CLearnPath(); $oPath->ImportUrlencoded($arParams['LESSON_PATH']); $arPath = $oPath->GetPathAsArray(); if (count($arPath) >= 2) { $secondLevelLesson = $arPath[1]; if (isset($arResult['LEARNING_GROUP_CHAPTERS_ACTIVE_FROM'][$secondLevelLesson])) { $activeFrom = $arResult['LEARNING_GROUP_CHAPTERS_ACTIVE_FROM'][$secondLevelLesson]; $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } $tzOffset = CTimeZone::getOffset(); if ($bTzWasDisabled) { CTimeZone::disable(); } // Adjust unix timestamp to bitrix-timestamp for correct comparision below $nowTimestamp = time() + $tzOffset; if ($nowTimestamp < MakeTimeStamp($activeFrom)) { $delayed = $activeFrom; } } } } } $lastDirtyCacheTS = COption::GetOptionString('learning', CLearnCacheOfLessonTreeComponent::OPTION_TS, time());
public static function UnifyFields(&$value, $key) { if (array_key_exists($key, self::$arComparedFields)) { switch (self::$arComparedFields[$key]) { case "integer": $value = intval($value); break; case "string": $value = trim($value); break; case "array": if (!is_array($value)) { $value = explode(",", $value); } $value = array_unique(array_filter(array_map("trim", $value))); sort($value); break; case "date": $value = MakeTimeStamp($value); if (!$value) { $value = strtotime($value); // There is correct Unix timestamp in return value // CTimeZone::getOffset() substraction here??? } else { // It can be other date on server (relative to client), ... $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } $value -= CTimeZone::getOffset(); // get correct UnixTimestamp if ($bTzWasDisabled) { CTimeZone::disable(); } // We mustn't store result of MakeTimestamp() in DB, // because it is shifted for time zone offset already, // which can't be restored. } break; case "bool": if ($value != "Y") { $value = "N"; } break; } } }
private static function getSqlForTimestamps($key, $val, $userID, $sAliasPrefix, $bGetZombie) { static $ts = null; // some fixed timestamp of "now" (for consistency) if ($ts === null) { $ts = CTasksPerHitOption::getHitTimestamp(); } $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } // Adjust UNIX TS to "Bitrix timestamp" $tzOffset = CTimeZone::getOffset(); $val += $tzOffset; $ts += $tzOffset; if ($bTzWasDisabled) { CTimeZone::disable(); } $arSqlSearch = array(); $arFilter = array('::LOGIC' => 'AND'); $key = ltrim($key); $res = CTasks::MkOperationFilter($key); $fieldName = substr($res["FIELD"], 5, -3); // Cutoff prefix "META:" and suffix "_TS" $cOperationType = $res["OPERATION"]; $operationSymbol = substr($key, 0, -1 * strlen($res["FIELD"])); if (substr($cOperationType, 0, 1) !== '#') { switch ($operationSymbol) { case '<': $operationCode = CTaskFilterCtrl::OP_STRICTLY_LESS; break; case '>': $operationCode = CTaskFilterCtrl::OP_STRICTLY_GREATER; break; case '<=': $operationCode = CTaskFilterCtrl::OP_LESS_OR_EQUAL; break; case '>=': $operationCode = CTaskFilterCtrl::OP_GREATER_OR_EQUAL; break; case '!=': $operationCode = CTaskFilterCtrl::OP_NOT_EQUAL; break; case '': case '=': $operationCode = CTaskFilterCtrl::OP_EQUAL; break; default: CTaskAssert::log('Unknown operation code: ' . $operationSymbol . '; $key = ' . $key . '; it will be silently ignored, incorrect results expected', CTaskAssert::ELL_ERROR); return $arSqlSearch; break; } } else { $operationCode = (int) substr($cOperationType, 1); } $date1 = $date2 = $cOperationType1 = $cOperationType2 = null; // Convert cOperationType to format accepted by self::FilterCreate switch ($operationCode) { case CTaskFilterCtrl::OP_EQUAL: case CTaskFilterCtrl::OP_DATE_TODAY: case CTaskFilterCtrl::OP_DATE_YESTERDAY: case CTaskFilterCtrl::OP_DATE_TOMORROW: case CTaskFilterCtrl::OP_DATE_CUR_WEEK: case CTaskFilterCtrl::OP_DATE_PREV_WEEK: case CTaskFilterCtrl::OP_DATE_NEXT_WEEK: case CTaskFilterCtrl::OP_DATE_CUR_MONTH: case CTaskFilterCtrl::OP_DATE_PREV_MONTH: case CTaskFilterCtrl::OP_DATE_NEXT_MONTH: case CTaskFilterCtrl::OP_DATE_NEXT_DAYS: case CTaskFilterCtrl::OP_DATE_LAST_DAYS: $cOperationType1 = '>='; $cOperationType2 = '<='; break; case CTaskFilterCtrl::OP_LESS_OR_EQUAL: $cOperationType1 = '<='; break; case CTaskFilterCtrl::OP_GREATER_OR_EQUAL: $cOperationType1 = '>='; break; case CTaskFilterCtrl::OP_NOT_EQUAL: $cOperationType1 = '<'; $cOperationType2 = '>'; break; case CTaskFilterCtrl::OP_STRICTLY_LESS: $cOperationType1 = '<'; break; case CTaskFilterCtrl::OP_STRICTLY_GREATER: $cOperationType1 = '>'; break; default: CTaskAssert::log('Unknown operation code: ' . $operationCode . '; $key = ' . $key . '; it will be silently ignored, incorrect results expected', CTaskAssert::ELL_ERROR); return $arSqlSearch; break; } // Convert/generate dates $ts1 = $ts2 = null; switch ($operationCode) { case CTaskFilterCtrl::OP_DATE_TODAY: $ts1 = $ts2 = $ts; break; case CTaskFilterCtrl::OP_DATE_YESTERDAY: $ts1 = $ts2 = $ts - 86400; break; case CTaskFilterCtrl::OP_DATE_TOMORROW: $ts1 = $ts2 = $ts + 86400; break; case CTaskFilterCtrl::OP_DATE_CUR_WEEK: $weekDay = date('N'); // numeric representation of the day of the week (1 to 7) $ts1 = $ts - ($weekDay - 1) * 86400; $ts2 = $ts + (7 - $weekDay) * 86400; break; case CTaskFilterCtrl::OP_DATE_PREV_WEEK: $weekDay = date('N'); // numeric representation of the day of the week (1 to 7) $ts1 = $ts - ($weekDay - 1 + 7) * 86400; $ts2 = $ts - $weekDay * 86400; break; case CTaskFilterCtrl::OP_DATE_NEXT_WEEK: $weekDay = date('N'); // numeric representation of the day of the week (1 to 7) $ts1 = $ts + (7 - $weekDay + 1) * 86400; $ts2 = $ts + (7 - $weekDay + 7) * 86400; break; case CTaskFilterCtrl::OP_DATE_CUR_MONTH: $ts1 = mktime(0, 0, 0, date('n', $ts), 1, date('Y', $ts)); $ts2 = mktime(23, 59, 59, date('n', $ts) + 1, 0, date('Y', $ts)); break; case CTaskFilterCtrl::OP_DATE_PREV_MONTH: $ts1 = mktime(0, 0, 0, date('n', $ts) - 1, 1, date('Y', $ts)); $ts2 = mktime(23, 59, 59, date('n', $ts), 0, date('Y', $ts)); break; case CTaskFilterCtrl::OP_DATE_NEXT_MONTH: $ts1 = mktime(0, 0, 0, date('n', $ts) + 1, 1, date('Y', $ts)); $ts2 = mktime(23, 59, 59, date('n', $ts) + 2, 0, date('Y', $ts)); break; case CTaskFilterCtrl::OP_DATE_LAST_DAYS: $ts1 = $ts - (int) $val * 86400; $ts2 = $ts; break; case CTaskFilterCtrl::OP_DATE_NEXT_DAYS: $ts1 = $ts; $ts2 = $ts + (int) $val * 86400; break; case CTaskFilterCtrl::OP_GREATER_OR_EQUAL: case CTaskFilterCtrl::OP_LESS_OR_EQUAL: case CTaskFilterCtrl::OP_STRICTLY_LESS: case CTaskFilterCtrl::OP_STRICTLY_GREATER: $ts1 = $val; break; case CTaskFilterCtrl::OP_EQUAL: $ts1 = mktime(0, 0, 0, date('n', $val), date('j', $val), date('Y', $val)); $ts2 = mktime(23, 59, 59, date('n', $val), date('j', $val), date('Y', $val)); break; case CTaskFilterCtrl::OP_NOT_EQUAL: $ts1 = mktime(0, 0, 0, date('n', $val), date('j', $val), date('Y', $val)); $ts2 = mktime(23, 59, 59, date('n', $val), date('j', $val), date('Y', $val)); break; default: CTaskAssert::log('Unknown operation code: ' . $operationCode . '; $key = ' . $key . '; it will be silently ignored, incorrect results expected', CTaskAssert::ELL_ERROR); return $arSqlSearch; break; } if ($ts1) { $date1 = ConvertTimeStamp(mktime(0, 0, 0, date('n', $ts1), date('j', $ts1), date('Y', $ts1)), 'FULL'); } if ($ts2) { $date2 = ConvertTimeStamp(mktime(23, 59, 59, date('n', $ts2), date('j', $ts2), date('Y', $ts2)), 'FULL'); } if ($cOperationType1 !== null && $date1 !== null) { $arrayKey = $cOperationType1 . $fieldName; while (isset($arFilter[$arrayKey])) { $arrayKey = ' ' . $arrayKey; } $arFilter[$arrayKey] = $date1; } if ($cOperationType2 !== null && $date2 !== null) { $arrayKey = $cOperationType2 . $fieldName; while (isset($arFilter[$arrayKey])) { $arrayKey = ' ' . $arrayKey; } $arFilter[$arrayKey] = $date2; } $arSqlSearch[] = self::GetSqlByFilter($arFilter, $userID, $sAliasPrefix, $bGetZombie); return $arSqlSearch; }
/** * Not part of public API, for internal use only. * @deprecated * @access private */ public static function getTimeZoneOffset($userId = false) { $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } if ($userId === false) { $tzOffset = CTimeZone::getOffset(); } else { $tzOffset = CTimeZone::getOffset($userId); } if ($bTzWasDisabled) { CTimeZone::disable(); } return $tzOffset; }