/** * * @param array $arData with element "arDataName" * @param string $strRequest, for example: #RC#arDataName#-2#field1#field2#...#fieldN */ function BXTasksParseAndGetDynaParamValue($arData, $strRequest) { CTaskAssert::assert(is_array($arData) && is_string($strRequest) && substr($strRequest, 0, 4) === '#RC#'); $dataCount = count($arData); $strToParse = substr($strRequest, 4); $arrayToParse = explode('#', $strToParse); CTaskAssert::assert(is_array($arrayToParse) && count($arrayToParse) >= 3 && isset($arData[$arrayToParse[0]]) && CTaskAssert::isLaxIntegers($arrayToParse[1]) && $arrayToParse[1] < 0); $arRequestedData = $arData[$arrayToParse[0]]; $curDataIndex = count($arRequestedData) - 1; $deltaIndex = (int) $arrayToParse[1]; $requestedIndex = $curDataIndex + $deltaIndex + 1; // +1 because last data item mustn't be in data array yet if (!isset($arRequestedData[$requestedIndex])) { return null; } // Now, iterate throws given fields $maxIndex = count($arrayToParse) - 1; $arIteratedData = $arRequestedData[$requestedIndex]; for ($i = 2; $i <= $maxIndex; $i++) { $requestedNthFieldName = $arrayToParse[$i]; if (!isset($arIteratedData[$requestedNthFieldName])) { return null; } $arIteratedData = $arIteratedData[$requestedNthFieldName]; } return $arIteratedData; }
/** * Sends notifications to IM. * * @param $fromUserID * @param $arRecipientsIDs * @param $message * @param int $taskID * @param null $message_email * @param array $arEventData * @return bool|null */ public static function SendMessage($fromUserID, $arRecipientsIDs, $message, $taskID = 0, $message_email = null, $arEventData = array(), $taskAssignedTo = null) { if (!(IsModuleInstalled("im") && CModule::IncludeModule("im"))) { return false; } $message_email = is_null($message_email) ? $message : $message_email; if (!($fromUserID && $arRecipientsIDs && $message)) { return false; } CTaskAssert::assert(is_array($arEventData)); $arEventData['fromUserID'] =& $fromUserID; $arEventData['arRecipientsIDs'] =& $arRecipientsIDs; $arEventData['message'] =& $message; $arEventData['message_email'] =& $message_email; foreach (GetModuleEvents('tasks', 'OnBeforeTaskNotificationSend', true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($arEventData)) === false) { return false; } } $arSites = array(); if (CModule::IncludeModule("extranet")) { $dbSite = CSite::GetList($by = "sort", $order = "desc", array("ACTIVE" => "Y")); while ($arSite = $dbSite->Fetch()) { $type = $arSite["ID"] == CExtranet::GetExtranetSiteID() ? "EXTRANET" : "INTRANET"; if ($type === 'INTRANET' && isset($arSites['INTRANET']) && $arSite['DEF'] !== 'Y') { // Don't overwrite INTRANET site data by not default site continue; } $arSites[$type] = array('SITE_ID' => $arSite['ID'], "DIR" => strlen(trim($arSite["DIR"])) > 0 ? $arSite["DIR"] : "/", "SERVER_NAME" => strlen(trim($arSite["SERVER_NAME"])) > 0 ? $arSite["SERVER_NAME"] : COption::GetOptionString("main", "server_name", $_SERVER["HTTP_HOST"])); } } if (is_array($arRecipientsIDs) && count($arRecipientsIDs)) { $arRecipientsIDs = array_unique($arRecipientsIDs); $rsUser = CUser::GetList($by = 'ID', $order = 'ASC', array('ID' => implode('|', $arRecipientsIDs)), array('FIELDS' => array('ID'))); while ($arUser = $rsUser->Fetch()) { $notifyEvent = 'manage'; if ($taskAssignedTo !== null) { if ($arUser['ID'] == $taskAssignedTo) { $notifyEvent = 'task_assigned'; } } $pathToTask = CTaskNotifications::GetNotificationPath($arUser, $taskID, true, $arSites); $arMessageFields = array("TO_USER_ID" => $arUser['ID'], "FROM_USER_ID" => $fromUserID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "tasks", "NOTIFY_EVENT" => $notifyEvent, "NOTIFY_MESSAGE" => str_replace("#PATH_TO_TASK#", $pathToTask, $message), "NOTIFY_MESSAGE_OUT" => strip_tags(str_replace("#PATH_TO_TASK#", $pathToTask, $message_email))); CIMNotify::Add($arMessageFields); } } return null; }
/** * @param CTaskItemInterface $oTaskItem * @throws TasksException * @return array $arReturn with elements * <ul> * <li>$arReturn[0] - array of items * <li>$arReturn[1] - CDBResult * </ul> */ public static function fetchList(CTaskItemInterface $oTaskItem, $arOrder = array(), $arFilter = array()) { $arItems = array(); CTaskAssert::assert($oTaskItem instanceof CTaskItemInterface); $taskId = (int) $oTaskItem->getId(); // Ensure that we have read access for task $taskData = $oTaskItem->getData(); try { list($arItemsData, $rsData) = static::fetchListFromDb($taskData, $arOrder, $arFilter); } catch (Exception $e) { throw new TasksException('Action failed', TasksException::TE_ACTION_FAILED_TO_BE_PROCESSED); } foreach ($arItemsData as $arItemData) { $arItems[] = self::constructWithPreloadedData($oTaskItem, $arItemData['ID'], $arItemData); } return array($arItems, $rsData); }
private static function managePerHitOptions($operation, $moduleId, $optionName, $value = null) { static $arOptions = array(); $oName = $moduleId . '::' . $optionName; if (!array_key_exists($oName, $arOptions)) { $arOptions[$oName] = null; } $rc = null; if ($operation === 'read') { $rc = $arOptions[$oName]; } elseif ($operation === 'write') { $arOptions[$oName] = $value; } else { CTaskAssert::assert(false); } return $rc; }
public static function runRestMethod($executiveUserId, $methodName, $args, $navigation) { static $arManifest = null; static $arMethodsMetaInfo = null; if ($arManifest === null) { $arManifest = self::getManifest(); $arMethodsMetaInfo = $arManifest['REST: available methods']; } // Check and parse params CTaskAssert::assert(isset($arMethodsMetaInfo[$methodName])); $arMethodMetaInfo = $arMethodsMetaInfo[$methodName]; $argsParsed = CTaskRestService::_parseRestParams('ctasklogitem', $methodName, $args); $returnValue = null; if (isset($arMethodMetaInfo['staticMethod']) && $arMethodMetaInfo['staticMethod']) { if ($methodName === 'list') { $taskId = $argsParsed[0]; $order = $argsParsed[1]; $filter = $argsParsed[2]; $oTaskItem = CTaskItem::getInstance($taskId, $executiveUserId); list($items, $rsData) = self::fetchList($oTaskItem, $order, $filter); $returnValue = array(); foreach ($items as $item) { $returnValue[] = $item->getData(false); } } else { $returnValue = call_user_func_array(array('self', $methodName), $argsParsed); } } else { $taskId = array_shift($argsParsed); $itemId = array_shift($argsParsed); $oTaskItem = CTaskItem::getInstance($taskId, $executiveUserId); $item = new self($oTaskItem, $itemId); $returnValue = call_user_func_array(array($item, $methodName), $argsParsed); } return array($returnValue, null); }
private static function convertItemForExport($arItem) { static $arFields = null; $arResult = array(); if ($arFields === null) { $arManifest = self::getManifest(); $arFields = $arManifest['Fields']; } foreach ($arItem as $itemName => $itemData) { CTaskAssert::assert(strlen($itemName) > 2); if ($itemName === '::LOGIC') { $arResult[$itemName] = $itemData; continue; } if (substr($itemName, 0, 12) === '::SUBFILTER-') { $arResult[$itemName] = self::convertItemForExport($itemData); continue; } $value = $itemData; $itemName = ltrim($itemName); // Resolve operation code and cutoff operation prefix from item name $operation = null; foreach (self::$arOperationsMap as $operationCode => $operationPrefix) { $pattern = '/^' . preg_quote($operationPrefix) . '[A-Za-z]/'; if (preg_match($pattern, $itemName)) { $operation = $operationCode; $itemName = substr($itemName, strlen($operationPrefix)); break; } } CTaskAssert::assert($operation !== null); // Process values for date fields if (isset($arFields[$itemName]['Type']) && $arFields[$itemName]['Type'] === self::TYPE_DATE) { $value = self::convertTimestampToDateString($operation, $value); } $arResult[] = array('field' => $itemName, 'operation' => $operation, 'value' => $value); } return $arResult; /* data in: $arFilter = array( '::LOGIC' => 'AND', 'RESPONSIBLE_ID' => 1, '::SUBFILTER-1' => array( '::LOGIC' => 'OR', 'CREATED_BY' => 1, '!=CREATED_BY' => 2 ), '::SUBFILTER-2' => array( '::LOGIC' => 'AND', '%TITLE' => 'some interesting substring', '!%TITLE' => 'some not interesting substring' ) ); data out: array( '::LOGIC' => 'AND', array( 'field' => 'RESPONSIBLE_ID', 'operation' => CTaskFilterCtrlInterface::OP_EQUAL, 'value' => 1 ), '::SUBFILTER-1' => array( '::LOGIC' => 'OR', array( 'field' => 'CREATED_BY', 'operation' => CTaskFilterCtrlInterface::OP_EQUAL, 'value' => 1 ), array( 'field' => 'CREATED_BY', 'operation' => CTaskFilterCtrlInterface::OP_NOT_EQUAL, 'value' => 2 ) ), '::SUBFILTER-2' => array( '::LOGIC' => 'AND', array( 'field' => 'TITLE', 'operation' => CTaskFilterCtrlInterface::OP_SUBSTRING, 'value' => 1 ), array( 'field' => 'TITLE', 'operation' => CTaskFilterCtrlInterface::OP_NOT_SUBSTRING, 'value' => 2 ) ) ) */ }
/** * @param $userId * @return array|bool array with keys TASK_ID, USER_ID, TIMER_STARTED_AT, TIMER_ACCUMULATOR, * or false on error */ public static function stop($userId) { global $DB; $ts = time(); if ($ts < 1) { CTaskAssert::logError('[0x03ad8b00] current unix timestamp is in past, check system time'); CTaskAssert::assert(false); } $arData = self::get($userId); if ($arData !== false && ($arData['TIMER_STARTED_AT'] != 0 || $arData['TIMER_ACCUMULATOR'] != 0)) { $DB->query("UPDATE b_tasks_timer \n\t\t\t\tSET TIMER_ACCUMULATOR = 0, TIMER_STARTED_AT = 0\n\t\t\t\tWHERE\n\t\t\t\t\tUSER_ID = " . (int) $userId . "\n\t\t\t\t\tAND TASK_ID = " . (int) $arData['TASK_ID']); if ($arData['TIMER_STARTED_AT'] > 0 && $ts > $arData['TIMER_STARTED_AT']) { $arData['TIMER_ACCUMULATOR'] += $ts - $arData['TIMER_STARTED_AT']; } return $arData; } else { return false; } }
/** * @deprecated */ public static function runRestMethod($executiveUserId, $methodName, $args, $navigation) { static $arManifest = null; static $arMethodsMetaInfo = null; if ($arManifest === null) { $arManifest = self::getManifest(); $arMethodsMetaInfo = $arManifest['REST: available methods']; } // Check and parse params CTaskAssert::assert(isset($arMethodsMetaInfo[$methodName])); $arMethodMetaInfo = $arMethodsMetaInfo[$methodName]; $argsParsed = CTaskRestService::_parseRestParams('ctaskcomments', $methodName, $args); $returnValue = null; if (isset($arMethodMetaInfo['staticMethod']) && $arMethodMetaInfo['staticMethod']) { if ($methodName === 'add') { $occurAsUserId = CTasksTools::getOccurAsUserId(); if (!$occurAsUserId) { $occurAsUserId = $executiveUserId; } $taskId = $argsParsed[0]; $commentText = $argsParsed[1]; $commentAuthorId = $occurAsUserId; $returnValue = self::add($taskId, $commentAuthorId, $commentText); } } else { $taskId = array_shift($argsParsed); $oTask = self::getInstanceFromPool($taskId, $executiveUserId); $returnValue = call_user_func_array(array($oTask, $methodName), $argsParsed); } return array($returnValue, null); }
function Update($ID, $arFields, $arParams = array()) { global $DB, $USER; $ID = intval($ID); if ($ID < 1) { return false; } $executiveUserId = null; if (isset($arParams['USER_ID'])) { $executiveUserId = (int) $arParams['USER_ID']; } elseif (is_object($USER) && method_exists($USER, 'getId')) { $executiveUserId = (int) $USER->getId(); } if ($this->CheckFields($arFields, $ID)) { /** @noinspection PhpDeprecationInspection */ $rsUpdatingLogItem = self::getByID($ID); if ($rsUpdatingLogItem && ($arUpdatingLogItem = $rsUpdatingLogItem->fetch())) { $taskId = $arUpdatingLogItem['TASK_ID']; } else { return false; } $curDuration = 0; $rsTask = CTasks::getList(array(), array('ID' => $taskId), array('ID', 'TIME_SPENT_IN_LOGS')); if ($rsTask && ($arTask = $rsTask->fetch())) { $curDuration = (int) $arTask['TIME_SPENT_IN_LOGS']; } unset($arFields["ID"]); $arBinds = array("COMMENT_TEXT" => $arFields["COMMENT_TEXT"]); // Maintance backward compatibility if (isset($arFields['MINUTES'], $arFields['SECONDS'])) { CTaskAssert::logError('[0x63038b4f] '); CTaskAssert::assert(false); } if (isset($arFields['SECONDS'])) { $arFields['MINUTES'] = (int) round($arFields['SECONDS'] / 60, 0); } elseif (isset($arFields['MINUTES'])) { $arFields['SECONDS'] = 60 * $arFields['MINUTES']; } else { CTaskAssert::logError('[0x14e5d0eb] '); CTaskAssert::assert(false); } foreach (GetModuleEvents('tasks', 'OnBeforeTaskElapsedTimeUpdate', true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($ID, $arUpdatingLogItem, &$arFields)) === false) { return false; } } // If time changed - set CTaskElapsedItem::SOURCE_MANUAL flag if ($arUpdatingLogItem['MINUTES'] != $arFields['MINUTES'] || $arUpdatingLogItem['SECONDS'] != $arFields['SECONDS']) { $arFields['SOURCE'] = CTaskElapsedItem::SOURCE_MANUAL; } $strUpdate = $DB->PrepareUpdate("b_tasks_elapsed_time", $arFields); $strSql = "UPDATE b_tasks_elapsed_time SET " . $strUpdate . " WHERE ID=" . $ID; $rc = $DB->QueryBind($strSql, $arBinds, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $occurAsUserId = CTasksTools::getOccurAsUserId(); if (!$occurAsUserId) { $occurAsUserId = $executiveUserId ? $executiveUserId : 1; } $oLog = new CTaskLog(); $oLog->Add(array('TASK_ID' => $taskId, 'USER_ID' => $occurAsUserId, '~CREATED_DATE' => $DB->currentTimeFunction(), 'FIELD' => 'TIME_SPENT_IN_LOGS', 'FROM_VALUE' => $curDuration, 'TO_VALUE' => $curDuration - (int) $arUpdatingLogItem['SECONDS'] + (int) $arFields['SECONDS'])); foreach (GetModuleEvents('tasks', 'OnTaskElapsedTimeUpdate', true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($ID, $arFields)); } return $rc; } return false; }
/** * prevent creating through "new" * * @param $userId */ private function __construct($userId) { global $USER; CTaskAssert::assertLaxIntegers($userId); CTaskAssert::assert($userId > 0); $this->userId = $userId; if (isset($USER) && is_object($USER) && $USER->IsAuthorized()) { $this->loggedInUserId = (int) $USER->getId(); $this->paramName = self::listViewModeParamName . '_by_user_' . $this->loggedInUserId; } else { $this->paramName = self::listViewModeParamName; } $rc = CUserOptions::GetOption(self::listCategoryName, $this->paramName, serialize(false), $this->userId); $this->resetState(); $state = unserialize($rc); if (is_array($state)) { $this->state = array_merge($this->state, $state); } }
/** * This method is only for rest purposes * * @access private */ public static function runRestMethod($executiveUserId, $methodName, $args, $navigation) { static $arManifest = null; static $arMethodsMetaInfo = null; $rsData = null; if ($arManifest === null) { $arManifest = self::getManifest(); $arMethodsMetaInfo = $arManifest['REST: available methods']; } // Check and parse params CTaskAssert::assert(isset($arMethodsMetaInfo[$methodName])); $arMethodMetaInfo = $arMethodsMetaInfo[$methodName]; $argsParsed = CTaskRestService::_parseRestParams('ctaskitem', $methodName, $args); $runAs = $methodName; if (isset($arMethodsMetaInfo[$methodName]['runAs']) && (string) $arMethodsMetaInfo[$methodName]['runAs'] != '') { $runAs = $arMethodsMetaInfo[$methodName]['runAs']; } $returnValue = null; if (isset($arMethodMetaInfo['staticMethod']) && $arMethodMetaInfo['staticMethod']) { if ($methodName === 'add') { $argsParsed[] = $executiveUserId; /** @var CTaskItem $oTaskItem */ $oTaskItem = call_user_func_array(array('self', $methodName), $argsParsed); $taskId = (int) $oTaskItem->getId(); $returnValue = $taskId; self::cacheInstanceInPool($taskId, $executiveUserId, $oTaskItem); } elseif ($methodName === 'getlist' || $methodName === 'list') { array_unshift($argsParsed, $executiveUserId); // we need to fill default values up to $arParams (4th) argument while (!array_key_exists(3, $argsParsed)) { $argsParsed[] = array(); } if ($navigation['iNumPage'] > 1) { $argsParsed[3]['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => (int) $navigation['iNumPage']); } else { if (isset($argsParsed[3]['NAV_PARAMS'])) { if (isset($argsParsed[3]['NAV_PARAMS']['nPageTop'])) { $argsParsed[3]['NAV_PARAMS']['nPageTop'] = min(CTaskRestService::TASKS_LIMIT_TOP_COUNT, (int) $argsParsed[3]['NAV_PARAMS']['nPageTop']); } if (isset($argsParsed[3]['NAV_PARAMS']['nPageSize'])) { $argsParsed[3]['NAV_PARAMS']['nPageSize'] = min(CTaskRestService::TASKS_LIMIT_PAGE_SIZE, (int) $argsParsed[3]['NAV_PARAMS']['nPageSize']); } if (!isset($argsParsed[3]['NAV_PARAMS']['nPageTop']) && !isset($argsParsed[3]['NAV_PARAMS']['nPageSize'])) { $argsParsed[3]['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => 1); } } else { $argsParsed[3]['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => 1); } } /** @var CTaskItem[] $oTaskItems */ /** @noinspection PhpUnusedLocalVariableInspection */ list($oTaskItems, $rsData) = call_user_func_array(array('self', 'fetchList'), $argsParsed); $returnValue = array(); foreach ($oTaskItems as $oTaskItem) { $arTaskData = $oTaskItem->getData(false); $arTaskData['ALLOWED_ACTIONS'] = $oTaskItem->getAllowedActionsAsStrings(); if (isset($argsParsed[3])) { if (isset($argsParsed[3]['LOAD_TAGS']) && ($argsParsed[3]['LOAD_TAGS'] == 1 || $argsParsed[3]['LOAD_TAGS'] == 'Y')) { $arTaskData['TAGS'] = $oTaskItem->getTags(); } } $returnValue[] = $arTaskData; } } else { $returnValue = call_user_func_array(array('self', $runAs), $argsParsed); } } else { $taskId = array_shift($argsParsed); $oTask = self::getInstanceFromPool($taskId, $executiveUserId); $returnValue = call_user_func_array(array($oTask, $runAs), $argsParsed); } return array($returnValue, $rsData); }
/** * This function is for internal use only, not a part of public API * * @access private */ public static function _parseRestParams($className, $methodName, $inArgs) { CTaskAssert::assert(is_array($inArgs) && isset(self::$arMethodsMetaInfo[$className][$methodName])); $arMethodMetaInfo = self::$arMethodsMetaInfo[$className][$methodName]; $arAllowedParams = $arMethodMetaInfo['params']; $mandatoryParamsCount = $arMethodMetaInfo['mandatoryParamsCount']; $arDateFields = array(); if (isset(self::$arManifests[$className]['REST: date fields'])) { $arDateFields = self::$arManifests[$className]['REST: date fields']; } $outArgs = array(); foreach ($arAllowedParams as $paramIndex => $paramMetaInfo) { // No more params given? if (!array_key_exists($paramIndex, $inArgs)) { // Set default value, if need if (array_key_exists('defaultValue', $paramMetaInfo)) { $inArgs[$paramIndex] = $paramMetaInfo['defaultValue']; } elseif ($paramIndex < $mandatoryParamsCount) { throw new TasksException('Param #' . $paramIndex . ' (' . $paramMetaInfo['description'] . ')' . ' expected by method ' . $className . '::' . $methodName . '(), but not given.', TasksException::TE_WRONG_ARGUMENTS); } else { break; } // no more params to be processed } // for "galvanic isolation" of input/output $paramValue = $inArgs[$paramIndex]; // Check param type /** @noinspection PhpUnusedLocalVariableInspection */ $isCorrectValue = false; switch ($paramMetaInfo['type']) { case 'boolean': if ($paramValue === '0' || $paramValue === 0) { $paramValue = false; } elseif ($paramValue === '1' || $paramValue === 1) { $paramValue = true; } $isCorrectValue = is_bool($paramValue); break; case 'array': $isCorrectValue = is_array($paramValue); break; case 'string': $isCorrectValue = is_string($paramValue); break; case 'integer': $isCorrectValue = CTaskAssert::isLaxIntegers($paramValue); break; default: throw new TasksException('Internal error: unknown param type: ' . $paramMetaInfo['type'], TasksException::TE_UNKNOWN_ERROR); break; } if (!$isCorrectValue) { throw new TasksException('Param #' . $paramIndex . ' (' . $paramMetaInfo['description'] . ')' . ' for method ' . $className . '::' . $methodName . '()' . ' expected to be of type "' . $paramMetaInfo['type'] . '",' . ' but given something else.', TasksException::TE_WRONG_ARGUMENTS); } // add legal aggregated columns in keys & values array if (is_array($paramMetaInfo['allowedAggregations'])) { // for keys if (is_array($paramMetaInfo['allowedKeysInAggregation'])) { $fields = $paramMetaInfo['allowedKeysInAggregation']; } else { $fields = $paramMetaInfo['allowedKeys']; } if (is_array($fields)) { $aggrCombos = static::getAllowedAggregateCombos($paramMetaInfo['allowedAggregations'], $fields); $paramMetaInfo['allowedKeys'] = array_merge($paramMetaInfo['allowedKeys'], $aggrCombos); } // for values if (is_array($paramMetaInfo['allowedValuesInAggregation'])) { $fields = $paramMetaInfo['allowedValuesInAggregation']; } else { $fields = $paramMetaInfo['allowedValues']; } if (is_array($fields)) { $aggrCombos = static::getAllowedAggregateCombos($paramMetaInfo['allowedAggregations'], $fields); $paramMetaInfo['allowedValues'] = array_merge($paramMetaInfo['allowedValues'], $aggrCombos); } } if (isset($paramMetaInfo['allowedKeys'])) { CTaskAssert::assert(is_array($paramValue)); // ensure that $paramValue is array /** @var $paramValue array */ foreach (array_keys($paramValue) as $key) { // a little fix to be able to pass an empty array in order to "skip" argument if ((string) $key == '0' && $paramValue[$key] == '') { unset($paramValue[$key]); continue; } if (isset($paramMetaInfo['allowedKeyPrefixes'])) { $keyWoPrefix = str_replace($paramMetaInfo['allowedKeyPrefixes'], '', $key); } else { $keyWoPrefix = $key; } if (!in_array((string) $keyWoPrefix, $paramMetaInfo['allowedKeys'], true)) { throw new TasksException('Param #' . $paramIndex . ' (' . $paramMetaInfo['description'] . ')' . ' for method ' . $className . '::' . $methodName . '()' . ' must not contain key "' . $key . '".', TasksException::TE_WRONG_ARGUMENTS); } // Additionally convert datetime fields from ISO 8601 if (in_array((string) $keyWoPrefix, $arDateFields, true) && !in_array($paramValue[$key], array('asc', 'desc'))) { $paramValue[$key] = (string) CRestUtil::unConvertDateTime($paramValue[$key]); } } } if (isset($paramMetaInfo['allowedValues'])) { CTaskAssert::assert(is_array($paramValue)); foreach ($paramValue as $value) { if ($value !== null && !is_bool($value)) { $value = (string) $value; } if (!in_array($value, $paramMetaInfo['allowedValues'], true)) { throw new TasksException('Param #' . $paramIndex . ' (' . $paramMetaInfo['description'] . ')' . ' for method ' . $className . '::' . $methodName . '()' . ' must not contain value "' . $value . '".', TasksException::TE_WRONG_ARGUMENTS); } } } // "galvanic isolation" of input/output $outArgs[] = $paramValue; } if (count($inArgs) > count($arAllowedParams)) { throw new TasksException('Too much params(' . count($inArgs) . ') given for method ' . $className . '::' . $methodName . '()' . ', but expected not more than ' . count($arAllowedParams) . '.', TasksException::TE_WRONG_ARGUMENTS); } return $outArgs; }
} $APPLICATION->IncludeComponent("bitrix:socialnetwork.group.selector", ".default", array('BIND_ELEMENT' => $inData['bindElement'], 'ON_SELECT' => $onSelectFuncName, 'JS_OBJECT_NAME' => $inData['jsObjectName'], 'FEATURES_PERMS' => array('tasks', 'create_tasks'), 'SELECTED' => 0), null, array("HIDE_ICONS" => "Y")); break; case 'LHEditor': CTaskAssert::assert(isset($inData['jsObjectName'], $inData['elementId'])); if (!CModule::IncludeModule("fileman")) { ShowError('Cannot include fileman module'); } else { $Editor = new CHTMLEditor(); $res = array_merge(array('minBodyWidth' => 350, 'minBodyHeight' => 200, 'normalBodyWidth' => 555, 'bAllowPhp' => false, 'limitPhpAccess' => false, 'showTaskbars' => false, 'showNodeNavi' => false, 'askBeforeUnloadPage' => true, 'bbCode' => true, 'siteId' => SITE_ID, 'autoResize' => true, 'autoResizeOffset' => 40, 'saveOnBlur' => true, 'setFocusAfterShow' => false, 'controlsMap' => array(array('id' => 'Bold', 'compact' => true, 'sort' => 80), array('id' => 'Italic', 'compact' => true, 'sort' => 90), array('id' => 'Underline', 'compact' => true, 'sort' => 100), array('id' => 'Strikeout', 'compact' => true, 'sort' => 110), array('id' => 'RemoveFormat', 'compact' => true, 'sort' => 120), array('id' => 'Color', 'compact' => true, 'sort' => 130), array('id' => 'FontSelector', 'compact' => false, 'sort' => 135), array('id' => 'FontSize', 'compact' => false, 'sort' => 140), array('separator' => true, 'compact' => false, 'sort' => 145), array('id' => 'OrderedList', 'compact' => true, 'sort' => 150), array('id' => 'UnorderedList', 'compact' => true, 'sort' => 160), array('id' => 'AlignList', 'compact' => false, 'sort' => 190), array('separator' => true, 'compact' => false, 'sort' => 200), array('id' => 'InsertLink', 'compact' => true, 'sort' => 210), array('id' => 'InsertImage', 'compact' => false, 'sort' => 220), array('id' => 'InsertVideo', 'compact' => true, 'sort' => 230), array('id' => 'InsertTable', 'compact' => false, 'sort' => 250), array('id' => 'Code', 'compact' => true, 'sort' => 260), array('id' => 'Quote', 'compact' => true, 'sort' => 270), array('separator' => true, 'compact' => false, 'sort' => 290), array('id' => 'Fullscreen', 'compact' => false, 'sort' => 310), array('id' => 'BbCode', 'compact' => true, 'sort' => 340), array('id' => 'More', 'compact' => true, 'sort' => 400))), array('name' => 'DESCRIPTION', 'id' => $inData['elementId'], 'width' => '100%', 'arSmiles' => array(), 'iframeCss' => 'body{font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 13px;}' . '.bx-spoiler {border:1px solid #C0C0C0;background-color:#fff4ca;padding: 4px 4px 4px 24px;color:#373737;border-radius:2px;min-height:1em;margin: 0;}')); $Editor->Show($res); } break; case 'system.field.edit::WEBDAV': case 'system.field.edit::CRM': CTaskAssert::assert(isset($inData['taskId'], $inData['userFieldName'], $inData['nameContainerId'], $inData['dataContainerId']) && CTaskAssert::isLaxIntegers($inData['taskId']) && is_string($inData['userFieldName']) && $inData['userFieldName'] !== '' && is_string($inData['nameContainerId']) && $inData['nameContainerId'] !== '' && is_string($inData['dataContainerId']) && $inData['dataContainerId'] !== ''); if ($inData['requestedObject'] === 'system.field.edit::CRM' && $inData['taskId'] == 0) { break; } global $USER_FIELD_MANAGER; $arAvailableUserFieldsMeta = $USER_FIELD_MANAGER->GetUserFields('TASKS_TASK', $inData['taskId'], LANGUAGE_ID); // We need only $inData['userFieldName'] if (!isset($arAvailableUserFieldsMeta[$inData['userFieldName']])) { break; } $arUserField = $arAvailableUserFieldsMeta[$inData['userFieldName']]; if ($arUserField['EDIT_IN_LIST'] !== 'Y') { break; } echo '<div id="' . $inData['nameContainerId'] . '">' . htmlspecialcharsbx($arUserField['EDIT_FORM_LABEL']) . '</div>'; echo '<div id="' . $inData['dataContainerId'] . '">';
pulltext: '<?php echo GetMessageJS('MB_TASKS_TASKS_FILTER_PULLDOWN_PULL'); ?> ', downtext: '<?php echo GetMessageJS('MB_TASKS_TASKS_FILTER_PULLDOWN_DOWN'); ?> ', loadtext: '<?php echo GetMessageJS('MB_TASKS_TASKS_FILTER_PULLDOWN_LOADING'); ?> ', action: 'RELOAD', callback: function() { app.reload(); } }); </script> <?php $arResult = array(); $environmentCheck = isset($GLOBALS['APPLICATION']) && is_object($GLOBALS['APPLICATION']) && isset($GLOBALS['USER']) && is_object($GLOBALS['USER']) && isset($arParams) && is_array($arParams) && CModule::IncludeModule('tasks'); try { CTaskAssert::assert($environmentCheck); unset($environmentCheck); $arResult['USER_ID'] = (int) $_GET['USER_ID']; $oFilter = CTaskFilterCtrl::GetInstance($arResult['USER_ID']); $arResult['PRESETS_TREE'] = $oFilter->ListFilterPresets($bTreeMode = true); $arResult['CURRENT_PRESET_ID'] = $oFilter->GetSelectedFilterPresetId(); } catch (Exception $e) { return false; } $this->IncludeComponentTemplate(); return $arResult;
public static function runRestMethod($executiveUserId, $methodName, $args, $navigation) { CTaskAssert::assert($methodName === 'getcurrenttaskslist'); // Check and parse params $argsParsed = CTaskRestService::_parseRestParams('ctaskplannermaintance', $methodName, $args); $arTasksIds = call_user_func_array(array('self', 'getcurrenttaskslist'), $argsParsed); return array($arTasksIds, null); }
/** * prevent creating through "new" * * @param $userId */ private function __construct($userId) { global $USER; CTaskAssert::assertLaxIntegers($userId); CTaskAssert::assert($userId > 0); $this->userId = $userId; if (isset($GLOBALS['USER']) && is_object($GLOBALS['USER']) && $USER->IsAuthorized()) { $this->loggedInUserId = (int) $USER->getId(); } $this->oListState = CTaskListState::getInstance($userId); }
function Update($ID, $arFields, $arParams = array()) { global $DB, $USER, $USER_FIELD_MANAGER; $ID = intval($ID); if ($ID < 1) { return false; } $bCheckFilesPermissions = false; if (isset($arParams['CHECK_RIGHTS_ON_FILES']) && ($arParams['CHECK_RIGHTS_ON_FILES'] === true || $arParams['CHECK_RIGHTS_ON_FILES'] === 'Y')) { CTaskAssert::assert(isset($arParams['USER_ID']) && CTaskAssert::isLaxIntegers($arParams['USER_ID']) && $arParams['USER_ID'] > 0); $bCheckFilesPermissions = true; } $arParamsForCheckFields = array('CHECK_RIGHTS_ON_FILES' => $bCheckFilesPermissions); if (isset($arParams['USER_ID'])) { $arParamsForCheckFields['USER_ID'] = $arParams['USER_ID']; } // We need understand, does REPLICATE_PARAMS changed $rsCurData = self::GetByID($ID); $arCurData = $rsCurData->Fetch(); $this->currentData = $arCurData; if (intval($arCurData['BASE_TEMPLATE_ID']) > 0) { unset($arFields['REPLICATE']); // ... you cannot set replicate params unset($arFields['PARENT_ID']); // ... and base task $isReplicateParamsChanged = false; } else { $isReplicateParamsChanged = isset($arFields['REPLICATE']) && $arCurData['REPLICATE'] !== $arFields['REPLICATE'] || isset($arFields['REPLICATE_PARAMS']) && $arCurData['REPLICATE_PARAMS'] !== $arFields['REPLICATE_PARAMS']; } if ($userID === null) { $userID = is_object($USER) ? intval($USER->GetID()) : 1; } if ($this->CheckFields($arFields, $ID, $arParamsForCheckFields)) { if ($USER_FIELD_MANAGER->CheckFields("TASKS_TASK_TEMPLATE", $ID, $arFields)) { unset($arFields['ID']); $arBinds = array('DESCRIPTION' => $arFields['DESCRIPTION'], 'REPLICATE_PARAMS' => $arFields['REPLICATE_PARAMS'], 'ACCOMPLICES' => $arFields['ACCOMPLICES'], 'AUDITORS' => $arFields['AUDITORS'], 'FILES' => $arFields['FILES'], 'TAGS' => $arFields['TAGS'], 'DEPENDS_ON' => $arFields['DEPENDS_ON']); $strUpdate = $DB->PrepareUpdate('b_tasks_template', $arFields, 'tasks'); if ((string) $strUpdate !== '') { $strSql = "UPDATE b_tasks_template SET " . $strUpdate . " WHERE ID=" . $ID; $DB->QueryBind($strSql, $arBinds, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } if (isset($arFields['FILES'])) { CTaskFiles::removeTemporaryStatusForFiles(unserialize($arFields['FILES']), $arParams['USER_ID']); } $USER_FIELD_MANAGER->Update("TASKS_TASK_TEMPLATE", $ID, $arFields, $userID); // update template tree, if required if (isset($arFields['BASE_TEMPLATE_ID'])) { try { Template\DependencyTable::link($ID, intval($arFields['BASE_TEMPLATE_ID']), array('CREATE_PARENT_NODE_ON_NOTFOUND' => true)); } catch (\Bitrix\Tasks\DB\Tree\LinkExistsException $e) { } } if ($isReplicateParamsChanged) { // Firstly, remove all agents for this template /** @noinspection PhpDynamicAsStaticMethodCallInspection */ CAgent::RemoveAgent('CTasks::RepeatTaskByTemplateId(' . $ID . ');', 'tasks'); /** @noinspection PhpDynamicAsStaticMethodCallInspection */ CAgent::RemoveAgent('CTasks::RepeatTaskByTemplateId(' . $ID . ', 0);', 'tasks'); /** @noinspection PhpDynamicAsStaticMethodCallInspection */ CAgent::RemoveAgent('CTasks::RepeatTaskByTemplateId(' . $ID . ', 1);', 'tasks'); // Set up new agent if ($arFields['REPLICATE'] === 'Y') { $nextTime = CTasks::GetNextTime(unserialize($arFields['REPLICATE_PARAMS'])); if ($nextTime) { CTimeZone::Disable(); /** @noinspection PhpDynamicAsStaticMethodCallInspection */ CAgent::AddAgent('CTasks::RepeatTaskByTemplateId(' . $ID . ', 0);', 'tasks', 'N', 86400, $nextTime, 'Y', $nextTime); CTimeZone::Enable(); } } } return true; } } return false; }
/** * prevent creating through "new" * * @param $userId */ private function __construct($userId) { global $USER; CTaskAssert::assertLaxIntegers($userId); CTaskAssert::assert($userId > 0); $this->userId = $userId; if (isset($USER) && is_object($USER) && $USER->IsAuthorized()) { $this->loggedInUserId = (int) $USER->getId(); $this->paramName = self::listViewModeParamName . '_by_user_' . $this->loggedInUserId; } else { $this->paramName = self::listViewModeParamName; } $rc = CUserOptions::GetOption(self::listCategoryName, $this->paramName, serialize(false), $this->userId); $this->state = array(self::TOC_SECTION_SELECTED => self::VIEW_SECTION_ROLES, self::TOC_ROLE_SELECTED => self::VIEW_ROLE_RESPONSIBLE, self::TOC_VIEW_SELECTED => self::VIEW_MODE_LIST, self::TOC_TASK_CATEGORY_SELECTED => array(self::VIEW_ROLE_RESPONSIBLE => self::VIEW_TASK_CATEGORY_IN_PROGRESS, self::VIEW_ROLE_ORIGINATOR => self::VIEW_TASK_CATEGORY_IN_PROGRESS, self::VIEW_ROLE_ACCOMPLICE => self::VIEW_TASK_CATEGORY_IN_PROGRESS, self::VIEW_ROLE_AUDITOR => self::VIEW_TASK_CATEGORY_IN_PROGRESS), self::TOC_SUBMODES => array(self::VIEW_SUBMODE_WITH_GROUPS => array(self::TOC_SELECTED => 'Y'), self::VIEW_SUBMODE_WITH_SUBTASKS => array(self::TOC_SELECTED => 'Y'))); $state = unserialize($rc); if (is_array($state)) { $this->state = array_merge($this->state, $state); } }
public static function runRestMethod($executiveUserId, $methodName, $args, $navigation) { CTaskAssert::assert($methodName === 'getlist'); // Force & limit NAV_PARAMS (in 4th argument) while (count($args) < 4) { $args[] = array(); } // All params in CTasks::GetList() by default are empty arrays $arParams =& $args[3]; if ($navigation['iNumPage'] > 1) { $arParams['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => (int) $navigation['iNumPage']); } else { if (isset($arParams['NAV_PARAMS'])) { if (isset($arParams['NAV_PARAMS']['nPageTop'])) { $arParams['NAV_PARAMS']['nPageTop'] = min(CTaskRestService::TASKS_LIMIT_TOP_COUNT, (int) $arParams['NAV_PARAMS']['nPageTop']); } if (isset($arParams['NAV_PARAMS']['nPageSize'])) { $arParams['NAV_PARAMS']['nPageSize'] = min(CTaskRestService::TASKS_LIMIT_PAGE_SIZE, (int) $arParams['NAV_PARAMS']['nPageSize']); } if (!isset($arParams['NAV_PARAMS']['nPageTop']) && !isset($arParams['NAV_PARAMS']['nPageSize'])) { $arParams['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => 1); } } else { $arParams['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => 1); } } // Check and parse params $argsParsed = CTaskRestService::_parseRestParams('ctasks', $methodName, $args); $arParams['USER_ID'] = $executiveUserId; // TODO: remove this hack (needs for select tasks with GROUP_ID === NULL or 0) if (isset($argsParsed[1])) { $arFilter = $argsParsed[1]; foreach ($arFilter as $key => $value) { if ($key === 'GROUP_ID' && $value == 0) { $argsParsed[1]['META:GROUP_ID_IS_NULL_OR_ZERO'] = 1; unset($argsParsed[1][$key]); break; } } if (isset($argsParsed[1]['ID']) && is_array($argsParsed[1]['ID']) && empty($argsParsed[1]['ID'])) { $argsParsed[1]['ID'] = -1; } } $rsTasks = call_user_func_array(array('self', 'getlist'), $argsParsed); $arTasks = array(); while ($arTask = $rsTasks->fetch()) { $arTasks[] = $arTask; } return array($arTasks, $rsTasks); }
public static function onEventFilter($arParams, $arHandler) { if (!isset($arHandler['EVENT_NAME'])) { $arHandler['EVENT_NAME'] = '$arHandler[\'EVENT_NAME\'] is not set'; } $entityType = (string) array_shift($arParams); $taskId = (int) array_shift($arParams); $parameters = array_shift($arParams); $arEventFields = array('FIELDS_BEFORE' => 'undefined', 'FIELDS_AFTER' => 'undefined', 'IS_ACCESSIBLE_BEFORE' => 'undefined', 'IS_ACCESSIBLE_AFTER' => 'undefined'); CTaskAssert::assert($taskId >= 1); // 'TK' is our entity type if ($entityType !== 'TK') { return; } if (empty($parameters["MESSAGE_ID"])) { return; } switch (strtolower($arHandler['EVENT_NAME'])) { case 'ontaskcommentadd': $arEventFields['FIELDS_BEFORE'] = 'undefined'; $arEventFields['FIELDS_AFTER'] = array('ID' => $parameters["MESSAGE_ID"], 'TASK_ID' => $taskId); $arEventFields['IS_ACCESSIBLE_BEFORE'] = 'N'; $arEventFields['IS_ACCESSIBLE_AFTER'] = 'undefined'; break; case 'ontaskcommentupdate': $arEventFields['FIELDS_BEFORE'] = array('ID' => $parameters["MESSAGE_ID"], 'TASK_ID' => $taskId); $arEventFields['FIELDS_AFTER'] = array('ID' => $parameters["MESSAGE_ID"], 'TASK_ID' => $taskId, 'ACTION' => $parameters["ACTION"]); $arEventFields['IS_ACCESSIBLE_BEFORE'] = 'undefined'; $arEventFields['IS_ACCESSIBLE_AFTER'] = 'undefined'; break; default: throw new Exception('tasks\' RPC event handler: onEventFilter: ' . 'not allowed $arHandler[\'EVENT_NAME\']: ' . $arHandler['EVENT_NAME']); break; } return $arEventFields; }
private function checkColumns($columns) { $arAllowedColumnsIDs = array_keys(CTaskColumnList::get()); CTaskAssert::assert(is_array($columns)); foreach ($columns as &$columnData) { CTaskAssert::assert(isset($columnData['ID'], $columnData['WIDTH']) && count($columnData) == 2 && CTaskAssert::isLaxIntegers($columnData['ID'], $columnData['WIDTH']) && in_array($columnData['ID'], $arAllowedColumnsIDs) && $columnData['WIDTH'] >= 0); } unset($columnData); }
CTaskAssert::assert(isset($_POST['movedColumnId'], $_POST['movedAfterColumnId'], $_POST['columnContextId'])); $loggedInUserId = $USER->getId(); $movedColumnId = (int) $_POST['movedColumnId']; $movedAfterColumnId = (int) $_POST['movedAfterColumnId']; $columnContextId = (int) $_POST['columnContextId']; $knownColumnsIds = array_keys(CTaskColumnList::get()); CTaskAssert::assert($loggedInUserId >= 1); CTaskAssert::assert(in_array($movedColumnId, $knownColumnsIds)); CTaskAssert::assert($movedAfterColumnId == 0 || in_array($movedAfterColumnId, $knownColumnsIds)); CTaskAssert::assert(in_array($columnContextId, CTaskColumnContext::get())); $oPresetManager = CTaskColumnPresetManager::getInstance($loggedInUserId, $columnContextId); $oColumnManager = new CTaskColumnManager($oPresetManager); $oColumnManager->moveColumnAfter($movedColumnId, $movedAfterColumnId); } else { if ($_POST['mode'] === 'groupAction') { CTaskAssert::assert(isset($_POST['action'])); } } } } } } } catch (Exception $e) { if ($jsonReply === null) { $jsonReply = array('status' => 'failure'); } } if ($jsonReply !== null) { $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); echo CUtil::PhpToJsObject($jsonReply);
if ($arData['TO_VALUE']) { // Don't format time, if it's 00:00 if (date('H:i', $arData['TO_VALUE']) == '00:00') { $strDateTo = FormatDate(CDatabase::DateFormatToPHP(FORMAT_DATE), $arData['TO_VALUE']); } else { $strDateTo = FormatDate(CDatabase::DateFormatToPHP(FORMAT_DATETIME), $arData['TO_VALUE']); } } $arResult = array('td1' => '<span class="task-log-date">' . FormatDateFromDB($arData['CREATED_DATE']) . '</span>', 'td2' => '<a class="task-log-author" target="_top" href="' . CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_USER_PROFILE'], array('user_id' => $authorUserId)) . '">' . htmlspecialcharsbx(tasksFormatNameShort($arCurUserData["NAME"], $arCurUserData["LAST_NAME"], $arCurUserData["LOGIN"], $arCurUserData["SECOND_NAME"], $arParams["NAME_TEMPLATE"])) . '</a>', 'td3' => '<span class="task-log-where">' . GetMessage("TASKS_LOG_DEADLINE") . '</span>', 'td4' => '<span class="task-log-what">' . $strDateFrom . '<span class="task-log-arrow">→</span>' . $strDateTo . '</span>'); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); echo CUtil::PhpToJsObject($arResult); } } elseif ($action === 'remove_file') { try { CTaskAssert::log('remove_file: fileId=' . $_POST['fileId'] . ', taskId=' . $_POST['taskId'] . ', userId=' . $loggedInUserId, CTaskAssert::ELL_INFO); CTaskAssert::assert(isset($_POST['fileId'], $_POST['taskId'])); $oTaskItem = new CTaskItem($_POST['taskId'], $loggedInUserId); $oTaskItem->removeAttachedFile($_POST['fileId']); echo 'Success'; } catch (Exception $e) { echo 'Error occured'; CTaskAssert::logWarning('Unable to remove_file: fileId=' . $_POST['fileId'] . ', taskId=' . $_POST['taskId'] . ', userId=' . $loggedInUserId); } } elseif ($action === 'render_task_detail_part') { if (isset($_POST['BLOCK'])) { switch ($_POST['BLOCK']) { case 'buttons': case 'right_sidebar': if ($_POST['IS_IFRAME'] === 'true' || $_POST['IS_IFRAME'] === true || $_POST['IS_IFRAME'] === 'Y') { $isIframe = true; } else {
private function __construct($userId) { CTaskAssert::assertLaxIntegers($userId); CTaskAssert::assert($userId > 0); $this->userId = (int) $userId; }
$oFilter = CTaskFilterCtrl::getInstance($loggedInUser); $newPresetId = $oFilter->importFilterDataFromJs($_POST['presetData'], $mode, $presetId); $arReply['newPresetId'] = $newPresetId; } catch (Exception $e) { $status = 'fail'; } break; case 'removePreset': try { CTaskAssert::assert(isset($_POST['presetId']) && $_POST['presetId'] > 0); CTaskAssert::assertLaxIntegers($_POST['presetId']); $oFilter = CTaskFilterCtrl::getInstance($loggedInUser); $arPresetDefinition = $oFilter->removePreset($_POST['presetId']); if ($arPresetDefinition !== false) { $arReply = array('removedPresetId' => (int) $_POST['presetId']); } else { $status = 'fail'; } } catch (Exception $e) { $status = 'fail'; } break; default: CTaskAssert::assert(false); break; } $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); echo CUtil::PhpToJsObject(array('status' => $status, 'reply' => $arReply)); CMain::FinalActions(); // to make events work on bitrix24