protected function display() { if (Tools::isConnectedUser()) { // only teamMembers & observers can access this page if (0 == $this->teamid || $this->session_user->isTeamCustomer($this->teamid)) { $this->smartyHelper->assign('accessDenied', TRUE); } else { $team = TeamCache::getInstance()->getTeam($this->teamid); $formatedteamName = str_replace(" ", "_", $team->getName()); // dates $month = date('m'); $year = date('Y'); // The first day of the current month $startdate = Tools::getSecurePOSTStringValue("startdate", Tools::formatDate("%Y-%m-%d", mktime(0, 0, 0, $month, 1, $year))); $this->smartyHelper->assign('startDate', $startdate); $startTimestamp = Tools::date2timestamp($startdate); // The current date plus one year $nbDaysInMonth = date("t", mktime(0, 0, 0, $month, 1, $year)); $enddate = Tools::getSecurePOSTStringValue("enddate", Tools::formatDate("%Y-%m-%d", mktime(23, 59, 59, $month, $nbDaysInMonth, $year))); $this->smartyHelper->assign('endDate', $enddate); $endTimestamp = Tools::date2timestamp($enddate); $endTimestamp += 24 * 60 * 60 - 1; // + 1 day -1 sec. if ('computeCsvMonthly' == $_POST['action']) { $timeTracking = new TimeTracking($startTimestamp, $endTimestamp, $this->teamid); $myFile = Constants::$codevOutputDir . DIRECTORY_SEPARATOR . 'reports' . DIRECTORY_SEPARATOR . $formatedteamName . "_Mantis_" . date("Ymd") . ".csv"; ExportCsvTools::exportManagedIssuesToCSV($this->teamid, $startTimestamp, $endTimestamp, $myFile); $this->smartyHelper->assign('managedIssuesToCSV', basename($myFile)); $myFile = Constants::$codevOutputDir . DIRECTORY_SEPARATOR . 'reports' . DIRECTORY_SEPARATOR . $formatedteamName . "_Projects_" . date("Ymd", $timeTracking->getStartTimestamp()) . "-" . date("Ymd", $timeTracking->getEndTimestamp()) . ".csv"; $this->exportProjectMonthlyActivityToCSV($timeTracking, $myFile); $this->smartyHelper->assign('projectMonthlyActivityToCSV', basename($myFile)); // reduce scope to enhance speed $reports = array(); for ($i = 1; $i <= 12; $i++) { $reports[] = basename(ExportCsvTools::exportHolidaystoCSV($i, $year, $this->teamid, $formatedteamName, Constants::$codevOutputDir . DIRECTORY_SEPARATOR . 'reports')); } $this->smartyHelper->assign('reports', $reports); $this->smartyHelper->assign('reportsDir', Constants::$codevOutputDir . DIRECTORY_SEPARATOR . 'reports'); } } } }
/** * Export week activity * @param int $teamid * @param $weekDates * @param TimeTracking $timeTracking * @param string $myFile * @return string */ private function exportWeekActivityReportToCSV($teamid, $weekDates, $timeTracking, $myFile) { $sepChar = ';'; // create filename & open file $fh = fopen($myFile, 'w'); $stringData = T_("Task") . $sepChar . T_("Job") . $sepChar . T_("Description") . $sepChar . T_("Assigned to") . $sepChar . Tools::formatDate("%A %d/%m", $weekDates[1]) . $sepChar . Tools::formatDate("%A %d/%m", $weekDates[2]) . $sepChar . Tools::formatDate("%A %d/%m", $weekDates[3]) . $sepChar . Tools::formatDate("%A %d/%m", $weekDates[4]) . $sepChar . Tools::formatDate("%A %d/%m", $weekDates[5]) . "\n"; fwrite($fh, $stringData); $query = "SELECT codev_team_user_table.user_id, mantis_user_table.realname " . "FROM `codev_team_user_table`, `mantis_user_table` " . "WHERE codev_team_user_table.team_id = {$teamid} " . "AND codev_team_user_table.user_id = mantis_user_table.id " . "ORDER BY mantis_user_table.realname"; $result = SqlWrapper::getInstance()->sql_query($query); if (!$result) { echo "<span style='color:red'>ERROR: Query FAILED</span>"; exit; } while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) { // if user was working on the project during the timestamp $user = UserCache::getInstance()->getUser($row->user_id); if ($user->isTeamDeveloper($teamid, $timeTracking->getStartTimestamp(), $timeTracking->getEndTimestamp()) || $user->isTeamManager($teamid, $timeTracking->getStartTimestamp(), $timeTracking->getEndTimestamp())) { $this->exportWeekDetailsToCSV($row->user_id, $timeTracking, $user->getShortname(), $fh); } } fclose($fh); return $myFile; }
/** * @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; }
/** * display Timetracking Tuples * @param int $userid * @param TimeTracking $timeTracking * @return mixed[] */ private function getTimetrackingTuples($userid, TimeTracking $timeTracking) { // Display previous entries $query = "SELECT id, bugid, jobid, date, duration" . " FROM `codev_timetracking_table`" . " WHERE userid = {$userid}" . " AND date >= " . $timeTracking->getStartTimestamp() . " ORDER BY date"; $result = SqlWrapper::getInstance()->sql_query($query) or die("Query failed: {$query}"); $jobs = new Jobs(); $timetrackingTuples = array(); while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) { // get information on this bug try { $issue = IssueCache::getInstance()->getIssue($row->bugid); // get general information $jobName = $jobs->getJobName($row->jobid); $formatedDate = Tools::formatDate("%Y-%m-%d", $row->date); $cosmeticDate = Tools::formatDate("%Y-%m-%d - %A", $row->date); $formatedJobName = str_replace("'", "\\'", $jobName); $formatedSummary = str_replace("'", "\\'", $issue->getSummary()); $formatedSummary = str_replace('"', "\\'", $formatedSummary); $formatedSummary = htmlspecialchars(preg_replace('![\\t\\r\\n]+!', ' ', $formatedSummary)); //$totalEstim = $issue->effortEstim + $issue->effortAdd; $timetrackingTuples[$row->id] = array('timestamp' => $row->date, 'date' => $formatedDate, 'formatedId' => $issue->getFormattedIds(), 'duration' => $row->duration, 'formatedJobName' => $formatedJobName, 'summary' => $formatedSummary, 'cosmeticDate' => $cosmeticDate, 'mantisURL' => Tools::mantisIssueURL($row->bugid, NULL, true), 'issueURL' => Tools::issueInfoURL($row->bugid), 'issueId' => $issue->getTcId(), 'projectName' => $issue->getProjectName(), 'issueSummary' => htmlspecialchars(preg_replace('![\\t\\r\\n]+!', ' ', $issue->getSummary())), 'jobName' => $jobName, 'categoryName' => $issue->getCategoryName(), 'currentStatusName' => $issue->getCurrentStatusName()); } catch (Exception $e) { $summary = T_('Error: Task not found in Mantis DB !'); $timetrackingTuples[$row->id] = array('formatedId' => $row->bugid, 'duration' => $row->duration, 'summary' => $summary, 'mantisURL' => '', 'issueURL' => $row->bugid, 'issueId' => '!', 'projectName' => '!', 'issueSummary' => '<span class="error_font">' . $summary . '</span>', 'categoryName' => '!', 'currentStatusName' => '!'); } } $currentTimeTrackingTuples = array(); $futureTimeTrackingTuples = array(); foreach ($timetrackingTuples as $trackId => $timeTrackingTuple) { if ($timeTrackingTuple['timestamp'] <= $timeTracking->getEndTimestamp()) { $currentTimeTrackingTuples[$trackId] = $timeTrackingTuple; } else { $futureTimeTrackingTuples[$trackId] = $timeTrackingTuple; } unset($timeTrackingTuple['timestamp']); } return array("current" => $currentTimeTrackingTuples, "future" => $futureTimeTrackingTuples); }