Skip to content

Commit

Permalink
fix the progress not returning plus dont sum just compare againts pre…
Browse files Browse the repository at this point in the history
Bearded Avenger committed Jul 6, 2015
1 parent 34e7f6f commit 8a331c3
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions includes/class.db.php
Original file line number Diff line number Diff line change
@@ -63,25 +63,32 @@ public function update_progress( $args = array() ) {

global $wpdb;

$new_progress = $args['percent'];
$old_progress = cgc_video_tracking_get_user_progress( $args['user_id'], $args['video_id'] );
$progress = ( (float) $old_progress + (float) $args['percent'] );
$old_progress = $old_progress ? $old_progress[0] : false;

if ( $progress > 95.0 ) {
return;
$update = false;

// if we're at 100% dont record anymore
if ( $old_progress > 100.0 ) {
return false;
}

$update = $wpdb->query(
$wpdb->update(
$this->table,
array(
'percent' => filter_var( $progress, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION )
),
array(
'user_id' => absint( $args['user_id'] ),
'video_id' => sanitize_text_field( $args['video_id'] )
if ( $new_progress >= $old_progress ) {

$update = $wpdb->query(
$wpdb->update(
$this->table,
array(
'percent' => filter_var( $new_progress, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION )
),
array(
'user_id' => absint( $args['user_id'] ),
'video_id' => sanitize_text_field( $args['video_id'] )
)
)
)
);
);
}

return $update ? $update : false;
}

0 comments on commit 8a331c3

Please sign in to comment.