Esempio n. 1
0
/**
 * Given a frontend object with user progress data, replace the tags with quiz-related information
 * based on the tags that have been found in the email.
 * 
 * @param WPCW_UnitFrontend $feObj The frontend object with details.
 * @param Array $tagList The list of tags found in the template.
 * @param String $emailData The data to replace the strings with.
 * @param String $additionalData Any additional data triggered from the trainer.
 * 
 * @return The modified email data ready for sending.
 */
function WPCW_email_replaceTags_quizData($feObj, $tagList, $emailData, $additionalData = false)
{
    if (!$feObj || empty($tagList)) {
        return $emailData;
    }
    $quizDetails = $feObj->fetch_getUnitQuizDetails();
    $progressData = $feObj->fetch_getQuizProgressDetails();
    // Replace each tag for quiz-related data.
    foreach ($tagList as $tagToReplace) {
        switch ($tagToReplace) {
            case '{QUIZ_TITLE}':
                $emailData = str_replace('{QUIZ_TITLE}', $quizDetails->quiz_title, $emailData);
                break;
            case '{QUIZ_GRADE}':
                $emailData = str_replace('{QUIZ_GRADE}', $progressData->quiz_grade . '%', $emailData);
                break;
            case '{QUIZ_ATTEMPTS}':
                $emailData = str_replace('{QUIZ_ATTEMPTS}', $progressData->attempt_count, $emailData);
                break;
            case '{QUIZ_TIME}':
                $timeToShare = __('n/a', 'wp_courseware');
                if ($progressData->quiz_completion_time_seconds > 0) {
                    $timeToShare = WPCW_time_convertSecondsToHumanLabel($progressData->quiz_completion_time_seconds);
                }
                $emailData = str_replace('{QUIZ_TIME}', $timeToShare, $emailData);
                break;
            case '{QUIZ_RESULT_DETAIL}':
                $emailData = str_replace('{QUIZ_RESULT_DETAIL}', $additionalData, $emailData);
                break;
            case '{QUIZ_GRADES_BY_TAG}':
                // Use existing frontend code to get the list of messages relating to tags.
                $msgList = $feObj->fetch_quizzes_questionResultsByTag();
                $msgSummary = false;
                if (!empty($msgList)) {
                    foreach ($msgList as $tagDetails) {
                        // Got open questions
                        if ($tagDetails['question_open_count'] > 0) {
                            $msgSummary .= sprintf("%s: %s\n", $tagDetails['tag_details']->question_tag_name, sprintf(__('Your grade is %d%%', 'wp_courseware'), $tagDetails['score_total']));
                        } else {
                            $msgSummary .= sprintf("%s: %s\n", $tagDetails['tag_details']->question_tag_name, sprintf(__('%d out of %d correct (%d%%)', 'wp_courseware'), $tagDetails['score_correct_questions'], $tagDetails['question_count'], $tagDetails['score_total']));
                        }
                        // end of question type check
                    }
                }
                $emailData = str_replace('{QUIZ_GRADES_BY_TAG}', $msgSummary, $emailData);
                break;
            case '{CUSTOM_FEEDBACK}':
                // Use existing frontend code to get the list of custom feedback messages.
                $customFeedback = false;
                $msgList = $feObj->fetch_customFeedbackMessage_calculateMessages();
                if (!empty($msgList)) {
                    $customFeedback = apply_filters('wpcw_email_feedback_separator_top', "\n\n------\n\n");
                    foreach ($msgList as $singleMsg) {
                        // Separate each custom feedback message slightly
                        $customFeedback .= $singleMsg . apply_filters('wpcw_email_feedback_separator', "\n\n------\n\n");
                    }
                }
                $emailData = str_replace('{CUSTOM_FEEDBACK}', $customFeedback, $emailData);
                break;
        }
    }
    return $emailData;
}
Esempio n. 2
0
if (!$fe->check_unit_doesUnitHaveParentData()) {
    WPCW_export_results_notFound(__('Could not find course details for unit.', 'wp_courseware'));
}
// #### User not allowed access to content
if (!$fe->check_user_canUserAccessCourse()) {
    WPCW_export_results_notFound($fe->fetch_message_user_cannotAccessCourse());
}
include_once 'pdf/pdf_quizresults.inc.php';
$qrpdf = new WPCW_QuizResults();
$parentData = $fe->fetch_getUnitParentData();
$quizDetails = $fe->fetch_getUnitQuizDetails();
// Set values for use in the results
$qrpdf->setTraineeName(WPCW_users_getUsersName($current_user));
$qrpdf->setCourseName($parentData->course_title);
$qrpdf->setQuizName($quizDetails->quiz_title);
// Render status messages
$qrpdf->setQuizMessages($fe->check_quizzes_workoutQuizPassStatusDetails());
// Render feedback messages
$qrpdf->setQuizFeedback($fe->fetch_customFeedbackMessage_calculateMessages());
// Render the results
$qrpdf->setQuizResults($fe->render_quizzes_showAllCorrectAnswers(true));
$qrpdf->generatePDF('browser');
die;
/**
 * Show a generic error, details not found.
 */
function WPCW_export_results_notFound($extraMessage = false)
{
    printf(__('Could not export your results. %s', 'wp_courseware'), $extraMessage);
    die;
}