コード例 #1
0
ファイル: team_activity_report.php プロジェクト: fg-ok/codev
 /**
  * @param TimeTracking $timeTracking
  * @param bool $isDetailed
  * @param int[] $weekDates
  * @return mixed[]
  */
 private function getWeekDetails(TimeTracking $timeTracking, $isDetailed, $weekDates, $session_userid)
 {
     $team = TeamCache::getInstance()->getTeam($timeTracking->getTeamid());
     $weekDetails = array();
     $session_users = $team->getUsers();
     foreach ($session_users as $session_user) {
         // if user was working on the project during the timestamp
         if ($session_user->isTeamDeveloper($timeTracking->getTeamid(), $timeTracking->getStartTimestamp(), $timeTracking->getEndTimestamp()) || $session_user->isTeamManager($timeTracking->getTeamid(), $timeTracking->getStartTimestamp(), $timeTracking->getEndTimestamp())) {
             // PERIOD week
             //$thisWeekId=date("W");
             $weekTracks = $timeTracking->getWeekDetails($session_user->getId(), !$isDetailed);
             $holidays = Holidays::getInstance();
             $weekJobDetails = array();
             foreach ($weekTracks as $bugid => $jobList) {
                 try {
                     $issue = IssueCache::getInstance()->getIssue($bugid);
                 } catch (Exception $e) {
                     self::$logger->error("getWeekDetails() skip issue {$bugid} : " . $e->getMessage());
                     $weekJobDetails[] = array("description" => '<span class="error_font">' . $bugid . ' : ' . T_('Error: Task not found in Mantis DB !') . '</span>', "duration" => "!", "progress" => "!", "projectName" => "!", "targetVersion" => "!", "jobName" => "!", "daysDetails" => "!", "totalDuration" => "!");
                     continue;
                 }
                 $project = ProjectCache::getInstance()->getProject($issue->getProjectId());
                 if ($isDetailed) {
                     $formatedJobList = implode(', ', array_keys($jobList));
                     $query = 'SELECT id, name FROM `codev_job_table` WHERE id IN (' . $formatedJobList . ');';
                     $result2 = SqlWrapper::getInstance()->sql_query($query);
                     if (!$result2) {
                         continue;
                     }
                     while ($row2 = SqlWrapper::getInstance()->sql_fetch_object($result2)) {
                         $jobName = $row2->name;
                         $dayList = $jobList[$row2->id];
                         $daysDetails = array();
                         $weekDuration = 0;
                         for ($i = 1; $i <= 7; $i++) {
                             $dayDetails = $this->getDaysDetails($i, $holidays, $weekDates, $dayList[$i]);
                             $weekDuration += $dayDetails['duration'];
                             $daysDetails[] = $dayDetails;
                         }
                         if (!$project->isSideTasksProject(array($team->getId())) && !$project->isExternalTasksProject()) {
                             $tooltipAttr = $issue->getTooltipItems($team->getId(), $session_userid);
                             // force some fields
                             #$tooltipAttr[T_('Elapsed')] = $issue->getElapsed();
                             #$tooltipAttr[T_('Backlog')] = $issue->getDuration();
                             #$tooltipAttr[T_('Drift')] = $issue->getDrift();
                             #$tooltipAttr[T_('DriftColor')] = $issue->getDriftColor();
                             $infoTooltip = Tools::imgWithTooltip('images/b_info.png', $tooltipAttr);
                         } else {
                             $infoTooltip = NULL;
                         }
                         // prepare json data for the IssueNoteDialogbox
                         $issueNoteData = $this->getIssueNoteTooltip($project, $team, $issue);
                         $weekJobDetails[] = array('description' => SmartyTools::getIssueDescription($bugid, $issue->getTcId(), $issue->getSummary()), 'duration' => $issue->getDuration(), 'progress' => round(100 * $issue->getProgress()), 'projectName' => $issue->getProjectName(), 'targetVersion' => $issue->getTargetVersion(), 'jobName' => $jobName, 'daysDetails' => $daysDetails, 'totalDuration' => $weekDuration, 'infoTooltip' => $infoTooltip, 'issueNoteId' => $issueNoteData['id'], 'noteTooltip' => $issueNoteData['tooltip']);
                     }
                 } else {
                     // for each day, concat jobs duration
                     $daysDetails = array();
                     $weekDuration = 0;
                     for ($i = 1; $i <= 7; $i++) {
                         $duration = 0;
                         foreach ($jobList as $dayList) {
                             if (array_key_exists($i, $dayList)) {
                                 $duration += $dayList[$i];
                             }
                         }
                         if ($duration == 0) {
                             $duration = "";
                         }
                         $dayDetails = $this->getDaysDetails($i, $holidays, $weekDates, $duration);
                         $weekDuration += $dayDetails['duration'];
                         $daysDetails[] = $dayDetails;
                     }
                     if (!$project->isSideTasksProject(array($team->getId())) && !$project->isExternalTasksProject()) {
                         $tooltipAttr = $issue->getTooltipItems($team->getId(), $session_userid);
                         // force some fields
                         #$tooltipAttr[T_('Elapsed')] = $issue->getElapsed();
                         #$tooltipAttr[T_('Backlog')] = $issue->getDuration();
                         #$tooltipAttr[T_('Drift')] = $issue->getDrift();
                         #$tooltipAttr[T_('DriftColor')] = $issue->getDriftColor();
                         $infoTooltip = Tools::imgWithTooltip('images/b_info.png', $tooltipAttr);
                     } else {
                         $infoTooltip = NULL;
                     }
                     // prepare json data for the IssueNoteDialogbox
                     $issueNoteData = $this->getIssueNoteTooltip($project, $team, $issue);
                     $weekJobDetails[] = array('description' => SmartyTools::getIssueDescription($bugid, $issue->getTcId(), $issue->getSummary()), 'duration' => $issue->getDuration(), 'progress' => round(100 * $issue->getProgress()), 'projectName' => $issue->getProjectName(), 'daysDetails' => $daysDetails, 'totalDuration' => $weekDuration, 'infoTooltip' => $infoTooltip, 'issueNoteId' => $issueNoteData['id'], 'noteTooltip' => $issueNoteData['tooltip']);
                 }
             }
             if (!empty($weekJobDetails)) {
                 $weekDetails[] = array('name' => $session_user->getName(), 'realname' => $session_user->getRealname(), 'forecastWorkload' => $session_user->getForecastWorkload(), 'weekDates' => array(Tools::formatDate("%A\n%d %b", $weekDates[1]), Tools::formatDate("%A\n%d %b", $weekDates[2]), Tools::formatDate("%A\n%d %b", $weekDates[3]), Tools::formatDate("%A\n%d %b", $weekDates[4]), Tools::formatDate("%A\n%d %b", $weekDates[5])), 'weekEndDates' => array(Tools::formatDate("%A\n%d %b", $weekDates[6]), Tools::formatDate("%A\n%d %b", $weekDates[7])), 'weekJobDetails' => $weekJobDetails);
             }
         }
     }
     return $weekDetails;
 }
