gocodebox / lifterlms

LifterLMS, a WordPress LMS Solution: Easily create, sell, and protect engaging online courses.
https://lifterlms.com
GNU General Public License v3.0
181 stars 135 forks source link

Add a filter to allow rounding of course progress when output for display only #727

Open thomasplevy opened 5 years ago

thomasplevy commented 5 years ago

When using the course progress shortcode, widget, block, template you should be able to specify rounding precision via a filter

foepsen commented 5 years ago

Hi Thomas! Just wanted to know if this enhancement is scheduled meanwhile? Or if not: Do you have an idea for a workaround like just round up/down the result just for displying it?

Maybe it is possible to edit the var $percentage via PHP_ROUND_HALF_UP an set it to "0" decimals? Any idea if this could be reached via the LifterLMS customization plugin?

Thanks, foepsen

thomasplevy commented 5 years ago

@foepsen this issue is to provide a way to filter rounding precision only when displaying the progress on screen.

There's no easy way (or specific filter) to filter only in this one condition.

However, you can use the general filter on the LLMS_Student::get_progress() method: https://developer.lifterlms.com/reference/classes/llms_student/get_progress/

EG:

add_filter( 'llms_student_get_progress', function( $progress ) { return round( $progress ); } );

This issue aims to add a filter on the llms_get_progress_bar_html() method which displays the progress

Pull requests welcome if you're requiring this sooner than "future"

foepsen commented 5 years ago

Hi @thomasplevy ! Thanks for your quick reply. I added this filter via the customization plugin and it works like a charme! Did I get it right that this filter is only affecting the displayed results while the original result stored in the DB is still a floating number? On the other hand adding the Mode PHP_ROUND_HALF_UP should prevent the case that users aren't able to finish a course because of the rounded result even if the rounded result is stored in the DB. As long as they reach sth between 99.1% and 99.9%, they would finish it with 100%...

Here is what I added finally:

add_filter( 'llms_student_get_progress', function( $progress ) { 
return round( $progress, 0, PHP_ROUND_HALF_UP); } );

Unfortunately I am not a developer so it is not possible for me to add this as a pull request - especially not with the requirement to configure this via GUI in the backend for other users...

Best, foepsen

thomasplevy commented 5 years ago

@foepsen

Did I get it right that this filter is only affecting the displayed results while the original result stored in the DB is still a floating number?

Correct.

On the other hand adding the Mode PHP_ROUND_HALF_UP should prevent the case that users aren't able to finish a course because of the rounded result even if the rounded result is stored in the DB. As long as they reach sth between 99.1% and 99.9%, they would finish it with 100%...

I've never seen this reported as an issue. If you're seeing this happen could you open a new issue and provide me with all the requested information and reproduction steps.