h5p temp

‘tablename’ => ‘H5P Results’,
‘userid’ => ‘none’,
), $atts );

$current_user = wp_get_current_user();
if($atts[‘userid’] !== ‘none’)
$current_user->ID = $atts[‘userid’];

$results = $wpdb->get_results( “SELECT id, slug FROM `wp_h5p_contents`;” );

$sql_string = ‘SELECT ‘;

if($atts[‘userid’] == ‘all’){
$sql_string = “SELECT u.display_name, “;
$atts[‘display’] = ‘row’;
}

foreach ($results as $result){
$sql_string .= “IFNULL(CONCAT(r”.$result->id.”.score , ‘/’, r”.$result->id.”.max_score),’N/A’) as ‘”.$result->slug.”‘, “;
}

$sql_string = substr($sql_string, 0, -2);

$sql_string .= ” FROM `wp_users` as u “;

foreach ($results as $result){

$sql_string .= “left join `wp_h5p_results` as r”.$result->id.” on r”.$result->id.”.user_id = u.id and r”.$result->id.”.content_id = “.$result->id.” “;
}

if($atts[‘userid’] !== ‘all’)
$sql_string .= “WHERE u.id =”.$current_user->ID ;

$results = $wpdb->get_results($sql_string);

if($atts[‘display’] == ‘row’){

$html = ”

“.”;foreach ($results as $result){
$result = (array)$result;
$result_keys = array_keys($result); // get keys
}foreach ($result_keys as $result_key){
$html .= ”;
}$html .= ”;foreach ($results as $row){
$html .= “”;foreach ($row as $r){
$html .= “”;
}
$html .= “”;
//close off table mn
}
$html .= “”;}if($atts[‘display’] == ‘list’){$sql = “SELECT c.title, c.slug, r.score, r.max_score, “.
“r.opened, r.finished FROM `wp_h5p_results` r LEFT JOIN “.
“`wp_h5p_contents` AS c ON c.id = r.content_id WHERE r.user_id = ”
.$current_user->ID;$results = $wpdb->get_results($sql);$html = ”;if(count($results) >= 1){foreach($results as $result){
// work out time taken
$duration = (string)$result->finished – (string)$result->opened;
$minutes = floor($duration / 60);
$seconds = $duration % 60;
// convert score to %
$score_percent = (string)$result->score / (string)$result->max_score * 100;$result->finished = date(‘m/d/Y’, $result->finished);$html .= ”;
}
}else{
$html .= ”;
}
$html .= ”;}
unset($atts);
unset($current_user);
return($html);
}add_shortcode(‘h5p_results’, ‘h5p_results_func’);

‘.$result_key.’
” . $r . “
‘.$atts[‘tablename’].’
Title Result Result % Completion date Time taken
‘.$result->title.’ ‘.
$result->score.’/’.$result->max_score.’
‘.
substr($score_percent,0,5).’
‘.
$result->finished.’
‘.
$minutes.’:’.$seconds.’
No results