Exemple #1
0
 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);
 }
Exemple #2
0
 public function stop()
 {
     global $CACHE_MANAGER;
     $arTimer = CTaskTimerCore::stop($this->userId);
     $this->cachedLastTimer = null;
     if ($arTimer !== false && $arTimer['TIMER_ACCUMULATOR'] > 0) {
         /** @noinspection PhpDeprecationInspection */
         $o = new CTaskElapsedTime();
         $o->add(array('USER_ID' => $this->userId, 'TASK_ID' => $arTimer['TASK_ID'], 'SECONDS' => $arTimer['TIMER_ACCUMULATOR'], 'COMMENT_TEXT' => ''), array('SOURCE_SYSTEM' => 'Y'));
         $oTaskItem = CTaskItem::getInstance($arTimer['TASK_ID'], $this->userId);
         $arTask = $oTaskItem->getData(false);
         $arAffectedUsers = array_unique(array_merge(array($this->userId, $arTask['RESPONSIBLE_ID']), (array) $arTask['ACCOMPLICES']));
         foreach ($arAffectedUsers as $userId) {
             $CACHE_MANAGER->ClearByTag('tasks_user_' . $userId);
         }
     }
 }
Exemple #3
0
 protected static function getTask($userId, $taskId)
 {
     // on the same $userId and $taskId this will return the same task instance from cache
     return \CTaskItem::getInstance($taskId, $userId);
 }
Exemple #4
0
 protected static function SaveTask(&$arFields)
 {
     $responsibleID = isset($arFields['RESPONSIBLE_ID']) ? intval($arFields['RESPONSIBLE_ID']) : 0;
     $typeID = isset($arFields['TYPE_ID']) ? intval($arFields['TYPE_ID']) : CCrmActivityType::Undefined;
     if (!($responsibleID > 0 && $typeID === CCrmActivityType::Task)) {
         return false;
     }
     if (!(IsModuleInstalled('tasks') && CModule::IncludeModule('tasks'))) {
         return false;
     }
     $associatedEntityID = isset($arFields['ASSOCIATED_ENTITY_ID']) ? intval($arFields['ASSOCIATED_ENTITY_ID']) : 0;
     if ($associatedEntityID <= 0) {
         return false;
     }
     $arTaskFields = array();
     if (isset($arFields['SUBJECT'])) {
         $arTaskFields['TITLE'] = $arFields['SUBJECT'];
     }
     if (isset($arFields['END_TIME'])) {
         $arTaskFields['DEADLINE'] = $arFields['END_TIME'];
     }
     if (isset($arFields['COMPLETED']) && $arFields['COMPLETED'] !== 'Y') {
         $arTaskFields['STATUS'] = CTasks::STATE_PENDING;
     }
     $result = true;
     if (!empty($arTaskFields)) {
         $task = new CTasks();
         self::$TASK_OPERATIONS[$associatedEntityID] = 'U';
         $result = $task->Update($associatedEntityID, $arTaskFields);
         unset(self::$TASK_OPERATIONS[$associatedEntityID]);
     }
     if (isset($arFields['COMPLETED']) && $arFields['COMPLETED'] === 'Y') {
         self::$TASK_OPERATIONS[$associatedEntityID] = 'U';
         try {
             $currentUser = CCrmSecurityHelper::GetCurrentUserID();
             $taskItem = CTaskItem::getInstance($associatedEntityID, $currentUser > 0 ? $currentUser : 1);
             $taskItem->complete();
             $result = true;
         } catch (TasksException $e) {
             $result = false;
         }
         unset(self::$TASK_OPERATIONS[$associatedEntityID]);
     }
     return $result;
 }