コード例 #2
0
ファイル: export_csv_weekly.php プロジェクト: fg-ok/codev
 /**
  * @param int $userid
  * @param TimeTracking $timeTracking
  * @param string $realname
  * @param resource $fh
  */
 private function exportWeekDetailsToCSV($userid, TimeTracking $timeTracking, $realname, $fh)
 {
     $sepChar = ';';
     $weekTracks = $timeTracking->getWeekDetails($userid);
     foreach ($weekTracks as $bugid => $jobList) {
         try {
             $issue = IssueCache::getInstance()->getIssue($bugid);
             // remove sepChar from summary text
             $formatedSummary = str_replace($sepChar, " ", $issue->getSummary());
             foreach ($jobList as $jobid => $dayList) {
                 $query = "SELECT name FROM `codev_job_table` WHERE id={$jobid}";
                 $result = SqlWrapper::getInstance()->sql_query($query);
                 if (!$result) {
                     echo "<span style='color:red'>ERROR: Query FAILED</span>";
                     exit;
                 }
                 $jobName = SqlWrapper::getInstance()->sql_result($result, 0);
                 $stringData = $bugid . $sepChar . $jobName . $sepChar . $formatedSummary . $sepChar . $realname . $sepChar;
                 for ($i = 1; $i <= 4; $i++) {
                     if (array_key_exists($i, $dayList)) {
                         $stringData .= $dayList[$i];
                     }
                     $stringData .= $sepChar;
                 }
                 if (array_key_exists(5, $dayList)) {
                     $stringData .= $dayList[5];
                 }
                 $stringData .= "\n";
                 fwrite($fh, $stringData);
             }
         } catch (Exception $e) {
             self::$logger->error('exportWeekDetailsToCSV(): issue $bugid not found in mantis DB !');
         }
     }
 }
