Add a Custom information in Course Stats download report

In this tip we’ll learn how to add a custom stats in the Course Download Stats report. To learn how to record a custom stats in data base refer to this tip 
This tip can be considered as a second part of the above tip using which we can download custom stats recorded in the database.

0. Check the topic : How to use Coding tips in WPLMS
1. Go to WP Admin -> Plugins -> editor -> WPLMS Customizer -> customizer_class.php
2. Add the following code in __construct function :

PHP Code:

add_filter('wplms_course_stats_list',array($this,'add_custom_course_stat'));
add_action('wplms_course_stats_process',array($this,'process_custom_course_stat'),10,8);

3. Add these functions in the class :

PHP Code:

 function add_custom_course_stat($list){
            $list['unit_duration']= 'Unit Duration';
            return $list;
        }

        function process_custom_course_stat(&$csv_title, &$csv,&$i,&$course_id,&$user_id,&$field,&$ccsv,&$k){
             if($field != 'unit_duration')
                return;
             // Custom Stat Calculation //
              $units=bp_course_get_curriculum_units($course_id);
                foreach($units as $unit_id){
                  if(get_post_type($unit_id) == 'unit'){

                  $title=get_the_title($unit_id);
                  if(!in_array($title,$csv_title))
                  $csv_title[$k]=array('title'=>$title,'field'=>$unit_id); // ----> This is Title of the CSV Column
                     $key = 'unit_start_time'.$unit_id;
                    $start_time = get_user_meta($user_id,$key,true); // Value in seconds
                    $end_time = get_user_meta($user_id,$unit_id,true); // Value in seconds
                    if(isset($end_time) && isset($start_time)){
                        $difference = ($end_time - $start_time);  
                        if($difference > 0){
                            $status = ($difference/60).' minutes';
                        }else{
                            $status = 'Pursuing';
                        }  
                    }else{
                        $status = 'N.A';
                    }
                    
                    $csv[$i][] = $status; // ---> Stats Column value
                    $ccsv[$i][$unit_id] = $field_val;
                  $i++;
                  }
                }
        }