3 * FusionForge reporting system
5 * Copyright 2003-2004, Tim Perdue/GForge, LLC
6 * Copyright 2009, Roland Mas
7 * Copyright 2013, Franck Villaume - TrivialDev
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'reporting/Report.class.php';
27 class ReportTrackerAct extends Report {
34 function ReportTrackerAct($span,$group_id,$atid,$start=0,$end=0) {
37 $group = group_get_object($group_id);
38 $at = new ArtifactType($group, $atid);
40 if ($at->isPermissionDeniedError()) {
41 exit_permission_denied('','tracker');
43 exit_error($at->getErrorMessage(),'tracker');
47 // Set start date from the project date.
49 $start=mktime(0,0,0,date('m'),1,date('Y')-1);
59 $this->setError('No group_id');
62 if (!$span || $span == REPORT_TYPE_MONTHLY) {
64 $arr =& $this->getMonthStartArr();
66 for ($i=0; $i<count($arr); $i++) {
67 if ($arr[$i]<$start || $arr[$i]>$end) {
68 //skip this month as it's not in the range
71 $this->labels[]=date('M d',$arr[$i]).' <-> '.date('M d',($arr[$i-1]-1));
72 $this->avgtime[]=$this->getAverageTime($atid,$arr[$i],($arr[$i-1]-1));
73 $this->opencount[]=$this->getOpenCount($atid,$arr[$i],($arr[$i-1]-1));
74 $this->stillopencount[]=$this->getStillOpenCount($atid,$arr[$i],($arr[$i-1]-1));
79 } elseif ($span == REPORT_TYPE_WEEKLY) {
81 $arr =& $this->getWeekStartArr();
83 for ($i=0; $i<count($arr); $i++) {
84 if ($arr[$i]<$start || $arr[$i]>$end) {
85 //skip this month as it's not in the range
88 $this->labels[]=date('M d',$arr[$i]).' <-> '.date('M d',($arr[$i-1]-1));
89 $this->avgtime[]=$this->getAverageTime($atid,$arr[$i],($arr[$i-1]-1));
90 $this->opencount[]=$this->getOpenCount($atid,$arr[$i],($arr[$i-1]-1));
91 $this->stillopencount[]=$this->getStillOpenCount($atid,$arr[$i],($arr[$i-1]-1));
98 $this->start_date=$start;
101 $this->setSpan($span);
102 $this->setDates($arr, 1);
107 function getAverageTime($atid,$start,$end) {
108 $res = db_query_params ('SELECT avg((close_date-open_date)/(24*60*60)) AS avgtime
110 WHERE group_artifact_id=$1
112 AND open_date BETWEEN $2 AND $3',
116 return db_result($res,0,0);
119 function getOpenCount($atid,$start,$end) {
120 $res = db_query_params ('SELECT count(*)
124 AND open_date BETWEEN $2 AND $3',
128 return db_result($res,0,0);
131 function getStillOpenCount($atid,$start,$end) {
132 $res = db_query_params ('SELECT count(*)
137 AND (close_date >= $3 OR close_date < 1 OR close_date is null)',
139 $end, // Yes, really.
141 return db_result($res,0,0);
144 function &getAverageTimeData() {
145 return $this->avgtime;
148 function &getOpenCountData() {
149 return $this->opencount;
152 function &getStillOpenCountData() {
153 return $this->stillopencount;
160 // c-file-style: "bsd"