Beispiel #1
0
 /**
  * Get days for each users
  * @param int $month The month
  * @param int $year The year
  * @param int $teamid The team
  * @param User[] $users The users (User[id])
  * @param int $nbDaysInMonth The number of days in a month
  * @param bool $isExternalTasks True if external tasks wanted, else false
  * @return mixed[string]
  */
 function getDaysUsers($month, $year, $teamid, array $users, $nbDaysInMonth, $filters)
 {
     $holidays = Holidays::getInstance();
     $isExternalTasks = $filters['isExternalTasks'];
     $isSidetasksInactivity = $filters['isSidetasksInactivity'];
     $startT = mktime(0, 0, 0, $month, 1, $year);
     $endT = mktime(23, 59, 59, $month, $nbDaysInMonth, $year);
     $smartyUsers = array();
     foreach ($users as $user) {
         // if user was working on the project within the timestamp
         if ($user->isTeamDeveloper($teamid, $startT, $endT) || $user->isTeamManager($teamid, $startT, $endT)) {
             $arrivalDate = $user->getArrivalDate($teamid);
             $departureDate = $user->getDepartureDate($teamid);
             $timeTracks = $user->getTimeTracks($startT, $endT);
             $issueIds = array();
             foreach ($timeTracks as $timeTrack) {
                 $issueIds[] = $timeTrack->getIssueId();
             }
             $daysOf = $user->getDaysOfInPeriod($timeTracks, $issueIds, $teamid);
             $astreintes = $user->getOnDutyTaskInMonth($teamid, $timeTracks, $issueIds);
             $externalTasks = $user->getExternalTasksInPeriod($timeTracks, $issueIds);
             $days = array();
             for ($i = 1; $i <= $nbDaysInMonth; $i++) {
                 $timestamp = mktime(0, 0, 0, $month, $i, $year);
                 if ($timestamp < $arrivalDate || 0 != $departureDate && $timestamp > $departureDate) {
                     $days[$i] = array("color" => 'D8D8D8', "title" => T_('User not in team'));
                 } elseif (isset($externalTasks[$timestamp]) && NULL != $externalTasks[$timestamp]) {
                     // always show inactivity tasks,
                     // other externalTasks must only be displayed if $isExternalTasks
                     if ('Inactivity' == $externalTasks[$timestamp]['type'] || $isExternalTasks) {
                         $days[$i] = array("color" => $externalTasks[$timestamp]['color'], "align" => true, "title" => htmlentities($externalTasks[$timestamp]['title']), "value" => $externalTasks[$timestamp]['duration']);
                     }
                 } elseif (isset($astreintes[$timestamp]) && NULL != $astreintes[$timestamp]) {
                     $days[$i] = array("color" => $astreintes[$timestamp]['color'], "align" => true, "value" => $astreintes[$timestamp]['duration'], "title" => htmlentities(T_($astreintes[$timestamp]['type'])));
                 } elseif (isset($daysOf[$timestamp]) && NULL != $daysOf[$timestamp]) {
                     if ($isSidetasksInactivity) {
                         $days[$i] = array("color" => $daysOf[$timestamp]['color'], "align" => true, "title" => htmlentities($daysOf[$timestamp]['title']), "value" => $daysOf[$timestamp]['duration']);
                     }
                 }
                 if (!isset($days[$i])) {
                     // If weekend or holiday, display gray
                     $timestamp = mktime(0, 0, 0, $month, $i, $year);
                     $h = $holidays->isHoliday($timestamp);
                     if (NULL != $h) {
                         $days[$i] = array("color" => $h->color, "title" => htmlentities($h->description));
                     } else {
                         $days[$i] = array();
                     }
                 }
             }
             $smartyUsers[$user->getId()] = array('realname' => $user->getRealname(), 'username' => $user->getName(), 'days' => $days);
         }
     }
     return $smartyUsers;
 }
 public function getSmartyVariables($isAjaxCall = false)
 {
     $totalLoad = 0;
     foreach ($this->execData as $duration) {
         $totalLoad += $duration;
     }
     // table data
     $tableData = array('projectLoad' => $this->execData, 'totalLoad' => $totalLoad, 'workdays' => Holidays::getInstance()->getWorkdays($this->startTimestamp, $this->endTimestamp));
     // ------------------------
     // pieChart data
     $jqplotData = Tools::array2plot($this->execData);
     $smartyVariables = array('loadPerProjectIndicator_tableData' => $tableData, 'loadPerProjectIndicator_jqplotData' => empty($jqplotData) ? NULL : $jqplotData, 'loadPerProjectIndicator_startDate' => Tools::formatDate("%Y-%m-%d", $this->startTimestamp), 'loadPerProjectIndicator_endDate' => Tools::formatDate("%Y-%m-%d", $this->endTimestamp));
     if (false == $isAjaxCall) {
         $smartyVariables['loadPerProjectIndicator_ajaxFile'] = self::getSmartySubFilename();
         $smartyVariables['loadPerProjectIndicator_ajaxPhpURL'] = self::getAjaxPhpURL();
     }
     return $smartyVariables;
 }