コード例 #3
0
ファイル: time_tracking_tools.php プロジェクト: fg-ok/codev
 /**
  * @param int[] $weekDates
  * @param int $userid
  * @param TimeTracking $timeTracking
  * @param array $incompleteDays
  * @return mixed[]
  */
 public static function getWeekTask(array $weekDates, $teamid, $userid, TimeTracking $timeTracking, array $incompleteDays)
 {
     $totalElapsed = array();
     $todayAtMidnight = mktime(0, 0, 0);
     for ($i = 1; $i <= 7; $i++) {
         $weekDate = $weekDates[$i];
         $totalElapsed[$weekDate] = array("elapsed" => 0, "class" => in_array($weekDate, $incompleteDays) && $weekDate < $todayAtMidnight ? "incompleteDay" : "");
     }
     $jobs = new Jobs();
     $weekTasks = NULL;
     $holidays = Holidays::getInstance();
     $weekTracks = $timeTracking->getWeekDetails($userid);
     foreach ($weekTracks as $bugid => $jobList) {
         try {
             $issue = IssueCache::getInstance()->getIssue($bugid);
             $backlog = $issue->getBacklog();
             $extRef = $issue->getTcId();
             $summary = $issue->getSummary();
             $description = SmartyTools::getIssueDescription($bugid, $extRef, $summary);
             $projectId = $issue->getProjectId();
         } catch (Exception $e) {
             $backlog = '!';
             $extRef = '';
             $summary = '<span class="error_font">' . T_('Error: Task not found in Mantis DB !') . '</span>';
             //$description = SmartyTools::getIssueDescription($bugid,$extRef,$summary);
             $description = Tools::mantisIssueURL($bugid, NULL, TRUE) . ' ' . $bugid . ' : ' . $summary;
             $projectId = -1;
         }
         foreach ($jobList as $jobid => $dayList) {
             // if no backlog set, display a '?' to allow Backlog edition
             if (is_numeric($backlog)) {
                 $formattedBacklog = $backlog;
                 // prepare json data for the BacklogDialogbox
                 $jsonIssueInfo = self::getUpdateBacklogJsonData($bugid, $jobid, $teamid, $userid);
             } else {
                 #if (($team->isSideTasksProject($issue->projectId)) ||
                 #    ($team->isNoStatsProject($issue->projectId))) {
                 // do not allow to edit sideTasks Backlog
                 $formattedBacklog = '';
                 $jsonIssueInfo = '';
                 #} else {
                 #   $formattedBacklog = '?';
                 #}
                 //
             }
             $dayTasks = "";
             for ($i = 1; $i <= 7; $i++) {
                 $title = NULL;
                 $bgColor = NULL;
                 if ($i <= 5) {
                     $h = $holidays->isHoliday($weekDates[$i]);
                     if ($h) {
                         $bgColor = $h->color;
                         #$bgColor = Holidays::$defaultColor;
                         $title = $h->description;
                     }
                 } else {
                     $bgColor = Holidays::$defaultColor;
                 }
                 $day = 0;
                 if (array_key_exists($i, $dayList)) {
                     $day = $dayList[$i];
                 }
                 $dayTasks[] = array('bgColor' => $bgColor, 'title' => $title, 'day' => $day);
                 $totalElapsed[$weekDates[$i]]['elapsed'] += $day;
             }
             /*          
                         $deadline = $issue->getDeadLine();
             
                         if (!is_null($deadline) || (0 != $deadline)) {
                            $formatedDate = Tools::formatDate(T_("%Y-%m-%d"), $deadline);
                         }
             */
             try {
                 $project = ProjectCache::getInstance()->getProject($projectId);
             } catch (Exception $e) {
                 $project = null;
             }
             if ($project != null) {
                 if (!$project->isSideTasksProject(array($teamid)) && !$project->isExternalTasksProject()) {
                     // TODO does $issue belong to current team's project ? what if not ?
                     $tooltipAttr = $issue->getTooltipItems($teamid, $userid);
                     $infoTooltip = Tools::imgWithTooltip('images/b_info.png', $tooltipAttr);
                 } else {
                     $infoTooltip = '';
                 }
             } else {
                 $infoTooltip = '';
             }
             // prepare json data for the IssueNoteDialogbox
             if ($project != null) {
                 if (!$project->isSideTasksProject(array($teamid)) && !$project->isExternalTasksProject()) {
                     $issueNote = IssueNote::getTimesheetNote($issue->getId());
                     if (!is_null($issueNote)) {
                         $issueNoteId = $issueNote->getId();
                         $user = UserCache::getInstance()->getUser($issueNote->getReporterId());
                         $rawNote = $issueNote->getText();
                         $note = trim(IssueNote::removeAllReadByTags($rawNote));
                         // used for the tooltip NOT the dialoBox
                         $tooltipAttr = array('reporter' => $user->getRealname(), 'date' => date('Y-m-d H:i:s', $issueNote->getLastModified()), 'Note' => $note);
                         $readByList = $issueNote->getReadByList(TRUE);
                         if (0 != count($readByList)) {
                             $tooltipAttr['Read by'] = implode(', ', array_keys($readByList));
                         }
                         $noteTooltip = Tools::imgWithTooltip('images/b_note.png', $tooltipAttr, NULL, 'js-add-note-link', ' style="cursor: pointer;" data-bugId="' . $issueNote->getBugId() . '"');
                     } else {
                         $issueNoteId = 0;
                         $noteTooltip = Tools::imgWithTooltip('images/b_note_grey.png', T_('Click to add a note'), NULL, 'js-add-note-link', ' style="cursor: pointer;" data-bugId="' . $issue->getId() . '"');
                     }
                 } else {
                     $noteTooltip = '';
                 }
             } else {
                 $noteTooltip = '';
             }
             // if project not declared in current team, then
             // user cannot add a timetrack by clicking in the weekTasks table
             // Note: (this would generate an error on addTimetrack)
             $team = TeamCache::getInstance()->getTeam($teamid);
             $isTeamProject = !is_null($team->getProjectType($projectId));
             $weekTasks[$bugid . "_" . $jobid] = array('bugid' => $bugid, 'description' => $description, 'formattedBacklog' => $formattedBacklog, 'jobid' => $jobid, 'jobName' => $jobs->getJobName($jobid), 'dayTasks' => $dayTasks, 'infoTooltip' => $infoTooltip, 'summary' => addslashes(htmlspecialchars($summary)), 'updateBacklogJsonData' => $jsonIssueInfo, 'issueNoteId' => $issueNoteId, 'noteTooltip' => $noteTooltip, 'isTeamProject' => $isTeamProject);
         }
     }
     return array("weekTasks" => $weekTasks, "totalElapsed" => $totalElapsed);
 }