Coursepress longtext query

Dear WP MU DEV,

Coursepress is a beautiful plug in and I experience a lot of joy from it. However, when I wanted to visualize a average progress percentage per course by using a query I found myself in a pickle.

The data from coursepress pro is saved in a php serialized matter. I tried to unserialize it with PHP but I get a bool(false) result...

Can someone help me or show me where the data get unserialized by Coursepress itself to use it? Maybe then I can figure it out myself in the future

Kind regards,

Simon

  • Predrag Dubajic

    Hey Simon,

    Hope you're doing well today

    I must say I'm not sure how can this be done with CP so I'll need to ping our second level support dev guys for additional help.
    Please note that, developer response might be slower than usual staff response, so we appreciate your patience on this.

    If you're in a hurry to customize this then you can post a job in our job board where you can hire a developer to assist further:
    http://premium.wpmudev.org/wpmu-jobs/
    Please note that, no WPMU official staff members are allowed to work in the job board.

    Best regards,
    Predrag

  • Panos

    Hi Simon ,

    Sincere apologies for the delay here!

    Could you please provide further information regarding what it is you want to achieve? Is it the course progress you need? I have prepared a function which you can use for this case. You need to know the id of the course:

    function wpmudev_get_course_students_progress( $course_id ){
    
    	if( !$course_id || !is_numeric( $course_id ) || $course_id < 0 ) return false;
    
    	$class_meta_query_key = '';
    	if ( is_multisite() ) {
             global $wpdb;
    		$class_meta_query_key = $wpdb->prefix . 'enrolled_course_class_' . $course_id;
    	} else {
    		$class_meta_query_key = 'enrolled_course_class_' . $course_id;
    	}
    
    	$args = array(
    		'meta_query' => array(
    			array(
    				'key'   => $class_meta_query_key,
    				'value' => '',
    			)
    		)
    	);	
    
    	$wp_user_search = new WP_User_Query( $args );
    
    	$return = array();
    	$students_num = 0;
    	$progress_sum = 0;
    	if( $students = $wp_user_search->get_results() ){
    
    		$students_array = array();
    
    		foreach( $students as $student ){
    			$students_num++;
    
    			$progress = Student_Completion::calculate_course_completion( $student->ID, $_GET['course_id'], false );
    
    			$students_array[ $student->ID ] = $progress;
    
    			$progress_sum += $progress;
    
    		}
    
    		$return['students'] = $students_array;
    		$progress_avg = $progress_sum / $students_num;
    		$return['progress_avg'] = $progress_avg;
    
    	}
    
    	return $return;
    
    }

    You will need to call it like this:

    //Assuming you already have the course id
    $course_progress_info = wpmudev_get_course_students_progress( $course_id );
    $course_progress = $course_progress_info[ 'progress_avg' ];
    $course_progress_students = $course_progress_info[ 'students' ];

    Please let me know if it is something else you are looking for and in such case please make sure you provide as much information possible

    Hope this helps!
    Panos