Beispiel #3
0
 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);
             // if first call to this page
             if (!array_key_exists('nextForm', $_POST)) {
                 $activeMembers = $team->getActiveMembers();
                 if ($this->session_user->isTeamManager($this->teamid)) {
                     $this->smartyHelper->assign('users', SmartyTools::getSmartyArray($activeMembers, $this->session_userid));
                 } else {
                     // developper & manager can add timeTracks
                     if (array_key_exists($this->session_userid, $activeMembers)) {
                         $_POST['userid'] = $this->session_userid;
                         $_POST['nextForm'] = "addHolidaysForm";
                         //$_POST['days'] = 'dayid';
                     }
                 }
             }
             $nextForm = Tools::getSecurePOSTStringValue('nextForm', '');
             if ($nextForm == "addHolidaysForm") {
                 $userid = Tools::getSecurePOSTIntValue('userid', $this->session_userid);
                 $managed_user = UserCache::getInstance()->getUser($userid);
                 // dates
                 $startdate = Tools::getSecurePOSTStringValue('startdate', date("Y-m-d"));
                 $enddate = Tools::getSecurePOSTStringValue('enddate', '');
                 $defaultBugid = Tools::getSecurePOSTIntValue('bugid', 0);
                 $action = Tools::getSecurePOSTStringValue('action', '');
                 $duration = Tools::getSecurePOSTNumberValue('duree', 0);
                 if ("addHolidays" == $action) {
                     // TODO add tracks !
                     $job = Tools::getSecurePOSTStringValue('job');
                     $duration = Tools::getSecurePOSTNumberValue('duree');
                     $holydays = Holidays::getInstance();
                     $keyvalue = Tools::getSecurePOSTStringValue('checkedDays');
                     $checkedDaysList = Tools::doubleExplode(':', ',', $keyvalue);
                     $startTimestamp = Tools::date2timestamp($startdate);
                     $endTimestamp = Tools::date2timestamp($enddate);
                     // save to DB
                     $weekday = date('l', strtotime($startdate));
                     $timestamp = $startTimestamp;
                     while ($timestamp <= $endTimestamp) {
                         // check if not a fixed holiday
                         if (!$holydays->isHoliday($timestamp)) {
                             // check existing timetracks on $timestamp and adjust duration
                             $availabletime = $managed_user->getAvailableTime($timestamp);
                             // not imput more than possible
                             if ($duration >= $availabletime) {
                                 $imput = $availabletime;
                             } else {
                                 $imput = $duration;
                             }
                             // check if weekday checkbox is checked
                             if (1 == $checkedDaysList[$weekday]) {
                                 if ($duration > 0) {
                                     if (self::$logger->isDebugEnabled()) {
                                         self::$logger->debug(date("Y-m-d", $timestamp) . " duration {$imput} job {$job}");
                                     }
                                     TimeTrack::create($managed_user->getId(), $defaultBugid, $job, $timestamp, $imput, $this->session_userid);
                                 }
                             }
                         }
                         $timestamp = strtotime("+1 day", $timestamp);
                         $weekday = date('l', strtotime(date("Y-m-d", $timestamp)));
                     }
                     // We redirect to holidays report, so the user can verify his holidays
                     header('Location:holidays_report.php');
                 }
                 $this->smartyHelper->assign('startDate', $startdate);
                 $this->smartyHelper->assign('endDate', $enddate);
                 if ($this->session_userid != $managed_user->getId()) {
                     $this->smartyHelper->assign('otherrealname', $managed_user->getRealname());
                 }
                 // Get Team SideTasks Project List
                 $projList = $team->getProjects(true, false);
                 foreach ($projList as $pid => $pname) {
                     // we want only SideTasks projects
                     try {
                         if (!$team->isSideTasksProject($pid)) {
                             unset($projList[$pid]);
                         }
                     } catch (Exception $e) {
                         self::$logger->error("project {$pid}: " . $e->getMessage());
                     }
                 }
                 $extproj_id = Config::getInstance()->getValue(Config::id_externalTasksProject);
                 $extProj = ProjectCache::getInstance()->getProject($extproj_id);
                 $projList[$extproj_id] = $extProj->getName();
                 $defaultProjectid = Tools::getSecurePOSTIntValue('projectid', 0);
                 if ($defaultBugid != 0 && $action == 'setBugId') {
                     // find ProjectId to update categories
                     $issue = IssueCache::getInstance()->getIssue($defaultBugid);
                     $defaultProjectid = $issue->getProjectId();
                 }
                 $this->smartyHelper->assign('projects', SmartyTools::getSmartyArray($projList, $defaultProjectid));
                 $this->smartyHelper->assign('issues', $this->getIssues($defaultProjectid, $projList, $extproj_id, $defaultBugid));
                 $this->smartyHelper->assign('jobs', $this->getJobs($defaultProjectid, $projList));
                 $this->smartyHelper->assign('duration', SmartyTools::getSmartyArray(TimeTrackingTools::getDurationList($team->getId()), $duration));
                 $this->smartyHelper->assign('userid', $managed_user->getId());
             }
         }
     }
 }