Exemple #5
0
 /**
  * @deprecated
  */
 private static function getTaskMembersByTaskId($taskId, $excludeUser = 0)
 {
     $oTask = CTaskItem::getInstance((int) $taskId, CTasksTools::GetCommanderInChief());
     $arTask = $oTask->getData(false);
     $arUsersIds = CTaskNotifications::getRecipientsIDs($arTask, $bExcludeLoggedUser = false);
     $excludeUser = (int) $excludeUser;
     if ($excludeUser >= 1) {
         $currentUserPos = array_search($excludeUser, $arUsersIds);
         if ($currentUserPos !== false) {
             unset($arUsersIds[$currentUserPos]);
         }
     } else {
         if ($excludeUser < 0) {
             CTaskAssert::logWarning('[0x3c2a31fe] invalid user id (' . $excludeUser . ')');
         }
     }
     return $arUsersIds;
 }
Exemple #6
0
                 try {
                     $oTask = CTaskItem::getInstance($taskId, $loggedInUserId);
                     $arTask = $oTask->getData(false);
                     $oTask->update(array('DEADLINE' => $value));
                     ++$processedItems;
                 } catch (TasksException $e) {
                     // some of items can't be processed (no rights, etc)
                     ++$notProcessedItems;
                 }
             }
             break;
         case 'set_group':
             $value = (int) $_POST['value'];
             foreach ($arTasksIds as $taskId) {
                 try {
                     $oTask = CTaskItem::getInstance($taskId, $loggedInUserId);
                     $arTask = $oTask->getData(false);
                     $oTask->update(array('GROUP_ID' => $value));
                     ++$processedItems;
                 } catch (TasksException $e) {
                     // some of items can't be processed (no rights, etc)
                     ++$notProcessedItems;
                 }
             }
             break;
         default:
             CTaskAssert::logError('[0x8a1747a5] unknown subaction: ' . $_POST['subaction']);
             break;
     }
     break;
 default:
Exemple #7
0
 public static function tasks_extended_meta_setAnyStatus($args)
 {
     $arMessages = array();
     $parsedReturnValue = null;
     $withoutExceptions = false;
     try {
         CTaskAssert::assert(is_array($args) && count($args) == 2);
         $statusId = array_pop($args);
         $taskId = array_pop($args);
         CTaskAssert::assertLaxIntegers($statusId, $taskId);
         $taskId = (int) $taskId;
         $statusId = (int) $statusId;
         if (!in_array($statusId, array(CTasks::STATE_PENDING, CTasks::STATE_IN_PROGRESS, CTasks::STATE_SUPPOSEDLY_COMPLETED, CTasks::STATE_COMPLETED, CTasks::STATE_DEFERRED), true)) {
             throw new TasksException('Invalid status given', TasksException::TE_WRONG_ARGUMENTS);
         }
         $oTask = CTaskItem::getInstance($taskId, 1);
         // act as Admin
         $oTask->update(array('STATUS' => $statusId));
         $parsedReturnValue = null;
         $withoutExceptions = true;
     } catch (CTaskAssertException $e) {
         $arMessages[] = array('id' => 'TASKS_ERROR_ASSERT_EXCEPTION', 'text' => 'TASKS_ERROR_ASSERT_EXCEPTION');
     } catch (TasksException $e) {
         $errCode = $e->getCode();
         $errMsg = $e->getMessage();
         if ($e->GetCode() & TasksException::TE_FLAG_SERIALIZED_ERRORS_IN_MESSAGE) {
             $arMessages = unserialize($errMsg);
         } else {
             $arMessages[] = array('id' => 'TASKS_ERROR_EXCEPTION_#' . $errCode, 'text' => 'TASKS_ERROR_EXCEPTION_#' . $errCode . '; ' . $errMsg . '; ' . TasksException::renderErrorCode($e));
         }
     } catch (Exception $e) {
         $errMsg = $e->getMessage();
         if ($errMsg !== '') {
             $arMessages[] = array('text' => $errMsg, 'id' => 'TASKS_ERROR');
         }
     }
     if ($withoutExceptions) {
         return $parsedReturnValue;
     } else {
         self::_emitError($arMessages);
         throw new Exception();
     }
 }
