LLMS_Admin_Reporting::output_widget( array $args = array() )
Outputs the HTML for a reporting widget.
Parameters Parameters
- $args
-
(array) (Optional) Array of widget options and data to be displayed.
- 'id'
(string) Required. A unique identifier for the widget. - 'text'
(string) A short description of the widget's data. - 'data'
(int|string|float) The value of the data to display. - 'data_compare'
(int|string|float) Additional data to compare $data against. - 'data_type'
(string) The type of data. Used to format displayed data. Accepts "numeric", "monetary", "text", "percentage", or "date". - 'icon'
(string) An optional Font Awesome icon used to help visually identify the widget. If supplied, should be supplied without thefa-
icon prefix. - 'impact'
(string) The type of impact the data has, either "positive" or "negative". This is used when displaying comparisons to determine if the change was a positive change or negative change. For example: student enrollments has a positive impact while quiz failures has a negative impact. An increase in enrollments will be displayed in green while a decrease will be displayed in red. An increase in quiz failures will be displayed in red while a decrease will be displayed in green. - 'cols'
(string) Grid class widget width ID. See: assets/scss/admin/partials/_grid.scss.
Default value: array()
- 'id'
Return Return
(void)
Source Source
File: includes/admin/reporting/class.llms.admin.reporting.php
* @type string $impact The type of impact the data has, either "positive" or "negative". This * is used when displaying comparisons to determine if the change was a positive * change or negative change. For example: student enrollments has a positive * impact while quiz failures has a negative impact. An increase in enrollments * will be displayed in green while a decrease will be displayed in red. An * increase in quiz failures will be displayed in red while a decrease will be * displayed in green. * @type string $cols Grid class widget width ID. See: assets/scss/admin/partials/_grid.scss. * } * @return void */ public static function output_widget( $args = array() ) { $args = self::get_output_widget_args( $args ); // Only these data types can make comparisons. $can_compare = in_array( $args['data_type'], array( 'numeric', 'monetary', 'percentage' ), true ); // Adds a percentage symbol after data. $data_after = 'percentage' === $args['data_type'] && is_numeric( $args['data'] ) ? '<sup>%</sup>' : ''; $change = false; $compare_operator = ''; $compare_class = ''; $compare_title = ''; $floating_precision = llms_get_floats_rounding_precision(); if ( $can_compare && $args['data_compare'] && floatval( $args['data'] ) ) { $change = round( ( $args['data'] - $args['data_compare'] ) / $args['data'] * 100, $floating_precision ); $compare_operator = ( $change <= 0 ) ? '' : '+'; $compare_title = sprintf( // Translators: %s = The value of the data from the previous data set. esc_attr__( 'Previously %s', 'lifterlms' ), round( $args['data_compare'], $floating_precision ) . wp_strip_all_tags( $data_after ) ); $compare_class = ( $change <= 0 ) ? 'negative' : 'positive'; if ( 'negative' === $args['impact'] ) {
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
6.11.0 | Moved HTML into a view file. Fixed division by zero error encountered during data comparisons when $data is 0 . Added a check to ensure only numeric, monetary, or percentage data types will generate comparison data. |
3.31.0 | Remove redundant if statement. |
3.15.0 | Introduced. |