Beispiel #4
0
 /**
  * @param int $month
  * @param int $year
  * @param Issue $issue The issue
  * @param TimeTrack[] $trackList
  * @return mixed[]
  */
 private function getMonth($month, $year, Issue $issue, array $trackList)
 {
     $totalDuration = 0;
     // if no work done this month, do not display month
     $found = 0;
     foreach ($trackList as $tt) {
         if ($month == date('m', $tt->getDate()) && $year == date('Y', $tt->getDate())) {
             $found += 1;
             $totalDuration += $tt->getDuration();
         }
     }
     if (0 == $found) {
         return NULL;
     }
     $monthTimestamp = mktime(0, 0, 0, $month, 1, $year);
     $monthFormated = Tools::formatDate("%B %Y", $monthTimestamp);
     $nbDaysInMonth = date("t", $monthTimestamp);
     $months = array();
     for ($i = 1; $i <= $nbDaysInMonth; $i++) {
         if ($i < 10) {
             $months[] = "0" . $i;
         } else {
             $months[] = $i;
         }
     }
     $jobs = new Jobs();
     $userList = $issue->getInvolvedUsers();
     $users = NULL;
     $timeTracks = $issue->getTimeTracks();
     foreach ($userList as $uid => $username) {
         $userTotalDuration = 0;
         // build $durationByDate[] for this user
         $durationByDate = array();
         $jobColorByDate = array();
         foreach ($timeTracks as $tt) {
             if ($tt->getUserId() == $uid) {
                 $date = $tt->getDate();
                 if (array_key_exists($date, $durationByDate)) {
                     $durationByDate[$date] += $tt->getDuration();
                 } else {
                     $durationByDate[$date] = $tt->getDuration();
                 }
                 $jobColorByDate[$date] = $jobs->getJobColor($tt->getJobId());
             }
         }
         $usersDetails = NULL;
         for ($i = 1; $i <= $nbDaysInMonth; $i++) {
             $todayTimestamp = mktime(0, 0, 0, $month, $i, $year);
             if (array_key_exists($todayTimestamp, $durationByDate)) {
                 $userTotalDuration += $durationByDate[$todayTimestamp];
                 $usersDetails[] = array("jobColor" => $jobColorByDate[$todayTimestamp], "jobDuration" => $durationByDate[$todayTimestamp]);
             } else {
                 // if weekend or holiday, display gray
                 $holidays = Holidays::getInstance();
                 $h = $holidays->isHoliday($todayTimestamp);
                 if (NULL != $h) {
                     $usersDetails[] = array("jobColor" => Holidays::$defaultColor, "jobDescription" => $h->description);
                 } else {
                     $usersDetails[] = array();
                 }
             }
         }
         $users[] = array("username" => $username, "jobs" => $usersDetails, 'totalDuration' => 0 == $userTotalDuration ? '' : $userTotalDuration);
     }
     return array("monthFormated" => $monthFormated, "totalDuration" => $totalDuration, "months" => $months, "users" => $users);
 }