Exemple #8
0
                     foreach ($arChecklistItemsInDb as $oChecklistItem) {
                         if (in_array($oChecklistItem->getId(), $arItemsToRemove)) {
                             $oChecklistItem->delete();
                         }
                     }
                 }
             }
         }
     }
     return $arChecklistItems;
 } else {
     throw new \Bitrix\Main\SystemException();
 }
 $arResult['BLOCKS'] = array_intersect($arWhiteList, $arParams['BLOCKS']);
 if (isset($arParams['TASK_ID']) && isset($arParams['LOAD_TASK_DATA']) && $arParams['LOAD_TASK_DATA'] === 'Y') {
     $oTask = CTaskItem::getInstance($arParams['TASK_ID'], $arResult['LOGGED_IN_USER']);
     $arResult['ALLOWED_ACTIONS'] = $oTask->getAllowedActions($asStrings = true);
     $arResult['TASK'] = $oTask->getData();
     $arResult['TASK']['META:ALLOWED_ACTIONS_CODES'] = $oTask->getAllowedTaskActions();
     $arResult['TASK']['META:ALLOWED_ACTIONS'] = $arResult['ALLOWED_ACTIONS'];
     $arResult['TASK']['META:IN_DAY_PLAN'] = 'N';
     $arResult['TASK']['META:CAN_ADD_TO_DAY_PLAN'] = 'N';
     // Was task created from template?
     if ($arResult['TASK']['FORKED_BY_TEMPLATE_ID']) {
         $rsTemplate = CTaskTemplates::GetByID($arResult['TASK']['FORKED_BY_TEMPLATE_ID']);
         if ($arTemplate = $rsTemplate->Fetch()) {
             $arTemplate['REPLICATE_PARAMS'] = unserialize($arTemplate['REPLICATE_PARAMS']);
             $arResult['TASK']['FORKED_BY_TEMPLATE'] = $arTemplate;
         }
     }
     if (($arResult['TASK']["RESPONSIBLE_ID"] == $arResult['LOGGED_IN_USER'] || in_array($arResult['LOGGED_IN_USER'], $arResult['TASK']['ACCOMPLICES'])) && CModule::IncludeModule("timeman") && (!CModule::IncludeModule('extranet') || !CExtranet::IsExtranetSite())) {
 /**
  * This function will decrements user counters of new tasks when user view task
  */
 public static function onBeforeTaskViewedFirstTime($taskId, $userId, $onTaskAdd)
 {
     $taskId = (int) $taskId;
     $userId = (int) $userId;
     // there is self::onAfterTaskAdd() function process case when task added
     if ($onTaskAdd) {
         return;
     }
     $adminId = self::getAdminId();
     if (!intval($adminId)) {
         return;
     }
     // if task not in statuses CTasks::STATE_PENDING or CTasks::STATE_NEW,
     // than counters of "new tasks" must to have been decremented already (on status change)
     // or not incremented at all (on task creation).
     $oTaskItem = CTaskItem::getInstance($taskId, $adminId);
     $arTask = $oTaskItem->getData($escaped = false);
     if (!self::isNewStatus($arTask['REAL_STATUS'])) {
         return;
     }
     // The task wasn't viewed by user, but will be viewed just now
     // So, we must decrement count of unviewed tasks for this user
     $oTaskItem = CTaskItem::getInstance($taskId, $adminId);
     $arTask = $oTaskItem->getData(false);
     if ($userId == $arTask['RESPONSIBLE_ID']) {
         CTaskCountersQueue::push(CTaskCountersProcessor::COUNTER_TASKS_MY_NEW, CTaskCountersQueue::OP_DECREMENT, array($userId));
     }
     if (isset($arTask['ACCOMPLICES']) && is_array($arTask['ACCOMPLICES'])) {
         if (in_array($userId, $arTask['ACCOMPLICES'])) {
             CTaskCountersQueue::push(CTaskCountersProcessor::COUNTER_TASKS_ACCOMPLICE_NEW, CTaskCountersQueue::OP_DECREMENT, array($userId));
         }
     }
     CTaskCountersQueue::execute();
 }
Exemple #10
0
 function lambda_sgkrg455d_funcCreateSubtasks($arFields, $arAllResponsibles, $index, $loggedInUserId, $woStepper = false, $parameters = array())
 {
     $allResponsiblesCount = count($arAllResponsibles);
     $arResponsibles = array_slice($arAllResponsibles, $index);
     $cutoffTime = microtime(true) + 5;
     foreach ($arResponsibles as $responsible) {
         $arFields['RESPONSIBLE_ID'] = $responsible;
         ++$index;
         try {
             $arFieldsToSave = $arFields;
             // transform UF files
             if (is_array($arFieldsToSave['UF_TASK_WEBDAV_FILES']) && !empty($arFieldsToSave['UF_TASK_WEBDAV_FILES']) && \Bitrix\Main\Loader::includeModule('disk')) {
                 // find which files are new and which are old
                 $old = array();
                 $new = array();
                 foreach ($arFieldsToSave['UF_TASK_WEBDAV_FILES'] as $fileId) {
                     if ((string) $fileId) {
                         if (strpos($fileId, 'n') === 0) {
                             $new[] = $fileId;
                         } else {
                             $old[] = $fileId;
                         }
                     }
                 }
                 if (!empty($old)) {
                     $userFieldManager = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager();
                     $old = $userFieldManager->cloneUfValuesFromAttachedObject($old, $loggedInUserId);
                     if (is_array($old) && !empty($old)) {
                         $new = array_merge($new, $old);
                     }
                 }
                 $arFieldsToSave['UF_TASK_WEBDAV_FILES'] = $new;
             }
             $oTask = CTaskItem::add($arFieldsToSave, $loggedInUserId);
             // Save checklist data
             $GLOBALS['APPLICATION']->IncludeComponent("bitrix:tasks.task.detail.parts", ".default", array('MODE' => 'JUST AFTER TASK CREATED', 'BLOCKS' => array("checklist"), 'TASK_ID' => (int) $oTask->getId()), null, array('HIDE_ICONS' => 'Y'));
             // copy child tasks
             if ($parameters['COPY_PARAMS']['COPY_CHILD_TASKS'] && intval($parameters['COPY_PARAMS']['ORIGIN_TASK'])) {
                 $parentTaskInstance = CTaskItem::getInstance(intval($parameters['COPY_PARAMS']['ORIGIN_TASK']), $loggedInUserId);
                 $parentTaskInstance->duplicateChildTasks($oTask);
                 // task access rights check inside
             }
             // create child tasks by child templates
             if ($parameters['COPY_PARAMS']['COPY_CHILD_TEMPLATES'] && intval($parameters['COPY_PARAMS']['ORIGIN_TEMPLATE'])) {
                 // get template to ensure we own it...
                 $templateData = CTaskTemplates::GetList(false, array('ID' => intval($parameters['COPY_PARAMS']['ORIGIN_TEMPLATE'])), false, array('USER_ID' => $loggedInUserId))->fetch();
                 if (is_array($templateData)) {
                     $oTask->addChildTasksByTemplate(intval($parameters['COPY_PARAMS']['ORIGIN_TEMPLATE']));
                     // task access rights check inside
                 }
             }
         } catch (Exception $e) {
         }
         // Timeout only if multistepper can be used
         if (!$woStepper && microtime(true) > $cutoffTime) {
             break;
         }
     }
     if ($woStepper) {
         $needStep = false;
     } else {
         $needStep = true;
         if ($index >= $allResponsiblesCount) {
             $needStep = false;
         }
     }
     return array($needStep, $index, $allResponsiblesCount);
 }