Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.swp
._*
.DS_Store
27 changes: 25 additions & 2 deletions Timecard/Timecard.API.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TimecardBug {
public $timecard;
public $estimate;
public $timestamp;
public $timestamp_updates;

public $updates;
public $spent;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

}

/**
Expand Down Expand Up @@ -340,7 +363,7 @@ function save() {
$this->bug_id,
$this->bugnote_id,
$this->user_id,
$this->timestamp,
$this->timestamp = db_now(),
$this->spent,
) );

Expand Down
58 changes: 51 additions & 7 deletions Timecard/Timecard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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'
" ) ),
);
}

Expand All @@ -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;
}

5 changes: 3 additions & 2 deletions Timecard/lang/strings_english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<span class="negative">%d hours overrun</span>)';
$s_plugin_Timecard_estimate_display = '%01.1f hours total (%01.1f hours remaining)';
$s_plugin_Timecard_estimate_over = '%01.1f hours total (<span class="negative">%01.1f hours overrun</span>)';
$s_plugin_Timecard_time_spent = 'Time Spent';
$s_plugin_Timecard_hours_remaining = 'Hours Remaining';
$s_plugin_Timecard_total_remaining = 'Total Hours Remaining';
Expand Down Expand Up @@ -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';

2 changes: 1 addition & 1 deletion Timecard/lang/strings_german.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion Timecard/pages/log_time.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
9 changes: 8 additions & 1 deletion Timecard/pages/view_timecard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down