php [CoursePress] - 证书中的回复
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [CoursePress] - 证书中的回复相关的知识,希望对你有一定的参考价值。
<?php
/**
* Plugin Name: [CoursePress] - Responses in Certificate
* Plugin URI: https://premium.wpmudev.org/
* Description: Include Questions and Responses in Certificates
* Author: Panos Lyrakis @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* License: GPLv2 or later
*/
add_filter( 'coursepress_basic_certificate_vars', function( $vars ){
if(
//is_admin() ||
! isset( $_REQUEST['action'] ) || 'certificate' != $_REQUEST['action'] ||
! isset( $_REQUEST['course_id'] ) || ! isset( $_REQUEST['student_id'] )
){
return;
}
$replacement = '';
$course_id = intval( $_REQUEST['course_id'] );
$student_id = intval( $_REQUEST['student_id'] );
$units = CoursePress_Data_Course::get_units_with_modules( $course_id );
// We will need completion data for input-text and input-textarea responses
$text_responses = array();
$completion_data = CoursePress_Data_Student::get_completion_data( $student_id, $course_id );
//Responses of text or textarea modules
foreach( $completion_data['units'] as $unit_id => $unit_data ){
if( isset( $unit_data['responses'] ) && ! empty( $unit_data['responses'] ) ){
foreach( $unit_data['responses'] as $module_id => $response_data ){
$text_responses[ $module_id ] = $response_data[0]['response'];
}
}
}
foreach( $units as $unit_id => $unit_data ){
$pages = $unit_data['pages'];
foreach ( $pages as $page_num => $page_data ) {
$modules = $page_data['modules'];
if( ! empty( $modules ) ){
$replacement .= '<ul>';
foreach( $modules as $module_id => $module ){
$response = '';
$attributes = CoursePress_Data_Module::attributes( $module_id );
switch ( $attributes['module_type'] ) {
case 'input-checkbox':
$answers = $attributes['answers'];
$answers_selected = $attributes['answers_selected'];
if( ! empty( $answers_selected ) ){
foreach( $answers_selected as $selected ){
if( isset( $answers[$selected] ) ){
$response .= $answers[$selected];
}
}
}
if( isset( $answers[$selected] ) ){
$response = $answers[$selected];
}
break;
case 'input-select':
case 'input-radio':
$selected = $attributes['answers_selected'];
if( isset( $answers[$selected] ) ){
$response = $answers[$selected];
}
break;
case 'input-text':
case 'input-textarea':
$response = isset( $text_responses[ $module_id ] ) ? $text_responses[ $module_id ] : '';
break;
}
$replacement .= "<li>{$module->post_title} <p>{$response}</p></li>";
}
$replacement .= '</ul>';
}
}
}
if( '' != $replacement ){
$vars['STUDENT_REPLIES'] = $replacement;
}
return $vars;
}, 10 );
以上是关于php [CoursePress] - 证书中的回复的主要内容,如果未能解决你的问题,请参考以下文章
php [CoursePress 2] - 回应历史。帮助及时监控学生的反应
php [CoursePress 2] - 订单单元部分 - 提供自定义管理页面以重新排序单元的部分
php 一个自定义函数,返回一个数组,其中包含CoursePress的每个用户ID的讲师和学生角色
php [CoursePress] - 提供一组可以创建课程和单元的功能。可以使用eval从wp-cli调用这些函数
使用 PHP 中的 curl 连接到在证书包中显示过期根证书的站点
从 php 中的 PKCS7 签名中提取证书