Beispiel #5
0
 /**
  * Find days which are not 'sat' or 'sun' or FixedHoliday and that have no timeTrack entry.
  * @param int $userid
  * @return number[]
  */
 public function checkMissingDays($userid)
 {
     $holidays = Holidays::getInstance();
     $missingDays = array();
     $user1 = UserCache::getInstance()->getUser($userid);
     // REM: if $this->team_id not set, then team_id = -1
     if ($this->team_id >= 0) {
         if (!$user1->isTeamDeveloper($this->team_id, $this->startTimestamp, $this->endTimestamp) && !$user1->isTeamManager($this->team_id, $this->startTimestamp, $this->endTimestamp)) {
             // User was not yet present
             return $missingDays;
         }
         $arrivalTimestamp = $user1->getArrivalDate($this->team_id);
         $departureTimestamp = $user1->getDepartureDate($this->team_id);
     } else {
         $arrivalTimestamp = $user1->getArrivalDate();
         $departureTimestamp = $user1->getDepartureDate();
     }
     // reduce timestamp if needed
     $startT = $arrivalTimestamp > $this->startTimestamp ? $arrivalTimestamp : $this->startTimestamp;
     $endT = $this->endTimestamp;
     if (0 != $departureTimestamp && $departureTimestamp < $this->endTimestamp) {
         $endT = $departureTimestamp;
     }
     $weekTimestamps = array();
     $timestamp = $startT;
     while ($timestamp <= $endT) {
         // monday to friday
         if (NULL == $holidays->isHoliday($timestamp)) {
             $weekTimestamps[] = $timestamp;
         }
         $timestamp = strtotime("+1 day", $timestamp);
     }
     if (count($weekTimestamps) > 0) {
         $query = "SELECT DISTINCT date " . "FROM `codev_timetracking_table` " . "WHERE userid = {$userid} AND date IN (" . implode(', ', $weekTimestamps) . ");";
         $result = SqlWrapper::getInstance()->sql_query($query);
         if (!$result) {
             echo "<span style='color:red'>ERROR: Query FAILED</span>";
             exit;
         }
         $daysWithTimeTracks = array();
         while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
             $daysWithTimeTracks[] = $row->date;
         }
         $missingDays = array_diff($weekTimestamps, $daysWithTimeTracks);
     }
     return $missingDays;
 }
