diff --git a/.gitignore b/.gitignore index 1377554..207784c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *.swp +._* +.DS_Store diff --git a/Timecard/Timecard.API.php b/Timecard/Timecard.API.php index 32d54f5..6b334e6 100644 --- a/Timecard/Timecard.API.php +++ b/Timecard/Timecard.API.php @@ -22,6 +22,7 @@ class TimecardBug { public $timecard; public $estimate; public $timestamp; + public $timestamp_updates; public $updates; public $spent; @@ -30,7 +31,7 @@ class TimecardBug { * Create a new TimecardBug object. * @param int Bug ID * @param string Timecard string - * @param int Estimate of hours required + * @param float Estimate of hours required */ function __construct( $p_bug_id, $p_timecard='', $p_estimate=-1 ) { $this->bug_id = $p_bug_id < 0 ? 0 : $p_bug_id; @@ -187,6 +188,28 @@ function calculate() { } } + /** + * Calculate last timestamp of updates. + */ + function calculateTimestampUpdates() { + $this->load_updates(); + + $this->timestamp_updates = $this->timestamp; + foreach ( $this->updates as $t_update ) { + if ($t_update->timestamp > $this->timestamp_updates) + $this->timestamp_updates = $t_update->timestamp; + } + } + + /** + * Get last timestamp of updates. + */ + function getTimestampUpdates() { + if (is_null($this->timestamp_updates)) + $this->calculateTimestampUpdates(); + return $this->timestamp_updates; + } + } /** @@ -340,7 +363,7 @@ function save() { $this->bug_id, $this->bugnote_id, $this->user_id, - $this->timestamp, + $this->timestamp = db_now(), $this->spent, ) ); diff --git a/Timecard/Timecard.php b/Timecard/Timecard.php index fcbec62..eb8ff67 100644 --- a/Timecard/Timecard.php +++ b/Timecard/Timecard.php @@ -126,7 +126,7 @@ function report_bug( $p_event, $p_data, $p_bug_id ) { if ( is_blank( $t_estimate ) ) { $t_bug->estimate = -1; } else { - $t_bug->estimate = gpc_get_int( 'plugin_timecard_estimate', 0 ); + $t_bug->estimate = gpc_get_float( 'plugin_timecard_estimate', 0 ); } } @@ -193,12 +193,14 @@ function update_bug( $p_event, $p_bug_data, $p_bug_id ) { $t_bug = TimecardBug::load( $p_bug_id, true ); if ( $t_use_estimates ) { - $t_estimate = gpc_get_string( 'plugin_timecard_estimate', '' ); + $t_estimate = gpc_get_float( 'plugin_timecard_estimate', '' ); - if ( !is_numeric( $t_estimate ) ) { - $t_bug->estimate = -1; + if ( !is_float( $t_estimate ) ) { + if (gpc_isset($t_estimate)) { + $t_bug->estimate = -1; + } } else { - $t_bug->estimate = gpc_get_int( 'plugin_timecard_estimate', 0 ); + $t_bug->estimate = gpc_get_float( 'plugin_timecard_estimate', 0 ); } } @@ -349,7 +351,7 @@ function bugnote_add( $p_event, $p_bug_id, $p_bugnote_id ) { return; } - $f_spent = gpc_get_int( 'plugin_timecard_spent', 0 ); + $f_spent = gpc_get_float( 'plugin_timecard_spent', 0 ); if ( $f_spent > 0 ) { $t_update = new TimecardUpdate( $p_bug_id, $p_bugnote_id, auth_get_current_user_id(), $f_spent ); $t_update->save(); @@ -389,7 +391,7 @@ function bugnote_edit( $p_event, $p_bug_id, $p_bugnote_id ) { } $f_update_id = gpc_get_int( 'plugin_timecard_id', 0 ); - $f_spent = gpc_get_int( 'plugin_timecard_spent', 0 ); + $f_spent = gpc_get_float( 'plugin_timecard_spent', 0 ); if ( $f_update_id > 0 ) { $t_update = TimecardUpdate::load( $f_update_id ); @@ -469,6 +471,15 @@ function schema() { array( 'AddColumnSQL', array( plugin_table( 'estimate' ), " timestamp I NOTNULL DEFAULT '0' " ) ), + array( 'AlterColumnSQL', array( plugin_table( 'estimate' ), " + estimate F(15,2) NOTNULL DEFAULT '0' + " ) ), + array( 'AlterColumnSQL', array( plugin_table( 'update' ), " + spent F(15,2) NOTNULL DEFAULT '0' + " ) ), + array( 'AlterColumnSQL', array( plugin_table( 'update' ), " + timestamp I NOTNULL DEFAULT '0' + " ) ), ); } @@ -486,3 +497,36 @@ function add_columns() { } } +/** + * Retrieve an integer GPC variable. Uses gpc_get(). + * If you pass in *no* default, an error will be triggered if + * the variable does not exist + * @param string $p_var_name + * @param float $p_default (optional) + * @return float|null + */ +function gpc_get_float( $p_var_name, $p_default = null ) { + # Don't pass along a default unless one was given to us + # otherwise we prevent an error being triggered + $args = func_get_args(); + $t_result = call_user_func_array( 'gpc_get', $args ); + + if( is_array( $t_result ) ) { + error_parameters( $p_var_name ); + trigger_error( ERROR_GPC_ARRAY_UNEXPECTED, ERROR ); + } + $t_val = str_replace( ' ', '', trim( $t_result ) ); + $t_val = str_replace( ',', '.', trim( $t_result ) ); + + if ($t_val != (string)(float)$t_val) { + if (!is_null($p_default) && $p_default === $t_val) + { + return $t_val; + } + error_parameters( $p_var_name ); + trigger_error( ERROR_GPC_NOT_NUMBER, ERROR ); + } + + return (float) $t_val; +} + diff --git a/Timecard/lang/strings_english.txt b/Timecard/lang/strings_english.txt index 97582ab..1a09b2b 100644 --- a/Timecard/lang/strings_english.txt +++ b/Timecard/lang/strings_english.txt @@ -20,8 +20,8 @@ $s_plugin_Timecard_default_timecard = 'Default Timecard'; $s_plugin_Timecard_timecard = 'Timecard'; $s_plugin_Timecard_estimate = 'Time Estimate'; $s_plugin_Timecard_estimate_zero = 'No estimate'; -$s_plugin_Timecard_estimate_display = '%d hours total (%d hours remaining)'; -$s_plugin_Timecard_estimate_over = '%d hours total (%d hours overrun)'; +$s_plugin_Timecard_estimate_display = '%01.1f hours total (%01.1f hours remaining)'; +$s_plugin_Timecard_estimate_over = '%01.1f hours total (%01.1f hours overrun)'; $s_plugin_Timecard_time_spent = 'Time Spent'; $s_plugin_Timecard_hours_remaining = 'Hours Remaining'; $s_plugin_Timecard_total_remaining = 'Total Hours Remaining'; @@ -50,4 +50,5 @@ $s_plugin_Timecard_estimate_removed = 'Time Estimate Removed'; $s_plugin_Timecard_time_spent_added = 'Time Spent Added'; $s_plugin_Timecard_time_spent_updated = 'Time Spent Updated'; $s_plugin_Timecard_time_spent_removed = 'Time Spent Removed'; +$s_plugin_Timecard_unknown = 'Unknown'; diff --git a/Timecard/lang/strings_german.txt b/Timecard/lang/strings_german.txt index 8511a2d..545bd50 100644 --- a/Timecard/lang/strings_german.txt +++ b/Timecard/lang/strings_german.txt @@ -51,4 +51,4 @@ $s_plugin_Timecard_estimate_removed = 'Zeitschätzung entfernt'; $s_plugin_Timecard_time_spent_added = 'Verbrauchte Zeit hinzugefügt'; $s_plugin_Timecard_time_spent_updated = 'Verbrauchte Zeit aktualisiert'; $s_plugin_Timecard_time_spent_removed = 'Verbrauchte Zeit entfernt'; - +$s_plugin_Timecard_unknown = 'Unbekannt'; diff --git a/Timecard/pages/log_time.php b/Timecard/pages/log_time.php index b585760..4fb2ca2 100644 --- a/Timecard/pages/log_time.php +++ b/Timecard/pages/log_time.php @@ -14,7 +14,7 @@ form_security_validate( 'plugin_Timecard_log_time' ); $f_bug_id = gpc_get_int( 'bug_id' ); -$f_spent = gpc_get_int( 'spent', 0 ); +$f_spent = gpc_get_float( 'spent', 0 ); access_ensure_bug_level( plugin_config_get( 'update_threshold' ), $f_bug_id ); diff --git a/Timecard/pages/view_timecard.php b/Timecard/pages/view_timecard.php index 61d94a1..ab38f5e 100644 --- a/Timecard/pages/view_timecard.php +++ b/Timecard/pages/view_timecard.php @@ -105,7 +105,14 @@ } $t_timecard->status = MantisEnum::getLabel( config_get( 'status_enum_string' ), $t_row['status'] ); - $t_timecard->diff = time_get_diff( $t_timecard->timestamp ); + $timestamp = $t_timecard->getTimestampUpdates(); + if (!empty($timestamp)) { + $t_timecard->diff = time_get_diff( $timestamp ); + } + else + { + $t_timecard->diff = plugin_lang_get('unknown'); + } if( $t_timecard->estimate < 0 ){ $t_timecard->estimate = plugin_lang_get( 'estimate_zero' );