} } // END Retakes $myavg = get_post_meta($course->ID, $user_id, true); if (!isset($myavg) || $myavg == '') { $myavg = __('TAKING', 'vibe'); } echo '<strong>' . __('MY SCORE : ', 'vibe') . '<span>' . apply_filters('wplms_course_marks', $myavg . '/100', $course->ID) . '</span></strong>'; echo '<ul class="in_details">'; if (isset($curriculum) && is_array($curriculum)) { foreach ($curriculum as $c) { if (is_numeric($c)) { if (get_post_type($c) == 'quiz') { $myavg = get_post_meta($c, $user_id, true); $avg = get_post_meta($c, 'average', true); $questions = bp_course_get_quiz_questions($c, $user_id); if (isset($questions['marks']) && is_array($questions['marks'])) { $marks = $questions['marks']; $max = array_sum($marks); } if (isset($myavg) && $myavg != '') { echo '<li>' . __('Average Marks in', 'vibe') . ' ' . get_the_title($c) . ' : ' . $avg . ''; echo '<strong>' . __('My Marks', 'vibe') . ' : ' . $myavg . ' / ' . $max . '</strong></li>'; } } else { $check = get_user_meta($user_id, $c, true); echo '<li>' . get_the_title($c) . '<strong>' . ($check ? '<i class="icon-check"></i>' : '<i class="icon-alarm-clock"></i>') . '</strong></li>'; } } } }
function bp_get_course_check_course_complete($args = NULL) { // AUTO EVALUATION FOR COURSE global $post; $defaults = array('id' => $post->ID, 'user_id' => get_current_user_id()); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $return = '<div class="course_finish">'; $course_curriculum = bp_course_get_curriculum_units($id); if (isset($course_curriculum) && count($course_curriculum)) { $flag = 0; foreach ($course_curriculum as $unit_id) { //if(is_numeric($unit_id)){ $unittaken = get_user_meta($user_id, $unit_id, true); if (!isset($unittaken) || !$unittaken) { $flag = $unit_id; break; } //} } $flag = apply_filters('wplms_finish_course_check', $flag, $course_curriculum); if (!$flag) { $course_id = $id; $auto_eval = get_post_meta($id, 'vibe_course_auto_eval', true); if (vibe_validate($auto_eval)) { // AUTO EVALUATION $curriculum = bp_course_get_curriculum_units($id); $total_marks = $student_marks = 0; foreach ($curriculum as $c) { if (get_post_type($c) == 'quiz') { $k = get_post_meta($c, $user_id, true); $student_marks += $k; $questions = bp_course_get_quiz_questions($c, $user_id); $total_marks += array_sum($questions['marks']); } } do_action('wplms_submit_course', $post->ID, $user_id); // Apply Filters on Auto Evaluation $student_marks = apply_filters('wplms_course_student_marks', $student_marks, $id, $user_id); $total_marks = apply_filters('wplms_course_maximum_marks', $total_marks, $id, $user_id); if (!$total_marks) { $total_marks = $student_marks = 1; } // Avoid the Division by Zero Error $marks = round($student_marks * 100 / $total_marks); $return .= '<div class="message" class="updated"><p>' . __('COURSE EVALUATED ', 'vibe') . '</p></div>'; $badge_per = get_post_meta($id, 'vibe_course_badge_percentage', true); $passing_cert = get_post_meta($id, 'vibe_course_certificate', true); // Certificate Enable $passing_per = get_post_meta($id, 'vibe_course_passing_percentage', true); // Certificate Passing Percentage //finish bit for student 1.8.4 update_user_meta($user_id, 'course_status' . $id, 3); //end finish bit do_action('wplms_evaluate_course', $id, $marks, $user_id, 1); $badge_filter = 0; if (isset($badge_per) && $badge_per && $marks >= $badge_per) { $badge_filter = 1; } $badge_filter = apply_filters('wplms_course_student_badge_check', $badge_filter, $course_id, $user_id, $marks, $badge_per); if ($badge_filter) { $badges = array(); $badges = vibe_sanitize(get_user_meta($user_id, 'badges', false)); if (isset($badges) && is_array($badges)) { $badges[] = $id; } else { $badges = array($id); } update_user_meta($user_id, 'badges', $badges); $b = bp_get_course_badge($id); $badge = wp_get_attachment_info($b); $badge_url = wp_get_attachment_image_src($b); if (isset($badge) && is_numeric($b)) { $return .= '<div class="congrats_badge">' . __('Congratulations ! You\'ve earned the ', 'vibe') . ' <strong>' . get_post_meta($id, 'vibe_course_badge_title', true) . '</strong> ' . __('Badge', 'vibe') . '<a class="tip ajax-badge" data-course="' . get_the_title($id) . '" title="' . get_post_meta($id, 'vibe_course_badge_title', true) . '"><img src="' . $badge_url[0] . '" title="' . $badge['title'] . '"/></a></div>'; } do_action('wplms_badge_earned', $id, $badges, $user_id, $badge_filter); } $passing_filter = 0; if (vibe_validate($passing_cert) && isset($passing_per) && $passing_per && $marks >= $passing_per) { $passing_filter = 1; } $passing_filter = apply_filters('wplms_course_student_certificate_check', $passing_filter, $course_id, $user_id, $marks, $passing_per); if ($passing_filter) { $pass = array(); $pass = vibe_sanitize(get_user_meta($user_id, 'certificates', false)); if (isset($pass) && is_array($pass)) { $pass[] = $id; } else { $pass = array($id); } update_user_meta($user_id, 'certificates', $pass); $return .= '<div class="congrats_certificate">' . __('Congratulations ! You\'ve successfully passed the course and earned the Course Completion Certificate !', 'vibe') . '<a href="' . bp_get_course_certificate('user_id=' . $user_id . '&course_id=' . $id) . '" class="ajax-certificate right"><span>' . __('View Certificate', 'vibe') . '</span></a></div>'; do_action('wplms_certificate_earned', $id, $pass, $user_id, $passing_filter); } update_post_meta($id, $user_id, $marks); $course_end_status = apply_filters('wplms_course_status', 4); update_user_meta($user_id, 'course_status' . $id, $course_end_status); //EXCEPTION $message = sprintf(__('You\'ve obtained %s in course %s ', 'vibe'), apply_filters('wplms_course_marks', $marks . '/100'), ' <a href="' . get_permalink($id) . '">' . get_the_title($id) . '</a>'); $return .= '<div class="congrats_message">' . $message . '</div>'; } else { $return .= '<div class="message" class="updated"><p>' . __('COURSE SUBMITTED FOR EVALUATION', 'vibe') . '</p></div>'; bp_course_update_user_course_status($user_id, $id, 2); // 2 determines Course is Complete do_action('wplms_submit_course', $post->ID, $user_id); } // Show the Generic Course Submission $content = get_post_meta($id, 'vibe_course_message', true); $return .= apply_filters('the_content', $content); $return = apply_filters('wplms_course_finished', $return); } else { $type = get_post_type($flag); switch ($type) { case 'unit': $type = __('UNIT', 'vibe'); break; case 'assignment': $type = __('ASSIGNMENT', 'vibe'); break; case 'quiz': $type = __('QUIZ', 'vibe'); break; } //Default for other customized options $message = __('PLEASE COMPLETE THE ', 'vibe') . $type . ' : ' . get_the_title($flag); $return .= '<div class="message"><p>' . apply_filters('wplms_unfinished_unit_quiz_message', $message, $flag) . '</p></div>'; } } else { $retun .= __('COURSE CURRICULUM NOT SET', 'vibe'); } $return .= '</div>'; return $return; }
function evaluate_quiz() { $quiz_id = intval($_POST['id']); $user_id = intval($_POST['user']); if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'vibe_quiz')) { echo '<p>' . __('Security check failed !', 'vibe') . '</p>'; die; } if (!isset($user_id) || !$user_id) { echo '<p>' . __(' Incorrect User selected.', 'vibe') . '</p>'; die; } if (get_post_type($quiz_id) != 'quiz') { echo '<p>' . __(' Incorrect Quiz Id.', 'vibe') . '</p>'; die; } $questions = bp_course_get_quiz_questions($quiz_id, $user_id); echo '<h3 class="evaluate_heading">' . get_the_title($quiz_id) . ' ' . _x('submission by', 'Quiz submission "by" user', 'vibe') . ' ' . bp_core_get_user_displayname($user_id) . '</h3>'; if (count($questions)) { echo '<ul class="quiz_questions">'; $sum = $max_sum = 0; //global $wpdb; To be Covered at a Later update //$questions_ids = implode($questions['ques']); //$quiz_results = $wpdb->get_results($wpdb->prepare("SELECT p.ID,c.comment_ID,p.post_content,c.comment_content FROM {$wpdb->posts} as p LEFT JOIN {$wpdb->comments} as c ON p.ID = c.comment_post_ID WHERE c.ID IN ($questions_ids) AND c.user_id = %d LIMIT 0,1")) foreach ($questions['ques'] as $key => $question) { if (isset($question) && $question) { $cid = ''; $q = get_post($question); echo '<li> <div class="q">' . apply_filters('the_content', $q->post_content) . '</div>'; $comments_query = new WP_Comment_Query(); $comments = $comments_query->query(array('post_id' => $question, 'user_id' => $user_id, 'number' => 1, 'status' => 'approve')); if (!empty($comments)) { echo '<strong>'; _e('Marked Answer :', 'vibe'); echo '</strong>'; $correct_answer = get_post_meta($question, 'vibe_question_answer', true); foreach ($comments as $comment) { // This loop runs only once $type = get_post_meta($question, 'vibe_question_type', true); $cid = ''; switch ($type) { case 'select': case 'single': $options = vibe_sanitize(get_post_meta($question, 'vibe_question_options', false)); echo $options[intval($comment->comment_content) - 1]; // Reseting for the array if (isset($correct_answer) && $correct_answer != '') { $ans = $options[intval($correct_answer) - 1]; } break; case 'multiple': $options = vibe_sanitize(get_post_meta($question, 'vibe_question_options', false)); $ans = explode(',', $comment->comment_content); foreach ($ans as $an) { echo $options[intval($an) - 1] . ' '; } $cans = explode(',', $correct_answer); $ans = ''; foreach ($cans as $can) { $ans .= $options[intval($can) - 1] . ', '; } break; case 'match': case 'sort': $options = vibe_sanitize(get_post_meta($question, 'vibe_question_options', false)); $ans = explode(',', $comment->comment_content); foreach ($ans as $an) { echo $an . '. ' . $options[intval($an) - 1] . ' '; } $cans = explode(',', $correct_answer); $ans = ''; foreach ($cans as $can) { $ans .= $can . '. ' . $options[intval($can) - 1] . ', '; } break; case 'fillblank': case 'smalltext': echo $comment->comment_content; $ans = $correct_answer; break; default: echo apply_filters('the_content', $comment->comment_content); $ans = $correct_answer; break; } $cid = $comment->comment_ID; $marks = get_comment_meta($comment->comment_ID, 'marks', true); } } if (isset($correct_answer) && $correct_answer != '') { echo '<strong>'; _e('Correct Answer :', 'vibe'); echo '<span>' . $ans . '</span></strong>'; } if (!empty($marks)) { if (empty($cid)) { echo '<strong>' . _x('Unattempted question ! Marks can not be assigned for this question.', 'Unattempted question warning in Course - Admin - Submissions area', 'vibe') . '</strong>'; } else { echo '<span class="marking">' . __('Marks Obtained', 'vibe') . ' <input type="text" id="' . $cid . '" class="form_field question_marks" value="' . $marks . '" placeholder="' . __('Give marks', 'vibe') . '" /> <a href="#" class="give_marks button" data-ans-id="' . $cid . '">' . __('Update Marks', 'vibe') . '</a>'; } $sum = $sum + $marks; } else { if (empty($cid)) { echo '<strong>' . _x('Unattempted question ! Marks can not be assigned for this question.', 'Unattempted question warning in Course - Admin - Submissions area', 'vibe') . '</strong>'; } else { echo '<span class="marking">' . __('Marks Obtained', 'vibe') . ' <input type="text" id="' . $cid . '" class="form_field question_marks" value="" placeholder="' . __('Give marks', 'vibe') . '" /> <a href="#" class="give_marks button" data-ans-id="' . $cid . '">' . __('Give Marks', 'vibe') . '</a>'; } } $max_sum = $max_sum + intval($questions['marks'][$key]); echo '<span> ' . __('Total Marks', 'vibe') . ' : ' . $questions['marks'][$key] . '</span>'; echo '</li>'; } // IF question check } echo '</ul>'; echo '<div id="total_marks">' . __('Total', 'vibe') . ' <strong><span>' . $sum . '</span> / ' . $max_sum . '</strong> </div>'; echo '<a href="#" id="mark_complete" class="button full" data-quiz="' . $quiz_id . '" data-user="******">' . __('Mark Quiz as Checked', 'vibe') . '</a>'; } die; }
function wplms_check_course_retake() { if (!isset($_POST['security'])) { return; } $user_id = get_current_user_id(); if (!wp_verify_nonce($_POST['security'], 'retake' . $user_id)) { echo '<p class="error">' . __('Security check failed !', 'vibe') . '</p>'; return; } $course_id = get_the_ID(); $status = bp_course_get_user_course_status($user_id, $course_id); if (isset($status) && is_numeric($status)) { // Necessary for continue course do_action('wplms_student_course_reset', $course_id, $user_id); bp_course_update_user_course_status($user_id, $course_id, 0); // New function $course_curriculum = bp_course_get_curriculum($course_id); foreach ($course_curriculum as $c) { if (is_numeric($c)) { delete_user_meta($user_id, $c); delete_post_meta($c, $user_id); if (get_post_type($c) == 'quiz') { if (function_exists('bp_course_get_quiz_questions')) { $questions = bp_course_get_quiz_questions($c, $user_id); } else { $questions = vibe_sanitize(get_post_meta($c, 'quiz_questions' . $user_id, false)); if (!isset($questions) || !is_array($questions)) { // Fallback for Older versions $questions = vibe_sanitize(get_post_meta($c, 'vibe_quiz_questions', false)); } } if (isset($questions) && is_array($questions) && is_Array($questions['ques'])) { foreach ($questions['ques'] as $question) { global $wpdb; if (isset($question) && $question != '' && is_numeric($question)) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET comment_approved='trash' WHERE comment_post_ID=%d AND user_id=%d", $question, $user_id)); } } } } } } $user_badges = vibe_sanitize(get_user_meta($user_id, 'badges', false)); $user_certifications = vibe_sanitize(get_user_meta($user_id, 'certificates', false)); if (isset($user_badges) && is_Array($user_badges) && in_array($course_id, $user_badges)) { $key = array_search($course_id, $user_badges); unset($user_badges[$key]); $user_badges = array_values($user_badges); update_user_meta($user_id, 'badges', $user_badges); } if (isset($user_certifications) && is_Array($user_certifications) && in_array($course_id, $user_certifications)) { $key = array_search($course_id, $user_certifications); unset($user_certifications[$key]); $user_certifications = array_values($user_certifications); update_user_meta($user_id, 'certificates', $user_certifications); } /*==== End Fix ======*/ do_action('wplms_course_retake', $course_id, $user_id); echo "<script>jQuery(document).ready(function(\$){ \$.removeCookie('course_progress{$course_id}', { path: '/' }); });</script>"; } else { echo '<p class="error">' . __('There was issue in retaking this course for the user. Please contact admin.', 'vibe') . '</p>'; } }