From 988dcb3947c5e0d347f1002dbee2ff5c5c56e1db Mon Sep 17 00:00:00 2001 From: anuko Date: Sun, 5 Nov 2017 13:14:13 +0000 Subject: [PATCH] Some cleanup in the Period class. --- WEB-INF/lib/Period.class.php | 42 +--------------------------- WEB-INF/lib/ttChartHelper.class.php | 2 +- WEB-INF/lib/ttReportHelper.class.php | 12 ++++---- WEB-INF/lib/ttTimeHelper.class.php | 4 +-- WEB-INF/templates/footer.tpl | 2 +- reports.php | 2 +- 6 files changed, 12 insertions(+), 52 deletions(-) diff --git a/WEB-INF/lib/Period.class.php b/WEB-INF/lib/Period.class.php index 6c1eafe5..5730a75d 100644 --- a/WEB-INF/lib/Period.class.php +++ b/WEB-INF/lib/Period.class.php @@ -114,43 +114,13 @@ class Period { } } - /** - * Return all days by period - * - * @return array - */ - function getAllDays() { - $ret_array = array(); - if ($this->startDate->before($this->endDate)) { - $d = $this->getBegin(); - while ($d->before($this->getEnd())) { - array_push($ret_array, $d); - $d = $d->nextDate(); - } - array_push($ret_array, $d); - } else { - array_push($ret_array, $this->startDate); - } - return $ret_array; - } - function setPeriod($b_date, $e_date) { $this->startDate = $b_date; $this->endDate = $e_date; } - // return date object - function getBegin() { - return $this->startDate; - } - - // return date object - function getEnd() { - return $this->endDate; - } - // return date string - function getBeginDate($format="") { + function getStartDate($format="") { return $this->startDate->toString($format); } @@ -158,14 +128,4 @@ class Period { function getEndDate($format="") { return $this->endDate->toString($format); } - - function getArray($format="") { - $result = array(); - $d = $this->getBegin(); - while ($d->before($this->getEnd())) { - $result[] = $d->toString($format); - $d = $d->nextDate(); - } - return $result; - } } diff --git a/WEB-INF/lib/ttChartHelper.class.php b/WEB-INF/lib/ttChartHelper.class.php index fef7729d..75a38d07 100644 --- a/WEB-INF/lib/ttChartHelper.class.php +++ b/WEB-INF/lib/ttChartHelper.class.php @@ -63,7 +63,7 @@ class ttChartHelper { $q_period = ''; if ($period != null) { - $q_period = " and date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and date <= '".$period->getEndDate(DB_DATEFORMAT)."'"; + $q_period = " and date >= '".$period->getStartDate(DB_DATEFORMAT)."' and date <= '".$period->getEndDate(DB_DATEFORMAT)."'"; } if (CHART_PROJECTS == $chart_type) { // Data for projects. diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index c66cb33a..cfa10794 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -74,7 +74,7 @@ class ttReportHelper { new DateAndTime($user->date_format, $bean->getAttribute('start_date')), new DateAndTime($user->date_format, $bean->getAttribute('end_date'))); } - $where = " where l.status = 1 and l.date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and l.date <= '".$period->getEndDate(DB_DATEFORMAT)."'". + $where = " where l.status = 1 and l.date >= '".$period->getStartDate(DB_DATEFORMAT)."' and l.date <= '".$period->getEndDate(DB_DATEFORMAT)."'". " $user_list_part $dropdown_parts"; return $where; } @@ -125,7 +125,7 @@ class ttReportHelper { new DateAndTime($user->date_format, $report['period_start']), new DateAndTime($user->date_format, $report['period_end'])); } - $where = " where l.status = 1 and l.date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and l.date <= '".$period->getEndDate(DB_DATEFORMAT)."'". + $where = " where l.status = 1 and l.date >= '".$period->getStartDate(DB_DATEFORMAT)."' and l.date <= '".$period->getEndDate(DB_DATEFORMAT)."'". " $user_list_part $dropdown_parts"; return $where; } @@ -164,7 +164,7 @@ class ttReportHelper { new DateAndTime($user->date_format, $bean->getAttribute('start_date')), new DateAndTime($user->date_format, $bean->getAttribute('end_date'))); } - $where = " where ei.status = 1 and ei.date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and ei.date <= '".$period->getEndDate(DB_DATEFORMAT)."'". + $where = " where ei.status = 1 and ei.date >= '".$period->getStartDate(DB_DATEFORMAT)."' and ei.date <= '".$period->getEndDate(DB_DATEFORMAT)."'". " $user_list_part $dropdown_parts"; return $where; } @@ -211,7 +211,7 @@ class ttReportHelper { new DateAndTime($user->date_format, $report['period_start']), new DateAndTime($user->date_format, $report['period_end'])); } - $where = " where ei.status = 1 and ei.date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and ei.date <= '".$period->getEndDate(DB_DATEFORMAT)."'". + $where = " where ei.status = 1 and ei.date >= '".$period->getStartDate(DB_DATEFORMAT)."' and ei.date <= '".$period->getEndDate(DB_DATEFORMAT)."'". " $user_list_part $dropdown_parts"; return $where; } @@ -945,7 +945,7 @@ class ttReportHelper { new DateAndTime($user->date_format, $bean->getAttribute('end_date'))); } - $totals['start_date'] = $period->getBeginDate(); + $totals['start_date'] = $period->getStartDate(); $totals['end_date'] = $period->getEndDate(); $totals['time'] = $total_time; $totals['cost'] = $total_cost; @@ -1015,7 +1015,7 @@ class ttReportHelper { new DateAndTime($user->date_format, $report['period_end'])); } - $totals['start_date'] = $period->getBeginDate(); + $totals['start_date'] = $period->getStartDate(); $totals['end_date'] = $period->getEndDate(); $totals['time'] = $total_time; $totals['cost'] = $total_cost; diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index 13a2d83d..02faa216 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -499,7 +499,7 @@ class ttTimeHelper { $mdb2 = getConnection(); $period = new Period(INTERVAL_THIS_WEEK, $date); - $sql = "select sum(time_to_sec(duration)) as sm from tt_log where user_id = $user_id and date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and date <= '".$period->getEndDate(DB_DATEFORMAT)."' and status = 1"; + $sql = "select sum(time_to_sec(duration)) as sm from tt_log where user_id = $user_id and date >= '".$period->getStartDate(DB_DATEFORMAT)."' and date <= '".$period->getEndDate(DB_DATEFORMAT)."' and status = 1"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { $val = $res->fetchRow(); @@ -514,7 +514,7 @@ class ttTimeHelper { $mdb2 = getConnection(); $period = new Period(INTERVAL_THIS_MONTH, $date); - $sql = "select sum(time_to_sec(duration)) as sm from tt_log where user_id = $user_id and date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and date <= '".$period->getEndDate(DB_DATEFORMAT)."' and status = 1"; + $sql = "select sum(time_to_sec(duration)) as sm from tt_log where user_id = $user_id and date >= '".$period->getStartDate(DB_DATEFORMAT)."' and date <= '".$period->getEndDate(DB_DATEFORMAT)."' and status = 1"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { $val = $res->fetchRow(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 14adb75a..823659e6 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.12.2.3682 | Copyright © Anuko | +  Anuko Time Tracker 1.12.2.3683 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/reports.php b/reports.php index 1b91b231..69e74235 100644 --- a/reports.php +++ b/reports.php @@ -225,7 +225,7 @@ if (($request->getMethod() == 'GET') && !$bean->isSaved()) { // No previous form data were found in session. Use the following default values. $form->setValueByElement('users', array_keys($user_list)); $period = new Period(INTERVAL_THIS_MONTH, new DateAndTime($user->date_format)); - $form->setValueByElement('start_date', $period->getBeginDate()); + $form->setValueByElement('start_date', $period->getStartDate()); $form->setValueByElement('end_date', $period->getEndDate()); $form->setValueByElement('chclient', '1'); $form->setValueByElement('chinvoice', '0'); -- 2.20.1