public function single_lesson_handler() { global $post; // Preview Lessons shouldn't ignore this rule. if (WooThemes_Sensei_Utils::is_preview_lesson($post->ID)) { return; } $course_id = get_post_meta($post->ID, '_lesson_course', true); // User already started this course, so ideally, we shouldn't restrict access. if (WooThemes_Sensei_Utils::user_started_course($post->ID, wp_get_current_user()->ID)) { return; } // This happens if the lesson isn't locked itself. if (memberful_can_user_access_post(wp_get_current_user()->ID, $post->ID)) { if (!memberful_can_user_access_post(wp_get_current_user()->ID, $course_id)) { // The user doesn't have access to this post, so he shouldn't have actions on it. remove_all_actions('sensei_lesson_single_meta'); // Now the funky filtering part. remove_action('the_content', 'memberful_wp_protect_content'); add_action('the_content', array($this, 'single_lesson_special_content_filter'), -10); } } else { // The user doesn't have access to this post, so he shouldn't have actions on it. remove_all_actions('sensei_lesson_single_meta'); } }
function sensei_check_woocommerce_version($version = '2.1') { if (WooThemes_Sensei_Utils::sensei_is_woocommerce_activated()) { global $woocommerce; if (version_compare($woocommerce->version, $version, ">=")) { return true; } } return false; }
/** * trigger function. * * @access public * @return void */ function trigger($user_id = 0, $course_id = 0) { global $woothemes_sensei, $sensei_email_data; // Get learner user object $this->user = new WP_User($user_id); // Get passed status $passed = __('passed', 'woothemes-sensei'); if (!WooThemes_Sensei_Utils::sensei_user_passed_course($course_id, $user_id)) { $passed = __('failed', 'woothemes-sensei'); } // Construct data array $sensei_email_data = apply_filters('sensei_email_data', array('template' => $this->template, 'heading' => $this->heading, 'user_id' => $user_id, 'course_id' => $course_id, 'passed' => $passed), $this->template); // Set recipient (learner) $this->recipient = stripslashes($this->user->user_email); // Send mail $woothemes_sensei->emails->send($this->recipient, $this->subject, $woothemes_sensei->emails->get_content($this->template)); }
/** * Sets up the object course query * that will be used int he render method. * * @since 1.9.0 */ protected function setup_course_query() { // course query parameters to be used for all courses $query_args = array('post_type' => 'course', 'post_status' => 'publish', 'posts_per_page' => 1000, 'orderby' => $this->orderby, 'order' => $this->order); // get all the courses that has a product attached $all_courses_query = new WP_Query($query_args); $paid_courses_not_taken = array(); // look through all course and find the purchasable ones that user has not purchased foreach ($all_courses_query->posts as $course) { // only keep the courses with a product including only courses that the user not taking $course_product_id = get_post_meta($course->ID, '_course_woocommerce_product', true); if (is_numeric($course_product_id) && !WooThemes_Sensei_Utils::user_started_course($course->ID, get_current_user_id())) { $paid_courses_not_taken[] = $course->ID; } } // end foreach // setup the course query again and only use the course the user has not purchased. // this query will be loaded into the global WP_Query in the render function. $query_args['post__in'] = $paid_courses_not_taken; $query_args['posts_per_page'] = $this->number; $this->query = new WP_Query($query_args); }
/** * Prepare the table with different parameters, pagination, columns and table elements * @since 1.7.0 * @return void */ public function prepare_items() { global $woothemes_sensei, $per_page, $wp_version; // Handle orderby $orderby = ''; if (!empty($_GET['orderby'])) { if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { $orderby = esc_html($_GET['orderby']); } // End If Statement } // Handle order $order = 'DESC'; if (!empty($_GET['order'])) { $order = 'ASC' == strtoupper($_GET['order']) ? 'ASC' : 'DESC'; } // Handle search $search = false; if (!empty($_GET['s'])) { $search = esc_html($_GET['s']); } // End If Statement $this->search = $search; // Searching users on statuses requires sub-selecting the statuses by user_ids if ($this->search) { $user_args = array('search' => '*' . $this->search . '*', 'fields' => 'ID'); // Filter for extending $user_args = apply_filters('sensei_grading_search_users', $user_args); if (!empty($user_args)) { $learners_search = new WP_User_Query($user_args); // Store for reuse on counts $this->user_ids = $learners_search->get_results(); } } // End If Statement $per_page = $this->get_items_per_page('sensei_comments_per_page'); $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); $paged = $this->get_pagenum(); $offset = 0; if (!empty($paged)) { $offset = $per_page * ($paged - 1); } // End If Statement $activity_args = array('type' => 'sensei_lesson_status', 'number' => $per_page, 'offset' => $offset, 'orderby' => $orderby, 'order' => $order, 'status' => 'any'); if ($this->lesson_id) { $activity_args['post_id'] = $this->lesson_id; } elseif ($this->course_id) { // Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple // post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 ) if (version_compare($wp_version, '4.1', '>=')) { $activity_args['post__in'] = $woothemes_sensei->post_types->course->course_lessons($this->course_id, 'any', 'ids'); } } // Sub select to group of learners if ($this->user_ids) { $activity_args['user_id'] = (array) $this->user_ids; } // Restrict to a single Learner if ($this->user_id) { $activity_args['user_id'] = $this->user_id; } switch ($this->view) { case 'in-progress': $activity_args['status'] = 'in-progress'; break; case 'ungraded': $activity_args['status'] = 'ungraded'; break; case 'graded': $activity_args['status'] = array('graded', 'passed', 'failed'); break; case 'all': default: $activity_args['status'] = 'any'; break; } // End switch $activity_args = apply_filters('sensei_grading_filter_statuses', $activity_args); // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice $total_statuses = WooThemes_Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? if ($total_statuses < $activity_args['offset']) { $new_paged = floor($total_statuses / $activity_args['number']); $activity_args['offset'] = $new_paged * $activity_args['number']; } $statuses = WooThemes_Sensei_Utils::sensei_check_for_activity($activity_args, true); // Need to always return an array, even with only 1 item if (!is_array($statuses)) { $statuses = array($statuses); } $this->total_items = $total_statuses; $this->items = $statuses; $total_items = $this->total_items; $total_pages = ceil($total_items / $per_page); $this->set_pagination_args(array('total_items' => $total_items, 'total_pages' => $total_pages, 'per_page' => $per_page)); }
/** * Load the desired component, if a method is available for it. * @param string $component The component to potentially be loaded. * * @since 1.0.0 * @return void */ protected function load_component($instance) { global $woothemes_sensei, $current_user; get_currentuserinfo(); $course_ids = array(); if ('activecourses' == esc_attr($instance['component'])) { $courses = WooThemes_Sensei_Utils::sensei_check_for_activity(array('user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'in-progress'), true); // Need to always return an array, even with only 1 item if (!is_array($courses)) { $courses = array($courses); } foreach ($courses as $course) { $course_ids[] = $course->comment_post_ID; } } elseif ('completedcourses' == esc_attr($instance['component'])) { $courses = WooThemes_Sensei_Utils::sensei_check_for_activity(array('user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'complete'), true); // Need to always return an array, even with only 1 item if (!is_array($courses)) { $courses = array($courses); } foreach ($courses as $course) { $course_ids[] = $course->comment_post_ID; } } // End If Statement $posts_array = array(); // course_query() is buggy, it doesn't honour the 1st arg if includes are provided, so instead slice the includes if (!empty($instance['limit']) && intval($instance['limit']) >= 1 && intval($instance['limit']) < count($course_ids)) { $course_ids = array_slice($course_ids, 0, intval($instance['limit'])); // This does mean the order by is effectively ignored } if (!empty($course_ids)) { $posts_array = $woothemes_sensei->post_types->course->course_query(intval($instance['limit']), esc_attr($instance['component']), $course_ids); } else { if ('activecourses' == esc_attr($instance['component']) || 'completedcourses' == esc_attr($instance['component'])) { $posts_array = array(); } else { $posts_array = $woothemes_sensei->post_types->course->course_query(intval($instance['limit']), esc_attr($instance['component'])); } } // End If Statement if (count($posts_array) > 0) { ?> <ul> <?php foreach ($posts_array as $post_item) { $post_id = absint($post_item->ID); $post_title = $post_item->post_title; $user_info = get_userdata(absint($post_item->post_author)); $author_link = get_author_posts_url(absint($post_item->post_author)); $author_display_name = $user_info->display_name; $author_id = $post_item->post_author; ?> <li class="fix"> <?php do_action('sensei_course_image', $post_id); ?> <a href="<?php echo esc_url(get_permalink($post_id)); ?> " title="<?php echo esc_attr($post_title); ?> "><?php echo $post_title; ?> </a> <br /> <?php if (isset($woothemes_sensei->settings->settings['course_author']) && $woothemes_sensei->settings->settings['course_author']) { ?> <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?> <a href="<?php echo esc_url($author_link); ?> " title="<?php echo esc_attr($author_display_name); ?> "><?php echo esc_html($author_display_name); ?> </a></span> <br /> <?php } // End If Statement ?> <span class="course-lesson-count"><?php echo $woothemes_sensei->post_types->course->course_lesson_count($post_id) . ' ' . apply_filters('sensei_lessons_text', __('Lessons', 'woothemes-sensei')); ?> </span> <br /> <?php sensei_simple_course_price($post_id); ?> </li> <?php } // End For Loop ?> <?php if ('activecourses' == esc_attr($instance['component']) || 'completedcourses' == esc_attr($instance['component'])) { $my_account_page_id = intval($woothemes_sensei->settings->settings['my_course_page']); echo '<li class="my-account fix"><a href="' . esc_url(get_permalink($my_account_page_id)) . '">' . __('My Courses', 'woothemes-sensei') . ' <span class="meta-nav"></span></a></li>'; } // End If Statement ?> </ul> <?php } else { // No posts returned. This means the user either has no active or no completed courses. $course_status = substr(esc_attr($instance['component']), 0, -7); echo sprintf(__('You have no %1s courses.', 'woothemes-sensei'), $course_status); } // End If Statement }
/** * Return array of learners * @since 1.7.0 * @return array learners */ private function get_learners($args) { $user_ids = false; $post_id = 0; $activity = ''; if ($this->lesson_id) { $post_id = intval($this->lesson_id); $activity = 'sensei_lesson_status'; } elseif ($this->course_id) { $post_id = intval($this->course_id); $activity = 'sensei_course_status'; } if (!$post_id || !$activity) { $this->total_items = 0; return array(); } $activity_args = array('post_id' => $post_id, 'type' => $activity, 'status' => 'any', 'number' => $args['per_page'], 'offset' => $args['offset'], 'orderby' => $args['orderby'], 'order' => $args['order']); // Searching users on statuses requires sub-selecting the statuses by user_ids if ($args['search']) { $user_args = array('search' => '*' . $args['search'] . '*', 'fields' => 'ID'); // Filter for extending $user_args = apply_filters('sensei_learners_search_users', $user_args); if (!empty($user_args)) { $learners_search = new WP_User_Query($user_args); $activity_args['user_id'] = $learners_search->get_results(); } } $activity_args = apply_filters('sensei_learners_filter_users', $activity_args); // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice $total_learners = WooThemes_Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? if ($total_learners < $activity_args['offset']) { $new_paged = floor($total_learners / $activity_args['number']); $activity_args['offset'] = $new_paged * $activity_args['number']; } $learners = WooThemes_Sensei_Utils::sensei_check_for_activity($activity_args, true); // Need to always return an array, even with only 1 item if (!is_array($learners)) { $learners = array($learners); } $this->total_items = $total_learners; return $learners; }
public function add_new_learners() { $result = false; if (!isset($_POST['add_learner_submit'])) { return $result; } if (!isset($_POST['add_learner_nonce']) || !wp_verify_nonce($_POST['add_learner_nonce'], 'add_learner_to_sensei')) { return $result; } if (!isset($_POST['add_user_id']) || '' == $_POST['add_user_id'] || !isset($_POST['add_post_type']) || !isset($_POST['add_course_id']) || !isset($_POST['add_lesson_id'])) { return $result; } $post_type = $_POST['add_post_type']; $user_id = absint($_POST['add_user_id']); $course_id = absint($_POST['add_course_id']); switch ($post_type) { case 'course': $result = WooThemes_Sensei_Utils::user_start_course($user_id, $course_id); // Complete each lesson if course is set to be completed if (isset($_POST['add_complete_course']) && 'yes' == $_POST['add_complete_course']) { $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); foreach ($lesson_ids as $id) { WooThemes_Sensei_Utils::sensei_start_lesson($id, $user_id, true); } // Updates the Course status and it's meta data WooThemes_Sensei_Utils::user_complete_course($course_id, $user_id); do_action('sensei_user_course_end', $user_id, $course_id); } break; case 'lesson': $lesson_id = absint($_POST['add_lesson_id']); $complete = false; if (isset($_POST['add_complete_lesson']) && 'yes' == $_POST['add_complete_lesson']) { $complete = true; } $result = WooThemes_Sensei_Utils::sensei_start_lesson($lesson_id, $user_id, $complete); // Updates the Course status and it's meta data WooThemes_Sensei_Utils::user_complete_course($course_id, $user_id); break; } // Set redirect URL after adding user to course/lesson $query_args = array('page' => $this->page_slug, 'view' => 'learners'); if ($result) { if ($course_id) { $query_args['course_id'] = $course_id; } if ($lesson_id) { $query_args['lesson_id'] = $lesson_id; } $query_args['message'] = 'success'; } else { $query_args['message'] = 'error'; } $redirect_url = apply_filters('sensei_learners_add_learner_redirect_url', add_query_arg($query_args, admin_url('admin.php'))); wp_safe_redirect(esc_url_raw($redirect_url)); exit; }
$single_lesson_complete = WooThemes_Sensei_Utils::user_completed_lesson($lesson_item->ID, $current_user->ID); if ($single_lesson_complete) { $post_classes[] = 'lesson-completed'; } // End If Statement } // End If Statement // Get Lesson data $complexity_array = $woothemes_sensei->post_types->lesson->lesson_complexities(); $lesson_length = get_post_meta($lesson_item->ID, '_lesson_length', true); $lesson_complexity = get_post_meta($lesson_item->ID, '_lesson_complexity', true); if ('' != $lesson_complexity) { $lesson_complexity = $complexity_array[$lesson_complexity]; } $user_info = get_userdata(absint($lesson_item->post_author)); $is_preview = WooThemes_Sensei_Utils::is_preview_lesson($lesson_item->ID); $preview_label = ''; if ($is_preview && !$is_user_taking_course) { $preview_label = $woothemes_sensei->frontend->sensei_lesson_preview_title_text($post->ID); $preview_label = '<span class="preview-heading">' . $preview_label . '</span>'; $post_classes[] = 'lesson-preview'; } $html .= '<article class="' . esc_attr(join(' ', get_post_class($post_classes, $lesson_item->ID))) . '">'; $html .= '<header>'; $html .= '<h2><a href="' . esc_url(get_permalink($lesson_item->ID)) . '" title="' . esc_attr(sprintf(__('Start %s', 'woothemes-sensei'), $lesson_item->post_title)) . '">'; if (apply_filters('sensei_show_lesson_numbers', $show_lesson_numbers)) { $html .= '<span class="lesson-number">' . $lesson_count . '. </span>'; } $html .= esc_html(sprintf(__('%s', 'woothemes-sensei'), $lesson_item->post_title)) . $preview_label . '</a></h2>'; $html .= '<p class="lesson-meta">'; if ('' != $lesson_length) {
$quiz_lesson = $woothemes_sensei->quiz->data->quiz_lesson; $quiz_grade_type = $woothemes_sensei->quiz->data->quiz_grade_type; $user_lesson_end = $woothemes_sensei->quiz->data->user_lesson_end; $user_lesson_complete = $woothemes_sensei->quiz->data->user_lesson_complete; $lesson_quiz_questions = $woothemes_sensei->quiz->data->lesson_quiz_questions; // Check if the user has started the course $lesson_course_id = absint(get_post_meta($quiz_lesson, '_lesson_course', true)); $has_user_start_the_course = WooThemes_Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID); // Get the meta info $quiz_passmark = absint(get_post_meta($post->ID, '_quiz_passmark', true)); $quiz_passmark_float = (double) $quiz_passmark; ?> <div class="lesson-meta"> <?php // Display user's quiz status $status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message($quiz_lesson, $current_user->ID); echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; // Lesson Quiz Meta if (0 < count($lesson_quiz_questions)) { $question_count = 1; ?> <form method="POST" action="<?php echo esc_url(get_permalink()); ?> " enctype="multipart/form-data"> <ol id="sensei-quiz-list"> <?php foreach ($lesson_quiz_questions as $question_item) { // Setup current Frontend Question $woothemes_sensei->quiz->data->question_item = $question_item; $woothemes_sensei->quiz->data->question_count = $question_count;
/** * Return array of Course statuses * @since 1.7.0 * @return array statuses */ private function get_course_statuses($args) { $activity_args = array('user_id' => $this->user_id, 'type' => 'sensei_course_status', 'number' => $args['number'], 'offset' => $args['offset'], 'orderby' => $args['orderby'], 'order' => $args['order'], 'status' => 'any'); $activity_args = apply_filters('sensei_analysis_user_profile_filter_statuses', $activity_args); // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice $this->total_items = WooThemes_Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? if ($this->total_items < $activity_args['offset']) { $new_paged = floor($total_statuses / $activity_args['number']); $activity_args['offset'] = $new_paged * $activity_args['number']; } $statuses = WooThemes_Sensei_Utils::sensei_check_for_activity($activity_args, true); // Need to always return an array, even with only 1 item if (!is_array($statuses)) { $statuses = array($statuses); } return $statuses; }
/** * Limit the analysis view to only the users taking courses belong to this teacher * * Hooked into sensei_analysis_get_learners * @param array $args WP_User_Query arguments * @return array $learners_query_results */ public function limit_analysis_learners($args) { // show default for none teachers if (!Sensei()->teacher->is_admin_teacher()) { return $args; } // for teachers all courses only return those which belong to the teacher // as they don't have access to course belonging to other users $teacher_courses = Sensei()->course->get_all_courses(); // if the user has no courses they should see no users if (empty($teacher_courses) || !is_array($teacher_courses)) { // tell the query to return 0 students $args['include'] = array(0); return $args; } $learner_ids_for_teacher_courses = array(); foreach ($teacher_courses as $course) { $course_learner_ids = array(); $activity_comments = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id'), true); if (empty($activity_comments) || is_array($activity_comments) && !(count($activity_comments) > 0)) { continue; // skip to the next course as there are no users on this course } // it could be an array of comments or a single comment if (is_array($activity_comments)) { foreach ($activity_comments as $comment) { $user = get_userdata($comment->user_id); if (empty($user)) { // next comment in this array continue; } $course_learner_ids[] = $user->ID; } } else { $user = get_userdata($activity_comments->user_id); $course_learner_ids[] = $user->ID; } // add learners on this course to the all courses learner list $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids); } // if there are no students taking the courses by this teacher don't show them any of the other users if (empty($learner_ids_for_teacher_courses)) { $args['include'] = array(0); } else { $args['include'] = $learner_ids_for_teacher_courses; } // return the WP_Use_Query arguments return $args; }
/** * Load template for displaying course lessons * @since 1.4.0 * @return void */ public function course_lessons() { global $course, $woothemes_sensei, $current_user; $started_course = WooThemes_Sensei_Utils::user_started_course($course->ID, $current_user->ID); if ($started_course) { $woothemes_sensei->frontend->sensei_get_template('course-results/course-lessons.php'); } }
<?php $view_lesson = true; wp_get_current_user(); $lesson_prerequisite = absint(get_post_meta($post->ID, '_lesson_prerequisite', true)); if ($lesson_prerequisite > 0) { // Check for prerequisite lesson completions $view_lesson = WooThemes_Sensei_Utils::user_completed_lesson($lesson_prerequisite, $current_user->ID); } $lesson_course_id = get_post_meta($post->ID, '_lesson_course', true); $user_taking_course = WooThemes_Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID); if (current_user_can('administrator')) { $view_lesson = true; $user_taking_course = true; } $is_preview = false; if (WooThemes_Sensei_Utils::is_preview_lesson($post->ID)) { $is_preview = true; $view_lesson = true; } if ($view_lesson) { ?> <section class="entry fix"> <?php if ($is_preview && !$user_taking_course) { ?> <div class="sensei-message alert"><?php echo $woothemes_sensei->permissions_message['message']; ?> </div> <?php
$lesson_course_id = absint(get_post_meta($post->ID, '_lesson_course', true)); $is_preview = WooThemes_Sensei_Utils::is_preview_lesson($post->ID); // Get User Meta get_currentuserinfo(); // Complete Lesson Logic do_action('sensei_complete_lesson'); // Check that the course has been started if ($woothemes_sensei->access_settings() || WooThemes_Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID) || $is_preview) { ?> <section class="lesson-meta" id="lesson_complete"> <?php if (apply_filters('sensei_video_position', 'top', $post->ID) == 'bottom') { do_action('sensei_lesson_video', $post->ID); } ?> <?php do_action('sensei_frontend_messages'); ?> <?php if (!$is_preview || WooThemes_Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) { do_action('sensei_lesson_quiz_meta', $post->ID, $current_user->ID); } ?> </section> <?php do_action('sensei_lesson_back_link', $lesson_course_id); } else { do_action('sensei_lesson_course_signup', $lesson_course_id); } // End If Statement do_action('sensei_lesson_meta_extra', $post->ID);
/** * Force the re-calculation of all Course statuses working from all Lesson statuses * * @global type $woothemes_sensei * @global type $wpdb * @param type $n * @param type $offset * @return boolean */ function status_changes_repair_course_statuses($n = 50, $offset = 0) { global $woothemes_sensei, $wpdb; $count_object = wp_count_posts('lesson'); $count_published = $count_object->publish; if (0 == $count_published) { return true; } // Calculate if this is the last page if (0 == $offset) { $current_page = 1; } else { $current_page = intval($offset / $n); } $total_pages = ceil($count_published / $n); $course_lesson_ids = $lesson_user_statuses = array(); // Get all Lesson => Course relationships $meta_list = $wpdb->get_results("SELECT {$wpdb->postmeta}.post_id, {$wpdb->postmeta}.meta_value FROM {$wpdb->postmeta} INNER JOIN {$wpdb->posts} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id) WHERE {$wpdb->posts}.post_type = 'lesson' AND {$wpdb->postmeta}.meta_key = '_lesson_course' LIMIT {$n} OFFSET {$offset} ", ARRAY_A); if (!empty($meta_list)) { foreach ($meta_list as $metarow) { $lesson_id = $metarow['post_id']; $course_id = $metarow['meta_value']; $course_lesson_ids[$course_id][] = $lesson_id; } } // Get all Lesson => Course relationships $status_list = $wpdb->get_results("SELECT user_id, comment_post_ID, comment_approved FROM {$wpdb->comments} WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A); if (!empty($status_list)) { foreach ($status_list as $status) { $lesson_user_statuses[$status['comment_post_ID']][$status['user_id']] = $status['comment_approved']; } } $course_completion = $woothemes_sensei->settings->settings['course_completion']; $per_page = 40; $comment_id_offset = $count = 0; $course_sql = "SELECT * FROM {$wpdb->comments} WHERE comment_type = 'sensei_course_status' AND comment_ID > %d LIMIT {$per_page}"; // $per_page users at a time while ($course_statuses = $wpdb->get_results($wpdb->prepare($course_sql, $comment_id_offset))) { foreach ($course_statuses as $course_status) { $user_id = $course_status->user_id; $course_id = $course_status->comment_post_ID; $total_lessons = count($course_lesson_ids[$course_id]); if ($total_lessons <= 0) { $total_lessons = 1; // Fix division of zero error, some courses have no lessons } $lessons_completed = 0; $status = 'in-progress'; // Some Courses have no lessons... (can they ever be complete?) if (!empty($course_lesson_ids[$course_id])) { foreach ($course_lesson_ids[$course_id] as $lesson_id) { $lesson_status = $lesson_user_statuses[$lesson_id][$user_id]; // If lessons are complete without needing quizzes to be passed if ('passed' != $course_completion) { switch ($lesson_status) { // A user cannot 'complete' a course if a lesson... case 'in-progress': // ...is still in progress // ...is still in progress case 'ungraded': // ...hasn't yet been graded break; default: $lessons_completed++; break; } } else { switch ($lesson_status) { case 'complete': // Lesson has no quiz/questions // Lesson has no quiz/questions case 'graded': // Lesson has quiz, but it's not important what the grade was // Lesson has quiz, but it's not important what the grade was case 'passed': // Lesson has quiz and the user passed $lessons_completed++; break; // A user cannot 'complete' a course if on a lesson... // A user cannot 'complete' a course if on a lesson... case 'failed': // ...a user failed the passmark on a quiz // ...a user failed the passmark on a quiz default: break; } } } // Each lesson } // Check for lessons if ($lessons_completed == $total_lessons) { $status = 'complete'; } // update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above $metadata = array('complete' => $lessons_completed, 'percent' => abs(round(doubleval($lessons_completed) * 100 / $total_lessons, 0))); WooThemes_Sensei_Utils::update_course_status($user_id, $course_id, $status, $metadata); $count++; } // per course status $comment_id_offset = $course_status->comment_ID; } // all course statuses if ($current_page == $total_pages) { return true; } else { return false; } }
public function process_grading() { // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry if (isset($_POST['sensei_manual_grade']) && isset($_GET['quiz_id'])) { // error_log( __CLASS__ . ':' . __FUNCTION__ . ':' . print_r($_POST, true)); $quiz_id = $_GET['quiz_id']; $user_id = $_GET['user']; $verify_nonce = wp_verify_nonce($_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading'); if ($verify_nonce && $quiz_id == $_POST['sensei_manual_grade']) { $questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions($quiz_id); $quiz_grade = 0; $count = 0; $quiz_grade_total = $_POST['quiz_grade_total']; foreach ($questions as $question) { ++$count; $question_id = $question->ID; if (isset($_POST['question_' . $question_id])) { $correct = false; $question_grade = 0; $question_total_grade = $_POST['question_total_grade']; if ($_POST['question_' . $question_id] == 'right') { $correct = true; $question_grade = $_POST['question_' . $question_id . '_grade']; } $activity_logged = WooThemes_Sensei_Utils::sensei_grade_question($question_id, $question_grade, $user_id); $quiz_grade += $question_grade; } else { WooThemes_Sensei_Utils::sensei_delete_question_grade($question_id); } // WP slashes all incoming data regardless of Magic Quotes setting (see wp_magic_quotes()), but // as an answer note is not direct post_content it won't have slashes removed, so we need to do it $answer_notes = wp_unslash($_POST['question_' . $question_id . '_notes']); if (!$answer_notes || $answer_notes == '') { $answer_notes = ''; } WooThemes_Sensei_Utils::sensei_add_answer_notes($question_id, $user_id, $answer_notes); } if ($_POST['all_questions_graded'] == 'yes') { $grade = abs(round(doubleval($quiz_grade) * 100 / $quiz_grade_total, 2)); $activity_logged = WooThemes_Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id); // Duplicating what Frontend->sensei_complete_quiz() does $quiz_lesson_id = absint(get_post_meta($quiz_id, '_quiz_lesson', true)); $pass_required = get_post_meta($quiz_id, '_pass_required', true); $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); $lesson_metadata = array(); if ($pass_required) { // Student has reached the pass mark and lesson is complete if ($quiz_passmark <= $grade) { $lesson_status = 'passed'; } else { $lesson_status = 'failed'; } // End If Statement } else { $lesson_status = 'graded'; } $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above WooThemes_Sensei_Utils::update_lesson_status($user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata); switch ($lesson_status) { case 'passed': case 'graded': do_action('sensei_user_lesson_end', $user_id, $quiz_lesson_id); break; } } if (isset($_POST['sensei_grade_next_learner']) && strlen($_POST['sensei_grade_next_learner']) > 0) { $load_url = add_query_arg(array('message' => 'graded')); } elseif (isset($_POST['_wp_http_referer'])) { $load_url = add_query_arg(array('message' => 'graded'), $_POST['_wp_http_referer']); } else { $load_url = add_query_arg(array('message' => 'graded')); } wp_safe_redirect($load_url); exit; } } }
function savedquest_options() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } echo '<div class="wrap" style="background:#fff;">'; if (isset($_GET['tab'])) { $tab = $_GET['tab']; } else { $tab = ""; } saved_admin_tab($tab); if ($tab == "quiztaken" or $tab == "") { ?> <table class="wp-list-table widefat fixed striped pages" width="100%" style="border-spacing: 0; text-align:center;" > <tr> <th>Lesson ID</th> <th>Lesson Title</th> <th>Number Of Questions</th> <th>Question Answered</th> <th>Unanswered Question</th> <th>User</th> <th>User Id</th> <th>DATE And Time</th> </tr> <?php $svequiz = get_option('savequiz_list'); ?> <?php foreach ($svequiz as $quizdata) { ?> <tr> <td><?php echo $quizdata['lesson_id']; ?> </td> <td><?php echo $quizdata['lesson_title']; ?> </td> <td><?php echo $quizdata['total_questtion']; ?> </td> <td><?php echo $quizdata['question_answered']; ?> (<?php echo get_percentage($quizdata['total_questtion'], $quizdata['question_answered']) . "%"; ?> )</td> <td><?php echo $quizdata['remaining_question']; ?> (<?php echo 100 - get_percentage($quizdata['total_questtion'], $quizdata['question_answered']) . "%"; ?> )</td> <td><?php echo $quizdata['fullname']; ?> </td> <td><?php echo $quizdata['user_id']; ?> </td> <td><?php echo $quizdata['DATETIME']; ?> </td> </tr> <?php } ?> </table> <?php } elseif ($tab == "timesession") { $user_last_login_logout = get_option('user_last_login_logout'); ?> <br /><br/> <table class="wp-list-table widefat fixed striped pages" width="100%" style="border-spacing: 0; text-align:center;" > <tr> <th>User ID</th> <th>Full Name</th> <th>Last Login</th> <th>Last Logout</th> <th>Amout of Time Spent</th> <th>Role</th> </tr> <?php $svequiz = get_option('savequiz_list'); ?> <?php foreach ($user_last_login_logout as $last_login_logout) { ?> <?php if ($last_login_logout['user_id'] != "") { ?> <?php $user_info = get_userdata($last_login_logout['user_id']); ?> <tr> <td><?php echo $last_login_logout['user_id']; ?> </td> <td><?php echo $user_info->display_name; ?> </td> <td><?php echo gettime_st($last_login_logout['logintime']); ?> </td> <td><?php echo gettime_st($last_login_logout['logouttime']); ?> </td> <?php if ($last_login_logout['logouttime'] != "") { $date1 = date_create($last_login_logout['logintime']); $date2 = date_create($last_login_logout['logouttime']); $diff = date_diff($date1, $date2); $diftime = $diff->format("%h Hours %i Minute %s Seconds"); } else { $diftime = ""; } ?> <th><?php echo $diftime; ?> </th> <td><?php echo implode(', ', $user_info->roles); ?> </td> </tr> <?php } ?> <?php } ?> </table><br /><br /> <?php } elseif ($tab == "timequizecompleted") { global $woothemes_sensei, $post, $current_user, $wp_query, $learner_user; echo "<table class='wp-list-table widefat fixed striped pages'>"; $allUsers = get_users(); echo "<tr>\r\r\n\t\t\t\t<th>User</th>\r\r\n\t\t\t\t<th>Courses</th>\r\r\n\t\t\t\t<th>Percentage Incomplete</th>\r\r\n\t\t\t\t<th>Percentage Complete</th>\r\r\n\t\t\t\t<th>Percentage Competent</th>\r\r\n\t\t\t\t<th>Percentage Attempted</th>\r\r\n\t\t\t\t<th>Length of time Course Completed</th>\r\r\n\t\t\t </tr>"; foreach ($allUsers as $user) { $args = array('post_type' => 'course'); $courses = get_posts($args); $i = 1; foreach ($courses as $course) { $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($course->ID, $user->ID); $course_status = WooThemes_Sensei_Utils::user_course_status($course->ID, $user->ID); $course_status_update = get_comment_meta($course_status->comment_ID); if (!empty($course_status)) { $displayed_lessons = array(); $modules = Sensei()->modules->get_course_modules(intval($course->ID)); foreach ($modules as $module) { $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($course->ID), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0); $lessons = get_posts($args); if (count($lessons) > 0) { $html .= '<h3>' . $module->name . '</h3>' . "\n"; $count = 0; foreach ($lessons as $lesson_item) { $lesson_grade = ' n/a'; $has_questions = get_post_meta($lesson_item->ID, '_quiz_has_questions', true); if ($has_questions) { $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $user->ID); // Get user quiz grade $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); if ($lesson_grade) { $lesson_grade .= '%'; } $modulequizdata = get_comment_meta($lesson_status->comment_ID); //echo "<a href='".get_post_permalink($lesson_item->ID)."'>".$lesson_item->post_title."</a><br />"; $modulequestion_asked = count(explode(",", $modulequizdata['questions_asked'][0])); $moduleanswered_quiz = count(unserialize($modulequizdata['quiz_answers'][0])); //echo "number of questions:".$modulequestion_asked."<br />"; //echo "number of Answered:".$moduleanswered_quiz."<br />"; if ($course_status->comment_approved == "complete") { $attempted = "(100%)"; } else { if ($modulequizdata['grade'][0] == "") { if ($lesson_status->comment_approved == "passed") { $attempted = 'P/Q'; } else { if ($modulequestion_asked >= $moduleanswered_quiz) { if ($modulequizdata['quiz_answers'][0] == "") { $attempted = ""; } else { $attempted = "( " . get_percentage($modulequestion_asked, $moduleanswered_quiz) . "% ) Saved"; } } } } else { $attempted = "( " . get_percentage($modulequestion_asked, $moduleanswered_quiz) . "% )"; } //echo "<pre>"; //echo "Attempted:".$attempted."<br />"; //echo $user->user_email."<br />"; //echo $modulequizdata['grade'][0]."<br />"; //echo $modulequizdata['quiz_answers'][0]."<br />"; //print_r($lesson_status); //echo "</pre>"; } } $html .= '<a href="' . esc_url(get_permalink($lesson_item->ID)) . '" title="' . esc_attr(sprintf(__('Start %s', 'woothemes-sensei'), $lesson_item->post_title)) . '">' . esc_html(sprintf(__('%s', 'woothemes-sensei'), $lesson_item->post_title)) . '</a> ' . $attempted . '<br />'; $displayed_lessons[] = $lesson_item->ID; } } } $args = array('post_type' => 'lesson', 'posts_per_page' => -1, 'suppress_filters' => 0, 'meta_key' => '_order_' . $course->ID, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($course->ID))), 'post__not_in' => $displayed_lessons); $lessons = get_posts($args); //echo "Number of lesson in a course: ".count($lessons); if (0 < count($lessons)) { $html .= '<h3>' . __('Other Lessons', 'woothemes-sensei') . '</h3>' . "\n"; } if ($course_status_update['percent'][0] == 100) { $date1 = date_create($course_status_update['start'][0]); $date2 = date_create($course_status->comment_date); $diff = date_diff($date1, $date2); $diftime = $diff->format("%h Hours %i Minute %s Seconds"); } else { $diftime = "course not completed yet."; } $allcourseid[] = $course->ID; $incomplete = 100 - $course_status_update['percent'][0]; echo "<tr><td>"; echo $user->user_email; echo "</td>"; echo "<td>"; echo "<a href='" . get_post_permalink($course->ID) . "'>" . $course->post_title . "</a>"; echo "</td>"; echo "<td>"; echo $incomplete . "%"; echo "</td>"; echo "<td>"; echo $course_status_update['percent'][0] . "%"; echo "</td>"; echo "<td>"; echo $course_user_grade . "%"; echo "</td>"; echo "<td>"; echo $html; $html = ""; foreach ($lessons as $lesson_item) { $lesson_grade = 'n/a'; $has_questions = get_post_meta($lesson_item->ID, '_quiz_has_questions', true); if ($has_questions) { $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $user->ID); // Get user quiz grade $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); if ($lesson_grade) { $lesson_grade .= '%'; } } $quizdata = get_comment_meta($lesson_status->comment_ID); //echo "<h1>Comment</h1>"; //print_r(get_comment_meta( $lesson_status->comment_ID )); //echo "<h1>LESSON STATUS</h1>"; //print_r($lesson_status); echo "<a href='" . get_post_permalink($lesson_item->ID) . "'>" . $lesson_item->post_title . "</a> "; //print_r($quizdata); $question_asked = count(explode(",", $quizdata['questions_asked'][0])); $answered_quiz = count(unserialize($quizdata['quiz_answers'][0])); if ($quizdata['grade'][0] == "") { if ($question_asked > $answered_quiz) { echo "( " . get_percentage($question_asked, $answered_quiz) . "% )"; } } else { echo "(100%)"; } echo '<br />'; } // End For Loop echo "</td>"; echo "<td>"; echo $diftime; echo "</td>"; echo "</tr>"; //echo $course->post_title." (".$course_status_update['percent'][0]."% Complete) (". $incomplete . "% incomplete) (". $course_user_grade . "% Competent)<br />"; $i++; } } } echo "</table>"; } elseif ($tab == "threshold") { //declare the wpdb for custom query global $wpdb; //check for submitted data if (isset($_POST['submittreshold']) && ($_POST['submittreshold'] = "submit")) { // declare users and variables $allUsers = get_users(); $modules_completed = $_POST['completionpermonth']; $courseid = $_POST['course']; $course_name = get_the_title($courseid); $array_to_csv = array(array('Student Name', 'Course Name ')); //user loop ----- loop user get the groups and course the course they take foreach ($allUsers as $user) { //declare course function calls $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($courseid, $user->ID); $user_course_status = WooThemes_Sensei_Utils::user_course_status($courseid, $user->ID); $course_status_info = get_comment_meta($user_course_status->comment_ID); $started_course = WooThemes_Sensei_Utils::user_started_course($courseid, $user->ID); $course_status = WooThemes_Sensei_Utils::sensei_user_course_status_message($courseid, $user->ID); $completed_course = WooThemes_Sensei_Utils::user_completed_course($user_course_status); //get the user groups $useringroup = new Groups_User($user->ID); $user_groups = $useringroup->__get('groups'); $displayed_lessons = array(); //declare and get module values $modules = Sensei()->modules->get_course_modules(intval($courseid)); $modules_content = Sensei()->modules->course_module_content(intval($courseid)); //echo "<pre>"; //echo $user->user_email."<br />"; //echo "sensei_user_course_status_message: "; //print_r($course_status); //echo "<br />"; //echo "started_course: "."<br />"; $course_status_info['start'][0]; $datenow = date('Y-m-d h:i:s'); $date1 = date_create($course_status_info['start'][0]); $date2 = date_create($datenow); $diff = date_diff($date1, $date2); $diftime = $diff->format("%m"); if ($diftime < 1) { $diftime = 1; } //echo "</pre>"; //module loop per user foreach ($modules as $module) { $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($courseid), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0); $lessons = get_posts($args); $num_of_lesson = count($lessons); //lessson loop per user foreach ($lessons as $lesson_item) { $is_lesson_completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_item->ID, $user->ID); if ($is_lesson_completed == 1) { $lesson_completed[] = $is_lesson_completed; } } //echo "lesson completed:". count($lesson_completed)."<br />"; if (count($lesson_completed) > 0) { if ($num_of_lesson == count($lesson_completed)) { $completed_modules_per_user[] = 1; $total_module_passed[] = 1; //echo "---Module completed <br />"; } else { //echo "---Module not completed <br />"; } } else { //echo "---Module not completed <br />"; } unset($lesson_completed); unset($completed_modules_per_user); } $overaalltotal_module_passed = count($total_module_passed); //echo $overaalltotal_module_passed . " module being passed"; //loop throughout the user group under a user if (is_array($user_groups)) { foreach ($user_groups as $user_group) { if ($user_group->group_id == $_POST['group']) { if (!empty($user_course_status)) { $modules_completed_from_groups = $user_group->description; if ($modules_completed == "") { $modules_completed = $modules_completed_from_groups; } $num_of_module_x_difftime = $modules_completed * $diftime; //echo "<br />num_of_module_x_difftime:".$num_of_module_x_difftime; if ($overaalltotal_module_passed >= $num_of_module_x_difftime) { $array_to_csv[] = array($user->display_name, $course_name); //$userid_within_group[$user->user_email] = $user->ID; } } } //echo $user_group->group_id."<br />"; } } unset($total_module_passed); } //echo "<pre>"; //echo $modules_completed; //print_r($array_to_csv); //echo "</pre>"; convert_to_csv($array_to_csv, 'report-' . md5(date('Y-m-d h:i:s')) . '.csv', ','); } ?> <div class="form-wrap" style="padding:20px;"> <form action="" method="post"> <div> <label> Group: </label> <?php $groups = $wpdb->get_results('SELECT * FROM `wp_groups_group`'); ?> <select name="group"> <?php foreach ($groups as $group) { echo "<option value='" . $group->group_id . "'>"; echo $group->name; echo "</option>"; } ?> </select> </div> <div> <label> Course: </label> <?php $course = new WP_Query(array('post_type' => 'course')); ?> <select name="course"> <?php // The Loop if ($course->have_posts()) { while ($course->have_posts()) { $course->the_post(); echo '<option value="' . $course->post->ID . '">' . get_the_title() . '</option>'; } } /* Restore original Post Data */ ?> </select> <?php wp_reset_postdata(); ?> </div> <div> <label> How many modules should be completed by now? </label> <input type="text" name="completionpermonth" /> </div><br /><br /> <input type="submit" class="button button-primary" name="submittreshold" value="submit" /> </form> </div> <?php } elseif ($tab == "incremental-progress") { wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css'); //declare the wpdb for custom query global $wpdb; //check for submitted data if (isset($_POST['submitincrenmental']) && ($_POST['submitincrenmental'] = "submit")) { // declare users and variables $allUsers = get_users(); $modules_completed = $_POST['completionpermonth']; $courseid = $_POST['course']; $course_name = get_the_title($courseid); $array_to_csv = array(array('Student Name', 'Course Name ', 'Lesson Title')); //user loop ----- loop user get the groups and course the course they take foreach ($allUsers as $user) { //declare course function calls $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($courseid, $user->ID); $user_course_status = WooThemes_Sensei_Utils::user_course_status($courseid, $user->ID); $course_status_info = get_comment_meta($user_course_status->comment_ID); $started_course = WooThemes_Sensei_Utils::user_started_course($courseid, $user->ID); $course_status = WooThemes_Sensei_Utils::sensei_user_course_status_message($courseid, $user->ID); $completed_course = WooThemes_Sensei_Utils::user_completed_course($user_course_status); //get the user groups $useringroup = new Groups_User($user->ID); $user_groups = $useringroup->__get('groups'); $displayed_lessons = array(); //declare and get module values $modules = Sensei()->modules->get_course_modules(intval($courseid)); $modules_content = Sensei()->modules->course_module_content(intval($courseid)); $course_status_info['start'][0]; $datenow = date('Y-m-d h:i:s'); $date1 = date_create($course_status_info['start'][0]); $date2 = date_create($datenow); $diff = date_diff($date1, $date2); $diftime = $diff->format("%m"); if ($diftime < 1) { $diftime = 1; } //echo "</pre>"; //module loop per user foreach ($modules as $module) { $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($courseid), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0); $lessons = get_posts($args); $num_of_lesson = count($lessons); //lessson loop per user foreach ($lessons as $lesson_item) { $is_lesson_completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_item->ID, $user->ID); $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $user->ID); $modulequizdata = get_comment_meta($lesson_status->comment_ID); if (!empty($lesson_status->comment_date)) { echo "<pre>"; //echo $lesson_status->comment_date."<br />"; //echo $_POST['date1']."<br />"; $lesson_completion_date = date("Y-m-d", strtotime($lesson_status->comment_date)); //echo "<br />"; //echo $_POST['date2']."<br />"; //echo "lesson is completed:".$is_lesson_completed."<br />"; //print_r($lesson_item); echo "</pre>"; } if ($is_lesson_completed == 1) { $date1 = strtotime($_POST['date1']); $date2 = strtotime($_POST['date2']); $lesson_completion_date_str = strtotime($lesson_completion_date); if ($lesson_completion_date_str > $date1 && $lesson_completion_date_str < $date2) { //echo "lesson is completed:".$is_lesson_completed."<br />"; //echo "user ".$user->display_name." pass this". $lesson_completion_date; $user_id_onrange[$user->ID] = $lesson_item->post_title; } } } //echo "lesson completed:". count($lesson_completed)."<br />"; } //loop throughout the user group under a user if (is_array($user_groups)) { foreach ($user_groups as $user_group) { if ($user_group->group_id == $_POST['group']) { if (!empty($user_course_status)) { if (array_key_exists($user->ID, $user_id_onrange)) { $array_to_csv[] = array($user->display_name, $course_name, $user_id_onrange[$user->ID]); } } } //echo $user_group->group_id."<br />"; } } } //print_r($user_id_onrange); //echo "<pre>"; //echo $modules_completed; //print_r($array_to_csv); //echo "</pre>"; convert_to_csv($array_to_csv, 'report-incremental-progress' . md5(date('Y-m-d h:i:s')) . '.csv', $headers); } ?> <div class="form-wrap" style="padding:20px;"> <form action="" method="post"> <div> <label> Group: </label> <?php $groups = $wpdb->get_results('SELECT * FROM `wp_groups_group`'); ?> <select name="group"> <?php foreach ($groups as $group) { echo "<option value='" . $group->group_id . "'>"; echo $group->name; echo "</option>"; } ?> </select> </div><br /> <div> <label> Course: </label> <?php $course = new WP_Query(array('post_type' => 'course')); ?> <select name="course"> <?php // The Loop if ($course->have_posts()) { while ($course->have_posts()) { $course->the_post(); echo '<option value="' . $course->post->ID . '">' . get_the_title() . '</option>'; } } /* Restore original Post Data */ ?> </select> <?php wp_reset_postdata(); ?> </div><br /> <div> <label> Date: </label> From<input type="text" id="date1" name="date1" /> to <input type="text" id="date2" name="date2" /> </div><br /><br /> <input type="submit" class="button button-primary" name="submitincrenmental" value="submit" /> </form> </div> <script> jQuery(document).ready(function() { jQuery('#date1').datepicker({ dateFormat : 'yy-mm-dd' }); jQuery('#date2').datepicker({ dateFormat : 'yy-mm-dd' }); }); </script> <?php } elseif ($tab == "total-progress") { //declare the wpdb for custom query global $wpdb; //check for submitted data if (isset($_POST['submittotalprogress']) && ($_POST['submittotalprogress'] = "submit")) { // declare users and variables $allUsers = get_users(); $modules_completed = $_POST['completionpermonth']; $courseid = $_POST['course']; $course_name = get_the_title($courseid); $array_to_csv = array(array('Student Name', 'Course Name', 'Lesson Title')); //user loop ----- loop user get the groups and course the course they take foreach ($allUsers as $user) { //declare course function calls $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($courseid, $user->ID); $user_course_status = WooThemes_Sensei_Utils::user_course_status($courseid, $user->ID); $course_status_info = get_comment_meta($user_course_status->comment_ID); $started_course = WooThemes_Sensei_Utils::user_started_course($courseid, $user->ID); $course_status = WooThemes_Sensei_Utils::sensei_user_course_status_message($courseid, $user->ID); $completed_course = WooThemes_Sensei_Utils::user_completed_course($user_course_status); //get the user groups $useringroup = new Groups_User($user->ID); $user_groups = $useringroup->__get('groups'); $displayed_lessons = array(); //declare and get module values $modules = Sensei()->modules->get_course_modules(intval($courseid)); $modules_content = Sensei()->modules->course_module_content(intval($courseid)); //echo "<pre>"; //echo $user->user_email."<br />"; //echo "sensei_user_course_status_message: "; //print_r($course_status); //echo "<br />"; //echo "started_course: "."<br />"; $course_status_info['start'][0]; $datenow = date('Y-m-d h:i:s'); $date1 = date_create($course_status_info['start'][0]); $date2 = date_create($datenow); $diff = date_diff($date1, $date2); $diftime = $diff->format("%m"); if ($diftime < 1) { $diftime = 1; } //echo "</pre>"; //module loop per user foreach ($modules as $module) { $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($courseid), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0); $lessons = get_posts($args); $num_of_lesson = count($lessons); //lessson loop per user foreach ($lessons as $lesson_item) { $is_lesson_completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_item->ID, $user->ID); if ($is_lesson_completed == 1) { $lesson_taken[$user->ID][] = $lesson_item->post_title; } } } $overaalltotal_module_passed = count($total_module_passed); //echo $overaalltotal_module_passed . " module being passed"; //loop throughout the user group under a user if (is_array($user_groups)) { foreach ($user_groups as $user_group) { if ($user_group->group_id == $_POST['group']) { if (!empty($user_course_status)) { $array_to_csv[] = array($user->display_name, $course_name, join("|", $lesson_taken[$user->ID])); //$userid_within_group[$user->user_email] = $user->ID; } } //echo $user_group->group_id."<br />"; } } //echo "<pre>"; //print_r($lesson_taken); //echo "<pre>"; unset($total_module_passed); unset($lesson_taken); } //echo "<pre>"; //echo $modules_completed; //print_r($array_to_csv); //echo "</pre>"; convert_to_csv($array_to_csv, 'report-total-progress' . md5(date('Y-m-d h:i:s')) . '.csv', ','); } ?> <div class="form-wrap" style="padding:20px;"> <form action="" method="post"> <div> <label> Group: </label> <?php $groups = $wpdb->get_results('SELECT * FROM `wp_groups_group`'); ?> <select name="group"> <?php foreach ($groups as $group) { echo "<option value='" . $group->group_id . "'>"; echo $group->name; echo "</option>"; } ?> </select> </div> <div> <label> Course: </label> <?php $course = new WP_Query(array('post_type' => 'course')); ?> <select name="course"> <?php // The Loop if ($course->have_posts()) { while ($course->have_posts()) { $course->the_post(); echo '<option value="' . $course->post->ID . '">' . get_the_title() . '</option>'; } } /* Restore original Post Data */ ?> </select> <?php wp_reset_postdata(); ?> </div> <br /><br /> <input type="submit" class="button button-primary" name="submittotalprogress" value="submit" /> </form> </div> <?php } echo '</div>'; }
?> "> <span><?php echo $answer_message; ?> </span> </div> <?php } ?> <input type="hidden" name="<?php echo esc_attr('question_id_' . $question_id); ?> " value="<?php echo esc_attr($question_id); ?> " /> <?php WooThemes_Sensei_Utils::sensei_text_editor($user_answer_entry, 'textquestion' . $question_id, 'sensei_question[' . $question_id . ']'); ?> <?php if ($answer_notes) { ?> <div class="sensei-message info info-special"><?php echo apply_filters('the_content', $answer_notes); ?> </div> <?php } ?> </li>
/** * Add settings fields. * @access public * @since 1.0.0 * @uses Sensei_Utils::get_slider_types() * @return void */ public function init_fields() { global $pagenow; $pages_array = $this->pages_array(); $posts_per_page_array = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20'); $complete_settings = array('passed' => __('Once all the course lessons have been completed', 'woothemes-sensei'), 'complete' => __('At any time (by clicking the \'Complete Course\' button)', 'woothemes-sensei')); $course_display_settings = array('excerpt' => __('Course Excerpt', 'woothemes-sensei'), 'full' => __('Full Course Content', 'woothemes-sensei')); $fields = array(); $fields['access_permission'] = array('name' => __('Access Permissions', 'woothemes-sensei'), 'description' => __('Users must be logged in to view Course and Lesson content.', 'woothemes-sensei', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => true, 'section' => 'default-settings'); $fields['messages_disable'] = array('name' => __('Disable Private Messages', 'woothemes-sensei'), 'description' => __('Disable the private message functions between learners and teachers.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => false, 'section' => 'default-settings'); $fields['course_page'] = array('name' => __('Course Archive Page', 'woothemes-sensei'), 'description' => __('The page to use to display courses. If you leave this blank the default custom post type archive will apply.', 'woothemes-sensei'), 'type' => 'select', 'default' => get_option('woothemes-sensei_courses_page_id', 0), 'section' => 'default-settings', 'required' => 0, 'options' => $pages_array); $fields['my_course_page'] = array('name' => __('My Courses Page', 'woothemes-sensei'), 'description' => __('The page to use to display the courses that a user is currently taking as well as the courses a user has complete.', 'woothemes-sensei'), 'type' => 'select', 'default' => get_option('woothemes-sensei_user_dashboard_page_id', 0), 'section' => 'default-settings', 'required' => 0, 'options' => $pages_array); $fields['placeholder_images_enable'] = array('name' => __('Use placeholder images', 'woothemes-sensei'), 'description' => __('Output a placeholder image when no featured image has been specified for Courses and Lessons.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => false, 'section' => 'default-settings'); $fields['styles_disable'] = array('name' => __('Disable Sensei Styles', 'woothemes-sensei'), 'description' => __('Prevent the frontend stylesheets from loading. This will remove the default styles for all Sensei elements.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => false, 'section' => 'default-settings'); $fields['js_disable'] = array('name' => __('Disable Sensei Javascript', 'woothemes-sensei'), 'description' => __('Prevent the frontend javascript from loading. This affects the progress bars and the My Courses tabs.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => false, 'section' => 'default-settings'); // Course Settings $fields['course_completion'] = array('name' => __('Courses are complete:', 'woothemes-sensei'), 'description' => __('This will determine when courses are marked as complete.', 'woothemes-sensei'), 'type' => 'select', 'default' => 'passed', 'section' => 'course-settings', 'required' => 0, 'options' => $complete_settings); $fields['course_author'] = array('name' => __('Display Course Author', 'woothemes-sensei'), 'description' => __('Output the Course Author on Course archive and My Courses page.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => true, 'section' => 'course-settings'); $fields['course_archive_amount'] = array('name' => __('Course Archive Pagination', 'woothemes-sensei'), 'description' => __('The number of courses to output for the archive pages.', 'woothemes-sensei'), 'type' => 'range', 'default' => '0', 'section' => 'course-settings', 'required' => 0, 'options' => $posts_per_page_array); $fields['my_course_amount'] = array('name' => __('My Courses Pagination', 'woothemes-sensei'), 'description' => __('The number of courses to output for the my courses page.', 'woothemes-sensei'), 'type' => 'range', 'default' => '0', 'section' => 'course-settings', 'required' => 0, 'options' => $posts_per_page_array); $fields['course_archive_image_enable'] = array('name' => __('Course Archive Image', 'woothemes-sensei'), 'description' => __('Output the Course Image on the Course Archive Page.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => true, 'section' => 'course-settings'); $fields['course_archive_image_width'] = array('name' => __('Image Width - Archive', 'woothemes-sensei'), 'description' => __('The width in pixels of the featured image for the Course Archive page.', 'woothemes-sensei'), 'type' => 'text', 'default' => '100', 'section' => 'course-settings', 'required' => 0); $fields['course_archive_image_height'] = array('name' => __('Image Height - Archive', 'woothemes-sensei'), 'description' => __('The height in pixels of the featured image for the Course Archive page.', 'woothemes-sensei'), 'type' => 'text', 'default' => '100', 'section' => 'course-settings', 'required' => 0); $fields['course_archive_image_hard_crop'] = array('name' => __('Image Hard Crop - Archive', 'woothemes-sensei'), 'description' => sprintf(__('After changing this setting you may need to <a href="%s">regenerate your thumbnails</a>.', 'woothemes-sensei'), 'http://wordpress.org/extend/plugins/regenerate-thumbnails/'), 'type' => 'checkbox', 'default' => false, 'section' => 'course-settings'); $fields['course_single_image_enable'] = array('name' => __('Single Course Image', 'woothemes-sensei'), 'description' => __('Output the Course Image on the Single Course Page.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => false, 'section' => 'course-settings'); $fields['course_single_image_width'] = array('name' => __('Image Width - Single', 'woothemes-sensei'), 'description' => __('The width in pixels of the featured image for the Course single post page.', 'woothemes-sensei'), 'type' => 'text', 'default' => '100', 'section' => 'course-settings', 'required' => 0); $fields['course_single_image_height'] = array('name' => __('Image Height - Single', 'woothemes-sensei'), 'description' => __('The height in pixels of the featured image for the Course single post page.', 'woothemes-sensei'), 'type' => 'text', 'default' => '100', 'section' => 'course-settings', 'required' => 0); $fields['course_single_image_hard_crop'] = array('name' => __('Image Hard Crop - Single', 'woothemes-sensei'), 'description' => sprintf(__('After changing this setting you may need to <a href="%s">regenerate your thumbnails</a>.', 'woothemes-sensei'), 'http://wordpress.org/extend/plugins/regenerate-thumbnails/'), 'type' => 'checkbox', 'default' => false, 'section' => 'course-settings'); $fields['course_single_content_display'] = array('name' => __('Single Course page displays:', 'woothemes-sensei'), 'description' => __('Determines what content to display on the single course page.', 'woothemes-sensei'), 'type' => 'select', 'default' => 'excerpt', 'section' => 'course-settings', 'required' => 0, 'options' => $course_display_settings); $fields['course_archive_featured_enable'] = array('name' => __('Featured Courses Panel', 'woothemes-sensei'), 'description' => __('Output the Featured Courses Panel on the Course Archive Page.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => true, 'section' => 'course-settings'); $fields['course_archive_more_link_text'] = array('name' => __('More link text', 'woothemes-sensei'), 'description' => __('The text that will be displayed on the Course Archive for the more courses link.', 'woothemes-sensei'), 'type' => 'text', 'default' => __('More', 'woothemes-sensei'), 'section' => 'course-settings', 'required' => 0); // Lesson Settings $fields['lesson_comments'] = array('name' => __('Allow Comments for Lessons', 'woothemes-sensei'), 'description' => __('This will allow learners to post comments on the single Lesson page, only learner who have access to the Lesson will be allowed to comment.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => true, 'section' => 'lesson-settings'); $fields['lesson_author'] = array('name' => __('Display Lesson Author', 'woothemes-sensei'), 'description' => __('Output the Lesson Author on Course single page & Lesson archive page.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => true, 'section' => 'lesson-settings'); $fields['course_lesson_image_enable'] = array('name' => __('Course Lesson Images', 'woothemes-sensei'), 'description' => __('Output the Lesson Image on the Single Course Page.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => false, 'section' => 'lesson-settings'); $fields['lesson_archive_image_width'] = array('name' => __('Image Width - Course Lessons', 'woothemes-sensei'), 'description' => __('The width in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei'), 'type' => 'text', 'default' => '100', 'section' => 'lesson-settings', 'required' => 0); $fields['lesson_archive_image_height'] = array('name' => __('Image Height - Course Lessons', 'woothemes-sensei'), 'description' => __('The height in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei'), 'type' => 'text', 'default' => '100', 'section' => 'lesson-settings', 'required' => 0); $fields['lesson_archive_image_hard_crop'] = array('name' => __('Image Hard Crop - Course Lessons', 'woothemes-sensei'), 'description' => sprintf(__('After changing this setting you may need to <a href="%s">regenerate your thumbnails</a>.', 'woothemes-sensei'), 'http://wordpress.org/extend/plugins/regenerate-thumbnails/'), 'type' => 'checkbox', 'default' => false, 'section' => 'lesson-settings'); $fields['lesson_single_image_enable'] = array('name' => __('Single Lesson Images', 'woothemes-sensei'), 'description' => __('Output the Lesson Image on the Single Lesson Page.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => false, 'section' => 'lesson-settings'); $fields['lesson_single_image_width'] = array('name' => __('Image Width - Single', 'woothemes-sensei'), 'description' => __('The width in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei'), 'type' => 'text', 'default' => '100', 'section' => 'lesson-settings', 'required' => 0); $fields['lesson_single_image_height'] = array('name' => __('Image Height - Single', 'woothemes-sensei'), 'description' => __('The height in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei'), 'type' => 'text', 'default' => '100', 'section' => 'lesson-settings', 'required' => 0); $fields['lesson_single_image_hard_crop'] = array('name' => __('Image Hard Crop - Single', 'woothemes-sensei'), 'description' => sprintf(__('After changing this setting you may need to <a href="%s">regenerate your thumbnails</a>.', 'woothemes-sensei'), 'http://wordpress.org/extend/plugins/regenerate-thumbnails/'), 'type' => 'checkbox', 'default' => false, 'section' => 'lesson-settings'); // Learner Profile settings $profile_url_base = apply_filters('sensei_learner_profiles_url_base', __('learner', 'woothemes-sensei')); $profile_url_example = trailingslashit(get_site_url()) . $profile_url_base . '/%username%'; $fields['learner_profile_enable'] = array('name' => __('Public learner profiles', 'woothemes-sensei'), 'description' => sprintf(__('Enable public learner profiles that will be accessible to everyone. Profile URL format: %s', 'woothemes-sensei'), $profile_url_example), 'type' => 'checkbox', 'default' => true, 'section' => 'learner-profile-settings'); $fields['learner_profile_show_courses'] = array('name' => __('Show learner\'s courses', 'woothemes-sensei'), 'description' => __('Display the learner\'s active and completed courses on their profile.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => true, 'section' => 'learner-profile-settings'); // Email notifications $learner_email_options = array('learner-graded-quiz' => __('Their quiz is graded (auto and manual grading)', 'woothemes-sensei'), 'learner-completed-course' => __('They complete a course', 'woothemes-sensei')); $teacher_email_options = array('teacher-completed-course' => __('A learner completes their course', 'woothemes-sensei'), 'teacher-started-course' => __('A learner starts their course', 'woothemes-sensei'), 'teacher-quiz-submitted' => __('A learner submits a quiz for grading', 'woothemes-sensei'), 'teacher-new-message' => __('A learner sends a private message to a teacher', 'woothemes-sensei')); $global_email_options = array('new-message-reply' => __('They receive a reply to their private message', 'woothemes-sensei')); $fields['email_learners'] = array('name' => __('Emails Sent to Learners', 'woothemes-sensei'), 'description' => __('Select the notifications that will be sent to learners.', 'woothemes-sensei'), 'type' => 'multicheck', 'options' => $learner_email_options, 'defaults' => array('learner-graded-quiz', 'learner-completed-course'), 'section' => 'email-notification-settings'); $fields['email_teachers'] = array('name' => __('Emails Sent to Teachers', 'woothemes-sensei'), 'description' => __('Select the notifications that will be sent to teachers.', 'woothemes-sensei'), 'type' => 'multicheck', 'options' => $teacher_email_options, 'defaults' => array('teacher-completed-course', 'teacher-started-course', 'teacher-quiz-submitted', 'teacher-new-message'), 'section' => 'email-notification-settings'); $fields['email_global'] = array('name' => __('Emails Sent to All Users', 'woothemes-sensei'), 'description' => __('Select the notifications that will be sent to all users.', 'woothemes-sensei'), 'type' => 'multicheck', 'options' => $global_email_options, 'defaults' => array('new-message-reply'), 'section' => 'email-notification-settings'); $fields['email_from_name'] = array('name' => __('"From" Name', 'woothemes-sensei'), 'description' => __('The name from which all emails will be sent.', 'woothemes-sensei'), 'type' => 'text', 'default' => get_bloginfo('name'), 'section' => 'email-notification-settings', 'required' => 1); $fields['email_from_address'] = array('name' => __('"From" Address', 'woothemes-sensei'), 'description' => __('The address from which all emails will be sent.', 'woothemes-sensei'), 'type' => 'text', 'default' => get_bloginfo('admin_email'), 'section' => 'email-notification-settings', 'required' => 1); $fields['email_header_image'] = array('name' => __('Header Image', 'woothemes-sensei'), 'description' => sprintf(__('Enter a URL to an image you want to show in the email\'s header. Upload your image using the %1$smedia uploader%2$s.', 'woothemes-sensei'), '<a href="' . admin_url('media-new.php') . '">', '</a>'), 'type' => 'text', 'default' => '', 'section' => 'email-notification-settings', 'required' => 0); $fields['email_footer_text'] = array('name' => __('Email Footer Text', 'woothemes-sensei'), 'description' => __('The text to appear in the footer of Sensei emails.', 'woothemes-sensei'), 'type' => 'textarea', 'default' => sprintf(__('%1$s - Powered by Sensei', 'woothemes-sensei'), get_bloginfo('name')), 'section' => 'email-notification-settings', 'required' => 0); $fields['email_base_color'] = array('name' => __('Base Colour', 'woothemes-sensei'), 'description' => sprintf(__('The base colour for Sensei email templates. Default %1$s#557da1%2$s.', 'woothemes-sensei'), '<code>', '</code>'), 'type' => 'color', 'default' => '#557da1', 'section' => 'email-notification-settings', 'required' => 1); $fields['email_background_color'] = array('name' => __('Background Colour', 'woothemes-sensei'), 'description' => sprintf(__('The background colour for Sensei email templates. Default %1$s#f5f5f5%2$s.', 'woothemes-sensei'), '<code>', '</code>'), 'type' => 'color', 'default' => '#f5f5f5', 'section' => 'email-notification-settings', 'required' => 1); $fields['email_body_background_color'] = array('name' => __('Body Background Colour', 'woothemes-sensei'), 'description' => sprintf(__('The main body background colour for Sensei email templates. Default %1$s#fdfdfd%2$s.', 'woothemes-sensei'), '<code>', '</code>'), 'type' => 'color', 'default' => '#fdfdfd', 'section' => 'email-notification-settings', 'required' => 1); $fields['email_text_color'] = array('name' => __('Body Text Colour', 'woothemes-sensei'), 'description' => sprintf(__('The main body text colour for Sensei email templates. Default %1$s#505050%2$s.', 'woothemes-sensei'), '<code>', '</code>'), 'type' => 'color', 'default' => '#505050', 'section' => 'email-notification-settings', 'required' => 1); if (WooThemes_Sensei_Utils::sensei_is_woocommerce_present()) { // WooCommerce Settings $fields['woocommerce_enabled'] = array('name' => __('Enable WooCommerce Courses', 'woothemes-sensei'), 'description' => __('Use WooCommerce to sell Courses by linking a Product to a Course.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => true, 'section' => 'woocommerce-settings'); $fields['course_archive_free_enable'] = array('name' => __('Free Courses Panel', 'woothemes-sensei'), 'description' => __('Output the Free Courses Panel on the Course Archive Page.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => true, 'section' => 'woocommerce-settings'); $fields['course_archive_paid_enable'] = array('name' => __('Paid Courses Panel', 'woothemes-sensei'), 'description' => __('Output the Paid Courses Panel on the Course Archive Page.', 'woothemes-sensei'), 'type' => 'checkbox', 'default' => true, 'section' => 'woocommerce-settings'); } // End If Statement if ('en_US' !== get_locale()) { $fields['install_language_pack'] = array('name' => __('Install Language Pack', 'woothemes-sensei'), 'description' => __('Use this action to install or re-install translation for your language if available.', 'woothemes-sensei'), 'type' => 'button', 'section' => 'language-settings', 'target' => Sensei_Language_Pack_Manager::get_install_uri(), 'label' => __('Install', 'woothemes-sensei')); } $this->fields = apply_filters('sensei_settings_fields', $fields); }
/** * Display output to the admin view * * This view is shown when grading a quiz for a single user in admin under grading * * @since 1.3.0 * @return html */ public function display() { // Get data for the user //echo do_shortcode("[i4w_get_contactId]"); //die(); $questions = $this->build_data_array(); global $woothemes_sensei; $count = 0; $graded_count = 0; $user_quiz_grade_total = 0; $quiz_grade_total = 0; $quiz_grade = 0; $lesson_id = $this->lesson_id; $user_id = $this->user_id; ?> <form name="<?php esc_attr_e('quiz_' . $this->quiz_id); ?> " action="" method="post"> <?php wp_nonce_field('sensei_manual_grading', '_wp_sensei_manual_grading_nonce'); ?> <input type="hidden" name="sensei_manual_grade" value="<?php esc_attr_e($this->quiz_id); ?> " /> <input type="hidden" name="sensei_grade_next_learner" value="<?php esc_attr_e($this->user_id); ?> " /> <div class="total_grade_display"> <span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?> </span> <span class="total_grade_total"><?php echo $user_quiz_grade_total; ?> </span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?> </span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?> </span>%) </div> <div class="buttons"> <input type="submit" value="<?php esc_attr_e(__('Save', 'woothemes-sensei')); ?> " class="grade-button button-primary" title="Saves grades as currently marked on this page" /> <input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?> " class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> <input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?> " class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> </div> <div class="clear"></div><br/><?php $lesson_status_id = WooThemes_Sensei_Utils::sensei_get_activity_value(array('post_id' => $this->lesson_id, 'user_id' => $this->user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID')); $user_quiz_grade = get_comment_meta($lesson_status_id, 'grade', true); $correct_answers = 0; foreach ($questions as $question) { $question_id = $question->ID; ++$count; $type = false; $type_name = ''; $type = Sensei()->question->get_question_type($question_id); $question_answer_notes = $woothemes_sensei->quiz->get_user_question_feedback($lesson_id, $question_id, $user_id); $question_grade_total = get_post_meta($question_id, '_question_grade', true); if (!$question_grade_total || 0 == intval($question_grade_total)) { $question_grade_total = 1; } $quiz_grade_total += $question_grade_total; $right_answer = get_post_meta($question_id, '_question_right_answer', true); $user_answer_content = $woothemes_sensei->quiz->get_user_question_answer($lesson_id, $question_id, $user_id); $type_name = __('Multiple Choice', 'woothemes-sensei'); $grade_type = 'manual-grade'; switch ($type) { case 'boolean': $type_name = __('True/False', 'woothemes-sensei'); $right_answer = ucfirst($right_answer); $user_answer_content = ucfirst($user_answer_content); $grade_type = 'auto-grade'; break; case 'multiple-choice': $type_name = __('Multiple Choice', 'woothemes-sensei'); $grade_type = 'auto-grade'; break; case 'gap-fill': $type_name = __('Gap Fill', 'woothemes-sensei'); $right_answer_array = explode('||', $right_answer); if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } if (!$user_answer_content) { $user_answer_content = '______'; } $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; $user_answer_content = $gapfill_pre . ' <span class="highlight">' . $user_answer_content . '</span> ' . $gapfill_post; $grade_type = 'auto-grade'; break; case 'multi-line': $type_name = __('Multi Line', 'woothemes-sensei'); $grade_type = 'manual-grade'; break; case 'single-line': $type_name = __('Single Line', 'woothemes-sensei'); $grade_type = 'manual-grade'; break; case 'file-upload': $type_name = __('File Upload', 'woothemes-sensei'); $grade_type = 'manual-grade'; // Get uploaded file if ($user_answer_content) { $attachment_id = $user_answer_content; $answer_media_url = $answer_media_filename = ''; if (0 < intval($attachment_id)) { $answer_media_url = wp_get_attachment_url($attachment_id); $answer_media_filename = basename($answer_media_url); if ($answer_media_url && $answer_media_filename) { $user_answer_content = sprintf(__('Submitted file: %1$s', 'woothemes-sensei'), '<a href="' . esc_url($answer_media_url) . '" target="_blank">' . esc_html($answer_media_filename) . '</a>'); } } } else { $user_answer_content = ''; } break; default: // Nothing break; } $user_answer_content = (array) $user_answer_content; $right_answer = (array) $right_answer; $question_title = sprintf(__('Question %d: ', 'woothemes-sensei'), $count) . $type_name; $graded_class = ''; $user_question_grade = $woothemes_sensei->quiz->get_user_question_grade($lesson_id, $question_id, $user_id); $graded_class = 'ungraded'; if (intval($user_question_grade) > 0) { $graded_class = 'user_right'; ++$correct_answers; $user_quiz_grade_total += $user_question_grade; ++$graded_count; } else { if (!is_string($user_question_grade) && intval($user_question_grade) == 0) { $graded_class = 'user_wrong'; ++$graded_count; } $user_question_grade = 0; } ?> <div class="postbox question_box <?php esc_attr_e($type); ?> <?php esc_attr_e($grade_type); ?> <?php esc_attr_e($graded_class); ?> " id="<?php esc_attr_e('question_' . $question_id . '_box'); ?> "> <div class="handlediv" title="Click to toggle"><br></div> <h3 class="hndle"><span><?php echo $question_title; ?> </span></h3> <div class="inside"> <div class="sensei-grading-actions"> <div class="actions"> <input type="hidden" class="question_id" value="<?php esc_attr_e($question_id); ?> " /> <input type="hidden" class="question_total_grade" name="question_total_grade" value="<?php echo $question_grade_total; ?> " /> <span class="grading-mark icon_right"><input type="radio" class="<?php esc_attr_e('question_' . $question_id . '_right_option'); ?> " name="<?php esc_attr_e('question_' . $question_id); ?> " value="right" <?php checked($graded_class, 'user_right', true); ?> /></span> <span class="grading-mark icon_wrong"><input type="radio" class="<?php esc_attr_e('question_' . $question_id . '_wrong_option'); ?> " name="<?php esc_attr_e('question_' . $question_id); ?> " value="wrong" <?php checked($graded_class, 'user_wrong', true); ?> /></span> <input type="number" class="question-grade" name="<?php esc_attr_e('question_' . $question_id . '_grade'); ?> " id="<?php esc_attr_e('question_' . $question_id . '_grade'); ?> " value="<?php esc_attr_e($user_question_grade); ?> " min="0" max="<?php esc_attr_e($question_grade_total); ?> " /> <span class="question-grade-total"><?php echo $question_grade_total; ?> </span> </div> </div> <div class="sensei-grading-answer"> <h4><?php echo apply_filters('sensei_question_title', $question->post_title); ?> </h4> <?php echo apply_filters('the_content', $question->post_content); ?> <p class="user-answer"><?php foreach ($user_answer_content as $_user_answer) { if ('multi-line' == Sensei()->question->get_question_type($question->ID)) { $_user_answer = htmlspecialchars_decode(nl2br(esc_html($_user_answer))); } echo apply_filters('sensei_answer_text', $_user_answer) . "<br>"; } ?> </p> <div class="right-answer"> <h5><?php _e('Correct answer', 'woothemes-sensei'); ?> </h5> <span class="correct-answer"><?php foreach ($right_answer as $_right_answer) { echo apply_filters('sensei_answer_text', $_right_answer) . "<br>"; } ?> </span> </div> <div class="answer-notes"> <h5><?php _e('Grading Notes', 'woothemes-sensei'); ?> </h5> <textarea class="correct-answer" name="questions_feedback[<?php esc_attr_e($question_id); ?> ]" placeholder="<?php _e('Add notes here...', 'woothemes-sensei'); ?> "><?php echo $question_answer_notes; ?> </textarea> </div> </div> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <div> <?php //floyd code to get the note history $historynotes = get_user_meta($_GET['user'], '_grading_notes_history', true); $historyanswers = get_user_meta($_GET['user'], '_grading_answer_history', true); //echo "<pre>"; //echo $question_id." ".$lesson_id; //print_r($historyanswers); //echo "</pre>"; if (is_array($historynotes)) { //print_r($historynotes[$question_id]); if (array_key_exists($question_id, $historynotes) || isset($historynotes[$question_id])) { echo "<table class='table striped'>"; echo "<tr><th colspan='3'>Question History</th></tr>"; echo "<tr>"; echo "<th>DATE</th>"; echo "<th>Answer</th>"; echo "<th>Notes</th>"; echo "</tr>"; foreach ($historynotes[$question_id] as $dateTime => $noteentry) { echo "<tr>"; echo "<td>" . $dateTime . "</td>"; echo "<td>" . $historyanswers[$question_id][$dateTime] . "</td>"; echo "<td>" . $noteentry . "</td>"; echo "</tr>"; } echo "</table>"; } } ?> </div> </div> </div><?php } $quiz_grade = intval($user_quiz_grade); $all_graded = 'no'; if (intval($count) == intval($graded_count)) { $all_graded = 'yes'; } ?> <input type="hidden" name="total_grade" id="total_grade" value="<?php esc_attr_e($user_quiz_grade_total); ?> " /> <input type="hidden" name="total_questions" id="total_questions" value="<?php esc_attr_e($count); ?> " /> <input type="hidden" name="quiz_grade_total" id="quiz_grade_total" value="<?php esc_attr_e($quiz_grade_total); ?> " /> <input type="hidden" name="total_graded_questions" id="total_graded_questions" value="<?php esc_attr_e($graded_count); ?> " /> <input type="hidden" name="all_questions_graded" id="all_questions_graded" value="<?php esc_attr_e($all_graded); ?> " /> <div class="total_grade_display"> <span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?> </span> <span class="total_grade_total"><?php echo $user_quiz_grade_total; ?> </span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?> </span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?> </span>%) </div> <div class="buttons"> <input type="submit" value="<?php esc_attr_e('Save'); ?> " class="grade-button button-primary" title="Saves grades as currently marked on this page" /> <input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?> " class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> <input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?> " class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> </div> <div class="clear"></div> <script type="text/javascript"> jQuery( window ).load( function() { // Calculate total grade on page load to make sure everything is set up correctly jQuery.fn.autoGrade(); }); </script> </form><?php }
/** * Runs when an order is cancelled. * @since 1.2.0 * @access public * @param integer $order_id order ID * @return void */ public function sensei_woocommerce_cancel_order($order_id) { // Get order object $order = new WC_Order($order_id); // Run through each product ordered if (0 < sizeof($order->get_items())) { // Get order user $user_id = $order->__get('user_id'); foreach ($order->get_items() as $item) { $product_type = ''; if (isset($item['variation_id']) && 0 < $item['variation_id']) { $item_id = $item['variation_id']; $product_type = 'variation'; } else { $item_id = $item['product_id']; } // End If Statement $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type); // Get courses that use the WC product $courses = array(); $courses = $this->post_types->course->get_product_courses($item_id); // Loop and update those courses foreach ($courses as $course_item) { // Check and Remove course from courses user meta $dataset_changes = WooThemes_Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id); } // End For Loop } // End For Loop } // End If Statement }
/** * Return array of course statuses * @since 1.7.0 * @return array statuses */ private function get_course_statuses($args) { $activity_args = array('post_id' => $this->course_id, 'type' => 'sensei_course_status', 'number' => $args['number'], 'offset' => $args['offset'], 'orderby' => $args['orderby'], 'order' => $args['order'], 'status' => 'any'); // Searching users on statuses requires sub-selecting the statuses by user_ids if ($this->search) { $user_args = array('search' => '*' . $this->search . '*', 'fields' => 'ID'); // Filter for extending $user_args = apply_filters('sensei_analysis_course_search_users', $user_args); if (!empty($user_args)) { $learners_search = new WP_User_Query($user_args); // Store for reuse on counts $activity_args['user_id'] = (array) $learners_search->get_results(); } } // End If Statement $activity_args = apply_filters('sensei_analysis_course_filter_statuses', $activity_args); // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice $this->total_items = WooThemes_Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? if ($this->total_items < $activity_args['offset']) { $new_paged = floor($total_statuses / $activity_args['number']); $activity_args['offset'] = $new_paged * $activity_args['number']; } $statuses = WooThemes_Sensei_Utils::sensei_check_for_activity($activity_args, true); // Need to always return an array, even with only 1 item if (!is_array($statuses)) { $statuses = array($statuses); } return $statuses; }
function sensei_has_user_completed_lesson($post_id = 0, $user_id = 0) { _deprecated_function(__FUNCTION__, '1.7', "WooThemes_Sensei_Utils::user_completed_lesson()"); return WooThemes_Sensei_Utils::user_completed_lesson($post_id, $user_id); }
/** * post_type_custom_column_content function. * * @access public * @since 1.0.0 * @return void */ public function post_type_custom_column_content($column_name, $post_ID) { $user_id = get_post_meta($post_ID, $key = 'learner_id', true); $course_id = get_post_meta($post_ID, $key = 'course_id', true); $user = get_userdata($user_id); $course = get_post($course_id); $course_end_date = WooThemes_Sensei_Utils::sensei_get_activity_value(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_date')); $certificate_hash = esc_html(substr(md5($course_id . $user_id), -8)); switch ($column_name) { case "learner": echo '<a href="' . add_query_arg(array('page' => 'sensei_analysis', 'user' => intval($user_id), 'course_id' => intval($course_id)), admin_url('edit.php?post_type=lesson')) . '">' . $user->user_login . '</a>'; break; case "course": echo '<a href="' . add_query_arg(array('page' => 'sensei_analysis', 'course_id' => intval($course_id)), admin_url('edit.php?post_type=lesson')) . '">' . $course->post_title . '</a>'; break; case "date_completed": echo $course_end_date; break; case "actions": echo '<a href="' . add_query_arg(array('certificate' => '1', 'hash' => $certificate_hash), site_url()) . '" target="_blank">' . __('View Certificate', 'sensei-certificates') . '</a>'; break; } // End Switch Statement }
/** * Add the admin all lessons screen edit options. * * The fields in this function work for both quick and bulk edit. The ID attributes is used * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then * name attribute is will be used by the quick edit and submitted via standard POST. This * will use this classes save_post_meta function to save the new field data. * * @hooked quick_edit_custom_box * @hooked bulk_edit_custom_box * * @since 1.8.0 * * @param string $column_name * @param string $post_type * @return void */ public function all_lessons_edit_fields($column_name, $post_type) { // only show these options ont he lesson post type edit screen if ('lesson' != $post_type || 'lesson-course' != $column_name) { return; } ?> <fieldset class="sensei-edit-field-set inline-edit-lesson"> <div class="sensei-inline-edit-col column-<?php echo $column_name; ?> "> <?php echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>'; // create a nonce field to be used as a security measure when saving the data wp_nonce_field('bulk-edit-lessons', '_edit_lessons_nonce'); wp_nonce_field('sensei-save-post-meta', 'woo_' . $this->token . '_nonce'); // unchanged option - we need this in because // the default option in bulk edit should not be empty. If it is // the user will erase data they didn't want to touch. $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --'; // //course selection // $courses = WooThemes_Sensei_Course::get_all_courses(); $course_options = array(); if (count($courses) > 0) { foreach ($courses as $course) { $course_options[$course->ID] = get_the_title($course->ID); } } //pre-append the no change option $course_options['-1'] = $no_change_text; $course_attributes = array('name' => 'lesson_course', 'id' => 'sensei-edit-lesson-course', 'class' => ' '); $course_field = WooThemes_Sensei_Utils::generate_drop_down('-1', $course_options, $course_attributes); echo $this->generate_all_lessons_edit_field(__('Lesson Course', 'woothemes-sensei'), $course_field); // // lesson complexity selection // $lesson_complexities = $this->lesson_complexities(); //pre-append the no change option $lesson_complexities['-1'] = $no_change_text; $complexity_dropdown_attributes = array('name' => 'lesson_complexity', 'id' => 'sensei-edit-lesson-complexity', 'class' => ' '); $complexity_filed = WooThemes_Sensei_Utils::generate_drop_down('-1', $lesson_complexities, $complexity_dropdown_attributes); echo $this->generate_all_lessons_edit_field(__('Lesson Complexity', 'woothemes-sensei'), $complexity_filed); ?> <h4><?php _e('Quiz Settings', 'woothemes-sensei'); ?> </h4> <?php // // Lesson require pass to complete // $pass_required_options = array('-1' => $no_change_text, '0' => __('No', 'woothemes'), '1' => __('Yes', 'woothemes')); $pass_required_select_attributes = array('name' => 'pass_required', 'id' => 'sensei-edit-lesson-pass-required', 'class' => ' '); $require_pass_field = WooThemes_Sensei_Utils::generate_drop_down('-1', $pass_required_options, $pass_required_select_attributes, false); echo $this->generate_all_lessons_edit_field(__('Pass required', 'woothemes-sensei'), $require_pass_field); // // Quiz pass percentage // $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />'; echo $this->generate_all_lessons_edit_field(__('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field); // // Enable quiz reset button // $quiz_reset_select__options = array('-1' => $no_change_text, '0' => __('No', 'woothemes'), '1' => __('Yes', 'woothemes')); $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset'; $quiz_reset_select_attributes = array('name' => 'enable_quiz_reset', 'id' => $quiz_reset_name_id, 'class' => ' '); $quiz_reset_field = WooThemes_Sensei_Utils::generate_drop_down('-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false); echo $this->generate_all_lessons_edit_field(__('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field); ?> </div> </fieldset> <?php }
/** * Sets up the object course query * that will be used int he render method. * * @since 1.9.0 */ protected function setup_course_query() { $status_query = array('user_id' => get_current_user_id(), 'type' => 'sensei_course_status'); $course_statuses = WooThemes_Sensei_Utils::sensei_check_for_activity($status_query, true); // User may only be on 1 Course if (!is_array($course_statuses)) { $course_statuses = array($course_statuses); } $completed_ids = $active_ids = array(); foreach ($course_statuses as $course_status) { if (WooThemes_Sensei_Utils::user_completed_course($course_status, get_current_user_id())) { $completed_ids[] = $course_status->comment_post_ID; } else { $active_ids[] = $course_status->comment_post_ID; } } if ('completed' == $this->status) { $included_courses = $completed_ids; } elseif ('active' == $this->status) { $included_courses = $active_ids; } else { $included_courses = array_merge($active_ids, $completed_ids); } // course query parameters $query_args = array('post_type' => 'course', 'post_status' => 'publish', 'orderby' => $this->orderby, 'order' => $this->order, 'posts_per_page' => $this->number, 'post__in' => $included_courses); $this->query = new WP_Query($query_args); }
/** * Display the single course modules content * * @since 1.8.0 * @return void */ public function course_module_content() { global $post; $course_id = $post->ID; $modules = $this->get_course_modules($course_id); // Display each module foreach ($modules as $module) { echo '<article class="post module">'; // module title link $module_url = esc_url(add_query_arg('course_id', $course_id, get_term_link($module, $this->taxonomy))); echo '<header><h2><a href="' . esc_url($module_url) . '">' . $module->name . '</a></h2></header>'; echo '<section class="entry">'; $module_progress = false; if (is_user_logged_in()) { global $current_user; wp_get_current_user(); $module_progress = $this->get_user_module_progress($module->term_id, $course_id, $current_user->ID); } if ($module_progress && $module_progress > 0) { $status = __('Completed', 'woothemes-sensei'); $class = 'completed'; if ($module_progress < 100) { $status = __('In progress', 'woothemes-sensei'); $class = 'in-progress'; } echo '<p class="status module-status ' . esc_attr($class) . '">' . $status . '</p>'; } if ('' != $module->description) { echo '<p class="module-description">' . $module->description . '</p>'; } $lessons = $this->get_lessons($course_id, $module->term_id); if (count($lessons) > 0) { $lessons_list = ''; foreach ($lessons as $lesson) { $status = ''; $lesson_completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson->ID, get_current_user_id()); $title = esc_attr(get_the_title(intval($lesson->ID))); if ($lesson_completed) { $status = 'completed'; } $lessons_list .= '<li class="' . $status . '"><a href="' . esc_url(get_permalink(intval($lesson->ID))) . '" title="' . esc_attr(get_the_title(intval($lesson->ID))) . '">' . apply_filters('sensei_module_lesson_list_title', $title, $lesson->ID) . '</a></li>'; // Build array of displayed lesson for exclusion later $displayed_lessons[] = $lesson->ID; } ?> <section class="module-lessons"> <header> <h3><?php _e('Lessons', 'woothemes-sensei'); ?> </h3> </header> <ul> <?php echo $lessons_list; ?> </ul> </section> <?php } //end count lessons ?> </section> </article> <?php } // end each module }
/** * Grade quiz automatically * * This function grades each question automatically if there all questions are auto gradable. If not * the quiz will not be auto gradable. * * @since 1.7.4 * * @param integer $quiz_id ID of quiz * @param array $submitted questions id ans answers { * @type int $question_id * @type mixed $answer * } * @param integer $total_questions Total questions in quiz (not used) * @param string $quiz_grade_type Optional defaults to auto * * @return int $quiz_grade total sum of all question grades */ public static function grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { if (!(intval($quiz_id) > 0) || !$submitted || $quiz_grade_type != 'auto') { return false; // exit early } global $woothemes_sensei; $user_id = get_current_user_id(); $lesson_id = $woothemes_sensei->quiz->get_lesson_id($quiz_id); $quiz_autogradable = true; /** * Filter the types of question types that can be automatically graded. * * This filter fires inside the auto grade quiz function and provides you with the default list. * * @param array { * 'multiple-choice', * 'boolean', * 'gap-fill'. * } */ $autogradable_question_types = apply_filters('sensei_autogradable_question_types', array('multiple-choice', 'boolean', 'gap-fill')); $grade_total = 0; $all_question_grades = array(); foreach ($submitted as $question_id => $answer) { // check if the question is autogradable, either by type, or because the grade is 0 $question_type = $woothemes_sensei->question->get_question_type($question_id); $achievable_grade = $woothemes_sensei->question->get_question_grade($question_id); // Question has a zero grade, so skip grading if (0 == $achievable_grade) { $all_question_grades[$question_id] = $achievable_grade; } elseif (in_array($question_type, $autogradable_question_types)) { // Get user question grade $question_grade = WooThemes_Sensei_Utils::sensei_grade_question_auto($question_id, $question_type, $answer, $user_id); $all_question_grades[$question_id] = $question_grade; $grade_total += $question_grade; } else { // There is a question that cannot be autograded $quiz_autogradable = false; } // end if in_array( $question_type... } // end for each question // Only if the whole quiz was autogradable do we set a grade if ($quiz_autogradable) { $quiz_total = WooThemes_Sensei_Utils::sensei_get_quiz_total($quiz_id); // Check for zero total from grades if (0 < $quiz_total) { $grade = abs(round(doubleval($grade_total) * 100 / $quiz_total, 2)); } else { $grade = 0; } WooThemes_Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id, $quiz_grade_type); } else { $grade = new WP_Error('autograde', __('This quiz is not able to be automatically graded.', 'woothemes-sensei')); } // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default // when doing manual grading. $woothemes_sensei->quiz->set_user_grades($all_question_grades, $lesson_id, $user_id); return $grade; }
// Check if the user is taking the course $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course($post->ID, $current_user->ID); // Content Access Permissions $access_permission = false; if (isset($woothemes_sensei->settings->settings['access_permission']) && !$woothemes_sensei->settings->settings['access_permission'] || sensei_all_access()) { $access_permission = true; } // End If Statement ?> <?php /** * woocommerce_before_single_product hook * * @hooked woocommerce_show_messages - 10 */ if (WooThemes_Sensei_Utils::sensei_is_woocommerce_activated()) { do_action('woocommerce_before_single_product'); } // End If Statement ?> <article <?php post_class(array('course', 'post')); ?> > <?php do_action('sensei_course_image', $post->ID); do_action('sensei_course_single_title'); /** * @hooked Sensei()->course->the_progress_statement - 15