/** * Handle showing the box that allows a user to mark a unit as completed. */ function WPCW_units_processUnitContent($content) { // #### Ensure we're only showing a course unit, a single item if (!is_single() || 'course_unit' != get_post_type()) { return $content; } // Use object to handle the rendering of the unit on the frontend. include_once WPCW_plugin_getPluginDirPath() . 'classes/class_frontend_unit.inc.php'; global $post; $fe = new WPCW_UnitFrontend($post); // #### Get associated data for this unit. No course/module data, then it's not a unit if (!$fe->check_unit_doesUnitHaveParentData()) { return $content; } // #### Ensure we're logged in if (!$fe->check_user_isUserLoggedIn()) { return $fe->message_user_notLoggedIn(); } // #### User not allowed access to content, so certainly can't say they've done this unit. if (!$fe->check_user_canUserAccessCourse()) { return $fe->message_user_cannotAccessCourse(); } // #### Is user allowed to access this unit yet? if (!$fe->check_user_canUserAccessUnit()) { return $fe->message_user_cannotAccessUnit(); } // ### Do the remaining rendering... return $fe->render_detailsForUnit($content); }
/** * The function called when a user receives a grade for a quiz, either when marked manually, or * when the question it automatically graded. * * Triggered by wpcw_quiz_graded. * * @param Integer $userID The ID of the user to notify. * @param Object $quizDetails The details of the quiz. * @param Integer $grade The grade that they've been given * @param String $additionalDetail Any additional data to add to the message. */ function WPCW_actions_userQuizGraded_notifyUser($userID, $quizDetails, $grade, $additionalDetail) { if (!$userID || !$quizDetails) { return; } // Need parent details to determine if we can send an email or not. $unitParentData = WPCW_units_getAssociatedParentData($quizDetails->parent_unit_id); // Check if admin wants user to have an email. if ($unitParentData->email_quiz_grade_option == 'send_email') { // User details - for sending the email. $userDetails = get_userdata($userID); // Need post object to create the notification. $post = get_post($quizDetails->parent_unit_id); if (!$post) { return; } // Initalise the unit details. Check we have access. $fe = new WPCW_UnitFrontend($post); if (!$fe->check_unit_doesUnitHaveParentData() || !$fe->check_user_canUserAccessCourse()) { return; } // Do email body first $emailBody = $unitParentData->email_quiz_grade_body; $tagList_Body = WPCW_email_getTagList($emailBody); $emailBody = WPCW_email_replaceTags_quizData($fe, $tagList_Body, $emailBody, $additionalDetail); // Then do subject line $emailSubject = $unitParentData->email_quiz_grade_subject; $tagList_Subject = WPCW_email_getTagList($emailSubject); $emailSubject = WPCW_email_replaceTags_quizData($fe, $tagList_Subject, $emailSubject, $additionalDetail); // Now send email WPCW_email_sendEmail($unitParentData, $userDetails, $userDetails->user_email, $emailSubject, $emailBody); } }
/** * Function called when user starting a quiz and needs to kick off the timer. */ function WPCW_AJAX_units_handleQuizTimerBegin() { // Security check if (!wp_verify_nonce(WPCW_arrays_getValue($_POST, 'progress_nonce'), 'wpcw-progress-nonce')) { die(__('Security check failed!', 'wp_courseware')); } // Get unit and quiz ID $unitID = intval(WPCW_arrays_getValue($_POST, 'unitid')); $quizID = intval(WPCW_arrays_getValue($_POST, 'quizid')); // Get the post object for this quiz item. $post = get_post($unitID); if (!$post) { echo WPCW_UnitFrontend::message_createMessage_error(__('Error - could not start the timer for the quiz.', 'wp_courseware') . ' ' . __('Could not find training unit.', 'wp_courseware')); die; } // Initalise the unit details $fe = new WPCW_UnitFrontend($post); // #### Get associated data for this unit. No course/module data, then it's not a unit if (!$fe->check_unit_doesUnitHaveParentData()) { echo WPCW_UnitFrontend::message_createMessage_error(__('Error - could not start the timer for the quiz.', 'wp_courseware') . ' ' . __('Could not find course details for unit.', 'wp_courseware')); die; } // #### User not allowed access to content if (!$fe->check_user_canUserAccessCourse()) { echo $fe->message_user_cannotAccessCourse(); die; } // #### See if we're in a position to retake this quiz? if (!$fe->check_quizzes_canUserRequestRetake()) { echo WPCW_UnitFrontend::message_createMessage_error(__('Error - could not start the timer for the quiz.', 'wp_courseware') . ' ' . __('You are not permitted to retake this quiz.', 'wp_courseware')); die; } // Trigger the upgrade to progress so that we can start the quiz, and trigger the timer. $fe->update_quizzes_beginQuiz(); // Only complete if allowed to continue. echo $fe->render_detailsForUnit(false, true); die; }
// Get unit and quiz ID $unitID = intval(WPCW_arrays_getValue($_GET, 'unitid')); $quizID = intval(WPCW_arrays_getValue($_GET, 'quizid')); // Get the post object for this quiz item. $post = get_post($unitID); if (!$post) { WPCW_export_results_notFound(__('Could not find training unit.', 'wp_courseware')); } // Initalise the unit details $fe = new WPCW_UnitFrontend($post); // #### Get associated data for this unit. No course/module data, then it's not a unit 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