public static function onAfterTMEntryUpdate($id, $arFields) { $needStopTimer = false; if (!(isset($arFields['USER_ID']) && $arFields['USER_ID'] > 0)) { return; } if ($arFields['PAUSED'] === 'Y') { $needStopTimer = true; } elseif (isset($arFields['DATE_FINISH'], $arFields['TIME_FINISH'])) { if ($arFields['DATE_FINISH'] !== false && $arFields['TIME_FINISH'] !== false) { $needStopTimer = true; } } if ($needStopTimer) { $oTimer = CTaskTimerManager::getInstance($arFields['USER_ID']); $oTimer->stop(); } }
function tasksRenderJSON($arTask, $childrenCount, $arPaths, $bParent = false, $bGant = false, $top = false, $nameTemplate = "", $arAdditionalFields = array(), $bSkipJsMenu = false) { global $USER; $arAllowedTaskActions = array(); if (isset($arTask['META:ALLOWED_ACTIONS'])) { $arAllowedTaskActions = $arTask['META:ALLOWED_ACTIONS']; } elseif ($arTask['ID']) { $oTask = CTaskItem::getInstanceFromPool($arTask['ID'], $USER->getId()); $arAllowedTaskActions = $oTask->getAllowedTaskActionsAsStrings(); $arTask['META:ALLOWED_ACTIONS'] = $arAllowedTaskActions; } $runningTaskId = $runningTaskTimer = null; if ($arTask['ALLOW_TIME_TRACKING'] === 'Y') { $oTimer = CTaskTimerManager::getInstance($USER->getId()); $runningTaskData = $oTimer->getRunningTask(false); $runningTaskId = $runningTaskData['TASK_ID']; $runningTaskTimer = time() - $runningTaskData['TIMER_STARTED_AT']; } ?> { id : <?php echo $arTask["ID"]; ?> , name : "<?php echo CUtil::JSEscape($arTask["TITLE"]); ?> ", <?php if ($arTask["GROUP_ID"]) { ?> projectId : <?php echo $arTask["GROUP_ID"]; ?> , projectName : '<?php echo CUtil::JSEscape($arTask['GROUP_NAME']); ?> ', <?php } ?> status : "<?php echo tasksStatus2String($arTask["STATUS"]); ?> ", realStatus : "<?php echo $arTask["REAL_STATUS"]; ?> ", url: '<?php echo CUtil::JSEscape(CComponentEngine::MakePathFromTemplate($arPaths["PATH_TO_TASKS_TASK"], array("task_id" => $arTask["ID"], "action" => "view"))); ?> ', details: window.top.onDetails, priority : <?php echo $arTask["PRIORITY"]; ?> , mark : <?php echo !$arTask["MARK"] ? "null" : "'" . $arTask["MARK"] . "'"; ?> , responsible: '<?php echo CUtil::JSEscape(tasksFormatNameShort($arTask["RESPONSIBLE_NAME"], $arTask["RESPONSIBLE_LAST_NAME"], $arTask["RESPONSIBLE_LOGIN"], $arTask["RESPONSIBLE_SECOND_NAME"], $nameTemplate)); ?> ', director: '<?php echo CUtil::JSEscape(tasksFormatNameShort($arTask["CREATED_BY_NAME"], $arTask["CREATED_BY_LAST_NAME"], $arTask["CREATED_BY_LOGIN"], $arTask["CREATED_BY_SECOND_NAME"], $nameTemplate)); ?> ', responsibleId : <?php echo $arTask["RESPONSIBLE_ID"]; ?> , directorId : <?php echo $arTask["CREATED_BY"]; ?> , responsible_name: '<?php echo CUtil::JSEscape($arTask["RESPONSIBLE_NAME"]); ?> ', responsible_second_name: '<?php echo CUtil::JSEscape($arTask["RESPONSIBLE_SECOND_NAME"]); ?> ', responsible_last_name: '<?php echo CUtil::JSEscape($arTask["RESPONSIBLE_LAST_NAME"]); ?> ', responsible_login: '******', director_name: '<?php echo CUtil::JSEscape($arTask["CREATED_BY_NAME"]); ?> ', director_second_name: '<?php echo CUtil::JSEscape($arTask["CREATED_BY_SECOND_NAME"]); ?> ', director_last_name: '<?php echo CUtil::JSEscape($arTask["CREATED_BY_LAST_NAME"]); ?> ', director_login: '******', dateCreated : <?php tasksJSDateObject($arTask["CREATED_DATE"], $top); ?> , <?php if ($arTask["START_DATE_PLAN"]) { ?> dateStart : <?php tasksJSDateObject($arTask["START_DATE_PLAN"], $top); ?> ,<?php } else { ?> dateStart: null,<?php } ?> <?php if ($arTask["END_DATE_PLAN"]) { ?> dateEnd : <?php tasksJSDateObject($arTask["END_DATE_PLAN"], $top); ?> ,<?php } else { ?> dateEnd: null,<?php } ?> <?php if ($arTask["DATE_START"]) { ?> dateStarted: <?php tasksJSDateObject($arTask["DATE_START"], $top); ?> ,<?php } ?> dateCompleted : <?php if ($arTask["CLOSED_DATE"]) { tasksJSDateObject($arTask["CLOSED_DATE"], $top); } else { ?> null<?php } ?> , <?php if ($arTask["DEADLINE"]) { ?> dateDeadline : <?php tasksJSDateObject($arTask["DEADLINE"], $top); ?> ,<?php } else { ?> dateDeadline: null,<?php } ?> canEditPlanDates : <?php if ($arAllowedTaskActions['ACTION_EDIT']) { ?> true<?php } else { ?> false<?php } ?> , <?php if ($arTask["PARENT_ID"] && $bParent) { ?> parentTaskId : <?php echo $arTask["PARENT_ID"]; ?> , <?php } ?> <?php if (sizeof($arTask["FILES"])) { $i = 0; ?> files: [ <?php foreach ($arTask["FILES"] as $file) { $i++; ?> { name : '<?php echo CUtil::JSEscape($file["ORIGINAL_NAME"]); ?> ', url : '/bitrix/components/bitrix/tasks.task.detail/show_file.php?fid=<?php echo $file["ID"]; ?> ', size : '<?php echo CUtil::JSEscape(CFile::FormatSize($file["FILE_SIZE"])); ?> ' }<?php if ($i != sizeof($arTask["FILES"])) { ?> ,<?php } ?> <?php } ?> ], <?php } ?> <?php if (count($arTask['ACCOMPLICES']) > 0) { $i = 0; echo 'accomplices: ['; foreach ($arTask['ACCOMPLICES'] as $ACCOMPLICE_ID) { if ($i++) { echo ','; } echo '{ id: ' . (int) $ACCOMPLICE_ID . ' }'; } echo '], '; } ?> <?php if (count($arTask['AUDITORS']) > 0) { $i = 0; echo 'auditors: ['; foreach ($arTask['AUDITORS'] as $AUDITOR_ID) { if ($i++) { echo ','; } echo '{ id: ' . (int) $AUDITOR_ID . ' }'; } echo '], '; } ?> isSubordinate: <?php echo $arTask["SUBORDINATE"] == "Y" ? "true" : "false"; ?> , isInReport: <?php echo $arTask["ADD_IN_REPORT"] == "Y" ? "true" : "false"; ?> , hasChildren : <?php if ((int) $childrenCount > 0) { echo 'true'; } else { echo 'false'; } ?> , childrenCount : <?php echo (int) $childrenCount; ?> , canEditDealine : <?php if ($arAllowedTaskActions['ACTION_EDIT'] || $arAllowedTaskActions['ACTION_CHANGE_DEADLINE']) { echo 'true'; } else { echo 'false'; } ?> , canStartTimeTracking : <?php if ($arAllowedTaskActions['ACTION_START_TIME_TRACKING']) { ?> true<?php } else { ?> false<?php } ?> , ALLOW_TIME_TRACKING : <?php if (isset($arTask['ALLOW_TIME_TRACKING']) && $arTask['ALLOW_TIME_TRACKING'] === 'Y') { echo 'true'; } else { echo 'false'; } ?> , TIMER_RUN_TIME : <?php if ($runningTaskId == $arTask['ID']) { echo (int) $runningTaskTimer; } else { echo 'false'; } ?> , TIME_SPENT_IN_LOGS : <?php echo (int) $arTask['TIME_SPENT_IN_LOGS']; ?> , TIME_ESTIMATE : <?php echo (int) $arTask['TIME_ESTIMATE']; ?> , IS_TASK_TRACKING_NOW : <?php if ($runningTaskId == $arTask['ID']) { echo 'true'; } else { echo 'false'; } ?> , menuItems: [<?php tasksGetItemMenu($arTask, $arPaths, SITE_ID, $bGant, $top, $bSkipJsMenu); ?> ] <?php foreach ($arAdditionalFields as $key => $value) { echo ', ' . $key . ' : ' . $value . "\n"; } ?> } <?php }
protected static function getTimemanCloseDayData($arParams) { if (CModule::IncludeModule('timeman')) { global $USER; $arTasks = array(); $userId = $USER->getId(); $runningTaskId = null; $taskRunTime = null; // key features of that info: // [REPORT_REQ] => 'A' means that day will be closed right now. other variants - just form show. // [INFO][DATE_START] => 1385459336 - unix timestamp of day start // [INFO][TIME_START] => 46136 - short timestamp of day start // [DURATION] // [TIME_LEAKS] $arTimemanInfo = CTimeMan::GetRunTimeInfo(true); if (!($userId > 0)) { foreach ($arTimemanInfo['PLANNER']['DATA']['TASKS'] as $arTask) { $arTask['TIME'] = 0; $arTasks[] = $arTask; } return array('TASKS' => $arTasks); } $unixTsDateStart = (int) $arTimemanInfo['INFO']['DATE_START']; $oTimer = CTaskTimerManager::getInstance($userId); $arTimer = $oTimer->getLastTimer(); if ($arTimer && $arTimer['TIMER_STARTED_AT'] > 0) { $runningTaskId = $arTimer['TASK_ID']; if ($arTimer['TIMER_STARTED_AT'] >= $unixTsDateStart) { $taskRunTime = max(0, time() - (int) $arTimer['TIMER_STARTED_AT']); } else { $taskRunTime = max(0, time() - $unixTsDateStart); } } $bitrixTimestampDateStart = $unixTsDateStart + CTasksTools::getTimeZoneOffset(); $dateStartAsString = ConvertTimeStamp($bitrixTimestampDateStart, 'FULL'); foreach ($arTimemanInfo['PLANNER']['DATA']['TASKS'] as $arTask) { $rsElapsedTime = CTaskElapsedTime::getList(array('ID' => 'ASC'), array('TASK_ID' => $arTask['ID'], 'USER_ID' => $userId, '>=CREATED_DATE' => $dateStartAsString), array('skipJoinUsers' => true)); $arTask['TIME'] = 0; while ($arElapsedTime = $rsElapsedTime->fetch()) { $arTask['TIME'] += max(0, $arElapsedTime['SECONDS']); } if ($runningTaskId && $arTask['ID'] == $runningTaskId) { $arTask['TIME'] += $taskRunTime; } $arTasks[] = $arTask; } return array('TASKS' => $arTasks); } }
$arResult['ITEMS'][$index]['ALLOWED_ACTIONS'] = $dataItem['ALLOWED_ACTIONS']; } elseif (isset($dataItem['TASK']['META:ALLOWED_ACTIONS'])) { $arResult['ITEMS'][$index]['ALLOWED_ACTIONS'] = $dataItem['TASK']['META:ALLOWED_ACTIONS']; } elseif ($dataItem['TASK']['ID']) { $oTask = CTaskItem::getInstanceFromPool($dataItem['TASK']['ID'], $loggedInUser); $arResult['ITEMS'][$index]['ALLOWED_ACTIONS'] = $oTask->getAllowedTaskActionsAsStrings(); } if ($dataItem["TASK"]['ALLOW_TIME_TRACKING'] === 'Y') { if ($dataItem['TASK']['TIME_ESTIMATE'] > 0 && $arResult['ITEMS'][$index]['CURRENT_TASK_SPENT_TIME'] > $dataItem['TASK']['TIME_ESTIMATE']) { $arResult['ITEMS'][$index]['TASK_TIMER_OVERDUE'] = 'Y'; } else { $arResult['ITEMS'][$index]['TASK_TIMER_OVERDUE'] = 'N'; } // Lazy load timer data only once if ($oTimer === null) { $oTimer = CTaskTimerManager::getInstance($loggedInUser); $arTimer = $oTimer->getRunningTask(false); // false => allow use static cache $arResult['TIMER'] = $arTimer; } if ($arTimer !== false && $arTimer['TASK_ID'] == $dataItem['TASK']['ID']) { $arResult['ITEMS'][$index]['CURRENT_TASK_TIMER_RUN_FOR_USER'] = '******'; } else { $arResult['ITEMS'][$index]['CURRENT_TASK_TIMER_RUN_FOR_USER'] = '******'; } if ($arResult['ITEMS'][$index]['CURRENT_TASK_TIMER_RUN_FOR_USER'] === 'Y' || $arResult['ITEMS'][$index]['ALLOWED_ACTIONS']['ACTION_START_TIME_TRACKING'] || $arResult['ITEMS'][$index]['TASK']['ALLOW_TIME_TRACKING'] === 'Y') { $arResult['ITEMS'][$index]['SHOW_TIMER_NODE'] = 'Y'; } else { $arResult['ITEMS'][$index]['SHOW_TIMER_NODE'] = 'N'; } }
$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())) { $arResult['TASK']['META:CAN_ADD_TO_DAY_PLAN'] = 'Y'; $arTasksInPlan = CTaskPlannerMaintance::getCurrentTasksList(); // If in day plan already if (is_array($arTasksInPlan) && in_array($arResult['TASK']["ID"], $arTasksInPlan)) { $arResult['TASK']['META:IN_DAY_PLAN'] = 'Y'; $arResult['TASK']['META:CAN_ADD_TO_DAY_PLAN'] = 'N'; } } } if (isset($arParams['TASK_ID']) && (in_array('buttons', $arResult['BLOCKS']) || in_array('right_sidebar', $arResult['BLOCKS']))) { if (!isset($arParams['TIMER'])) { $oTimer = CTaskTimerManager::getInstance($arResult['LOGGED_IN_USER']); $arTimer = $oTimer->getLastTimer(false); $arResult['TIMER'] = $arTimer; } else { $arResult['TIMER'] = $arParams['TIMER']; } if ($arResult['TIMER'] !== false && $arResult['TIMER']['TIMER_STARTED_AT'] > 0 && $arResult['TIMER']['TASK_ID'] == $arParams['TASK_ID']) { $arResult['TIMER_IS_RUNNING_FOR_CURRENT_USER'] = '******'; } else { $arResult['TIMER_IS_RUNNING_FOR_CURRENT_USER'] = '******'; } if ($arResult['TIMER_IS_RUNNING_FOR_CURRENT_USER'] === 'Y' || $arResult['ALLOWED_ACTIONS']['ACTION_START_TIME_TRACKING'] || $arResult['TASK']['ALLOW_TIME_TRACKING'] === 'Y') { $arResult['SHOW_TIMER_NODE'] = 'Y'; } else { $arResult['SHOW_TIMER_NODE'] = 'N'; }