Beispiel #6
0
 /**
  * @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;
 }
 public function getSmartyVariables($isAjaxCall = false)
 {
     $usersActivities = array();
     $totalLeave = 0;
     $totalExternal = 0;
     $totalElapsed = 0;
     $totalOther = 0;
     $totalSidetask = 0;
     foreach ($this->execData as $userid => $userActivity) {
         $user = UserCache::getInstance()->getUser($userid);
         $usersActivities[$user->getName()] = $userActivity;
         if (array_key_exists('leave', $userActivity)) {
             $totalLeave += $userActivity['leave'];
         }
         if (array_key_exists('external', $userActivity)) {
             $totalExternal += $userActivity['external'];
         }
         if (array_key_exists('elapsed', $userActivity)) {
             $totalElapsed += $userActivity['elapsed'];
         }
         if (array_key_exists('other', $userActivity)) {
             $totalOther += $userActivity['other'];
         }
         if ($this->showSidetasks && array_key_exists('sidetask', $userActivity)) {
             $totalSidetask += $userActivity['sidetask'];
         }
     }
     $totalActivity = array();
     $totalActivity['leave'] = $totalLeave;
     $totalActivity['external'] = $totalExternal;
     $totalActivity['elapsed'] = $totalElapsed;
     $totalActivity['other'] = $totalOther;
     if ($this->showSidetasks) {
         $totalActivity['sidetask'] += $totalSidetask;
     }
     ksort($usersActivities);
     // table data
     $tableData = array('usersActivities' => $usersActivities, 'totalActivity' => $totalActivity, 'workdays' => Holidays::getInstance()->getWorkdays($this->startTimestamp, $this->endTimestamp));
     // ------------------------
     // pieChart data
     $jqplotData = array(T_('Elapsed') => $totalActivity['elapsed'], T_('Other') => $totalActivity['other'], T_('External') => $totalActivity['external'], T_('Inactivity') => $totalActivity['leave']);
     $formatedColors = array("#92C5FC", "#C2DFFF", "#75FFDA", "#A8FFBD");
     if ($this->showSidetasks) {
         $jqplotData[T_('Waste')] = $totalActivity['sidetask'];
         $formatedColors[] = "#FFF494";
     } else {
     }
     $seriesColors = '["' . implode('","', $formatedColors) . '"]';
     // ["#FFCD85","#C2DFFF"]
     $smartyVariables = array('loadPerUserIndicator_tableData' => $tableData, 'loadPerUserIndicator_jqplotData' => empty($jqplotData) ? NULL : Tools::array2json($jqplotData), 'loadPerUserIndicator_colors' => $formatedColors, 'loadPerUserIndicator_jqplotSeriesColors' => $seriesColors, 'loadPerUserIndicator_startDate' => Tools::formatDate("%Y-%m-%d", $this->startTimestamp), 'loadPerUserIndicator_endDate' => Tools::formatDate("%Y-%m-%d", $this->endTimestamp));
     if (false == $isAjaxCall) {
         $smartyVariables['loadPerUserIndicator_ajaxFile'] = self::getSmartySubFilename();
         $smartyVariables['loadPerUserIndicator_ajaxPhpURL'] = self::getAjaxPhpURL();
     }
     return $smartyVariables;
 }
Beispiel #8
0
 /**
  * Returns the Estimated Date of Arrival, depending on user's holidays and other timetracks
  *
  * @param int $beginTimestamp              the start day
  * @param int $availTimeOnBeginTimestamp   On the start day, part of the day may already have
  *                                     been spent on other issues. this param defines how much
  *                                     time is left for this issue.
  *                                     if NULL, use user->getAvailableTime($beginTimestamp)
  * @param int $userid                      if NULL, use assignedTo user
  * @return mixed[] array(endTimestamp, $availTimeOnEndTimestamp)
  *          $availTimeOnEndTimestamp can be re-injected in the next call to this function
  */
 public function computeEstimatedDateOfArrival($beginTimestamp, $availTimeOnBeginTimestamp = NULL, $userid = NULL)
 {
     // find user in charge of this issue
     if (NULL != $userid) {
         $user = UserCache::getInstance()->getUser($userid);
     } else {
         if (NULL != $this->getHandlerId()) {
             $user = UserCache::getInstance()->getUser($this->getHandlerId());
         } else {
             // issue not assigned to anybody
             $user = NULL;
         }
     }
     // we need to be absolutely sure that time is 00:00:00
     $timestamp = mktime(0, 0, 0, date("m", $beginTimestamp), date("d", $beginTimestamp), date("Y", $beginTimestamp));
     $tmpDuration = $this->getDuration();
     if (self::$logger->isDebugEnabled()) {
         self::$logger->debug("computeEstimatedDateOfArrival: user="******" tmpDuration = {$tmpDuration} begindate=" . date('Y-m-d', $timestamp));
     }
     // first day depends only on $availTimeOnBeginTimestamp
     if (NULL == $availTimeOnBeginTimestamp) {
         $availTime = $user->getAvailableTime($timestamp);
     } else {
         $availTime = $availTimeOnBeginTimestamp;
     }
     $tmpDuration -= $availTime;
     if (self::$logger->isDebugEnabled()) {
         self::$logger->debug("computeEstimatedDateOfArrival: 1st " . date('Y-m-d', $timestamp) . " tmpDuration (-{$availTime}) = {$tmpDuration}");
     }
     // --- next days
     while ($tmpDuration > 0) {
         $timestamp = strtotime("+1 day", $timestamp);
         if (NULL != $user) {
             $availTime = $user->getAvailableTime($timestamp);
             $tmpDuration -= $availTime;
             if (self::$logger->isDebugEnabled()) {
                 self::$logger->debug("computeEstimatedDateOfArrival: " . date('Y-m-d', $timestamp) . " tmpDuration = {$tmpDuration}");
             }
         } else {
             // if not assigned, just check for global holidays
             if (NULL == Holidays::getInstance()->isHoliday($timestamp)) {
                 $tmpDuration -= 1;
                 // it's not a holiday, so complete day available.
             }
         }
     }
     $endTimestamp = $timestamp;
     // if $tmpDuration < 0 this means that this issue will be finished before
     // the end of the day. So the backlog time must be reported to be available
     // fot the next issue to be worked on.
     $availTimeOnEndTimestamp = abs($tmpDuration);
     if (self::$logger->isDebugEnabled()) {
         self::$logger->debug("computeEstimatedDateOfArrival: {$this->bugId}.computeEstimatedEndTimestamp(" . date('Y-m-d', $beginTimestamp) . ", {$availTimeOnBeginTimestamp}, {$userid}) = [" . date('Y-m-d', $endTimestamp) . ",{$availTimeOnEndTimestamp}]");
     }
     return array($endTimestamp, $availTimeOnEndTimestamp);
 }
Beispiel #9
0
 /**
  * @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);
 }