/** * Echo the number of columns (also number of items per row) on the * the course archive. * * @uses Sensei_Course::get_loop_number_of_columns * @since 1.9.0 */ function sensei_courses_per_row() { echo Sensei_Course::get_loop_number_of_columns(); }
/** * Show the WooCommerce add to cart button for the current course * * The function will only show the button if * 1- the user can buy the course * 2- if they have completed their pre-requisite * 3- if the course has a valid product attached * * @since 1.9.0 * @param int $course_id * @return string $html markup for the button or nothing if user not allowed to buy */ public static function the_add_to_cart_button_html($course_id) { if (!Sensei_Course::is_prerequisite_complete($course_id)) { return ''; } $wc_post_id = self::get_course_product_id($course_id); // Check if customer purchased the product if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id) || empty($wc_post_id)) { return ''; } // based on simple.php in WC templates/single-product/add-to-cart/ // Get the product $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); // do not show the button for invalid products, non purchasable products, out // of stock product or if course is already in cart if (!isset($product) || !is_object($product) || !$product->is_purchasable() || !$product->is_in_stock() || self::is_course_in_cart($wc_post_id)) { return ''; } // // button output: // ?> <form action="<?php echo esc_url($product->add_to_cart_url()); ?> " class="cart" method="post" enctype="multipart/form-data"> <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?> " /> <input type="hidden" name="quantity" value="1" /> <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?> <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?> " /> <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?> <?php foreach ($product->variation_data as $att => $val) { ?> <input type="hidden" name="<?php echo esc_attr($att); ?> " id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?> " value="<?php echo esc_attr($val); ?> " /> <?php } ?> <?php } ?> <?php } ?> <button type="submit" class="single_add_to_cart_button button alt"> <?php echo $product->get_price_html(); ?> - <?php _e('Purchase this Course', 'woothemes-sensei'); ?> </button> </form> <?php }
/** * load_user_courses_content generates HTML for user's active & completed courses * * This function also ouputs the html so no need to echo the content. * * @since 1.4.0 * @param object $user Queried user object * @param boolean $manage Whether the user has permission to manage the courses * @return string HTML displayng course data */ public function load_user_courses_content($user = false) { global $course, $my_courses_page, $my_courses_section; if (!isset(Sensei()->settings->settings['learner_profile_show_courses']) || !Sensei()->settings->settings['learner_profile_show_courses']) { // do not show the content if the settings doesn't allow for it return; } $manage = $user->ID == get_current_user_id() ? true : false; do_action('sensei_before_learner_course_content', $user); // Build Output HTML $complete_html = $active_html = ''; if (is_a($user, 'WP_User')) { $my_courses_page = true; // Allow action to be run before My Courses content has loaded do_action('sensei_before_my_courses', $user->ID); // Logic for Active and Completed Courses $per_page = 20; if (isset(Sensei()->settings->settings['my_course_amount']) && 0 < absint(Sensei()->settings->settings['my_course_amount'])) { $per_page = absint(Sensei()->settings->settings['my_course_amount']); } $course_statuses = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user->ID, 'type' => 'sensei_course_status'), 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 (Sensei_Utils::user_completed_course($course_status, $user->ID)) { $completed_ids[] = $course_status->comment_post_ID; } else { $active_ids[] = $course_status->comment_post_ID; } } $active_count = $completed_count = 0; $active_courses = array(); if (0 < intval(count($active_ids))) { $my_courses_section = 'active'; $active_courses = Sensei()->course->course_query($per_page, 'usercourses', $active_ids); $active_count = count($active_ids); } // End If Statement $completed_courses = array(); if (0 < intval(count($completed_ids))) { $my_courses_section = 'completed'; $completed_courses = Sensei()->course->course_query($per_page, 'usercourses', $completed_ids); $completed_count = count($completed_ids); } // End If Statement foreach ($active_courses as $course_item) { $course_lessons = Sensei()->course->course_lessons($course_item->ID); $lessons_completed = 0; foreach ($course_lessons as $lesson) { if (Sensei_Utils::user_completed_lesson($lesson->ID, $user->ID)) { ++$lessons_completed; } } // Get Course Categories $category_output = get_the_term_list($course_item->ID, 'course-category', '', ', ', ''); $active_html .= '<article class="' . esc_attr(join(' ', get_post_class(array('course', 'post'), $course_item->ID))) . '">'; // Image $active_html .= Sensei()->course->course_image(absint($course_item->ID), '100', '100', true); // Title $active_html .= '<header>'; $active_html .= '<h2><a href="' . esc_url(get_permalink(absint($course_item->ID))) . '" title="' . esc_attr($course_item->post_title) . '">' . esc_html($course_item->post_title) . '</a></h2>'; $active_html .= '</header>'; $active_html .= '<section class="entry">'; $active_html .= '<p class="sensei-course-meta">'; // Author $user_info = get_userdata(absint($course_item->post_author)); if (isset(Sensei()->settings->settings['course_author']) && Sensei()->settings->settings['course_author']) { $active_html .= '<span class="course-author">' . __('by ', 'woothemes-sensei') . '<a href="' . esc_url(get_author_posts_url(absint($course_item->post_author))) . '" title="' . esc_attr($user_info->display_name) . '">' . esc_html($user_info->display_name) . '</a></span>'; } // End If Statement // Lesson count for this author $lesson_count = Sensei()->course->course_lesson_count(absint($course_item->ID)); // Handle Division by Zero if (0 == $lesson_count) { $lesson_count = 1; } // End If Statement $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __('Lessons', 'woothemes-sensei') . '</span>'; // Course Categories if ('' != $category_output) { $active_html .= '<span class="course-category">' . sprintf(__('in %s', 'woothemes-sensei'), $category_output) . '</span>'; } // End If Statement $active_html .= '<span class="course-lesson-progress">' . sprintf(__('%1$d of %2$d lessons completed', 'woothemes-sensei'), $lessons_completed, $lesson_count) . '</span>'; $active_html .= '</p>'; $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; $progress_percentage = abs(round(doubleval($lessons_completed) * 100 / $lesson_count, 0)); $active_html .= $this->get_progress_meter($progress_percentage); $active_html .= '</section>'; if (is_user_logged_in()) { $active_html .= '<section class="entry-actions">'; $active_html .= '<form method="POST" action="' . esc_url(remove_query_arg(array('active_page', 'completed_page'))) . '">'; $active_html .= '<input type="hidden" name="' . esc_attr('woothemes_sensei_complete_course_noonce') . '" id="' . esc_attr('woothemes_sensei_complete_course_noonce') . '" value="' . esc_attr(wp_create_nonce('woothemes_sensei_complete_course_noonce')) . '" />'; $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr(absint($course_item->ID)) . '" />'; if (0 < absint(count($course_lessons)) && Sensei()->settings->settings['course_completion'] == 'complete') { $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' . __('Mark as Complete', 'woothemes-sensei') . '"/> </span>'; } // End If Statement $course_purchased = false; if (Sensei_WC::is_woocommerce_active()) { // Get the product ID $wc_post_id = get_post_meta(absint($course_item->ID), '_course_woocommerce_product', true); if (0 < $wc_post_id) { $course_purchased = Sensei_WC::has_customer_bought_product($user->ID, $wc_post_id); } // End If Statement } // End If Statement if (false == $course_purchased) { $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' . __('Delete Course', 'woothemes-sensei') . '"/></span>'; } // End If Statement $active_html .= '</form>'; $active_html .= '</section>'; } $active_html .= '</article>'; } // Active pagination if ($active_count > $per_page) { $current_page = 1; if (isset($_GET['active_page']) && 0 < intval($_GET['active_page'])) { $current_page = $_GET['active_page']; } $active_html .= '<nav class="pagination woo-pagination">'; $total_pages = ceil($active_count / $per_page); if ($current_page > 1) { $prev_link = add_query_arg('active_page', $current_page - 1); $active_html .= '<a class="prev page-numbers" href="' . esc_url($prev_link) . '">' . __('Previous', 'woothemes-sensei') . '</a> '; } for ($i = 1; $i <= $total_pages; $i++) { $link = add_query_arg('active_page', $i); if ($i == $current_page) { $active_html .= '<span class="page-numbers current">' . $i . '</span> '; } else { $active_html .= '<a class="page-numbers" href="' . esc_url($link) . '">' . $i . '</a> '; } } if ($current_page < $total_pages) { $next_link = add_query_arg('active_page', $current_page + 1); $active_html .= '<a class="next page-numbers" href="' . esc_url($next_link) . '">' . __('Next', 'woothemes-sensei') . '</a> '; } $active_html .= '</nav>'; } foreach ($completed_courses as $course_item) { $course = $course_item; // Get Course Categories $category_output = get_the_term_list($course_item->ID, 'course-category', '', ', ', ''); $complete_html .= '<article class="' . join(' ', get_post_class(array('course', 'post'), $course_item->ID)) . '">'; // Image $complete_html .= Sensei()->course->course_image(absint($course_item->ID), 100, 100, true); // Title $complete_html .= '<header>'; $complete_html .= '<h2><a href="' . esc_url(get_permalink(absint($course_item->ID))) . '" title="' . esc_attr($course_item->post_title) . '">' . esc_html($course_item->post_title) . '</a></h2>'; $complete_html .= '</header>'; $complete_html .= '<section class="entry">'; $complete_html .= '<p class="sensei-course-meta">'; // Author $user_info = get_userdata(absint($course_item->post_author)); if (isset(Sensei()->settings->settings['course_author']) && Sensei()->settings->settings['course_author']) { $complete_html .= '<span class="course-author">' . __('by ', 'woothemes-sensei') . '<a href="' . esc_url(get_author_posts_url(absint($course_item->post_author))) . '" title="' . esc_attr($user_info->display_name) . '">' . esc_html($user_info->display_name) . '</a></span>'; } // End If Statement // Lesson count for this author $complete_html .= '<span class="course-lesson-count">' . Sensei()->course->course_lesson_count(absint($course_item->ID)) . ' ' . __('Lessons', 'woothemes-sensei') . '</span>'; // Course Categories if ('' != $category_output) { $complete_html .= '<span class="course-category">' . sprintf(__('in %s', 'woothemes-sensei'), $category_output) . '</span>'; } // End If Statement $complete_html .= '</p>'; $complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; $complete_html .= $this->get_progress_meter(100); if ($manage) { $has_quizzes = Sensei()->course->course_quizzes($course_item->ID, true); // Output only if there is content to display if (has_filter('sensei_results_links') || $has_quizzes) { $complete_html .= '<p class="sensei-results-links">'; $results_link = ''; if ($has_quizzes) { $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink($course_item->ID) . '">' . __('View results', 'woothemes-sensei') . '</a>'; } /** * Filter documented in Sensei_Course::the_course_action_buttons */ $complete_html .= apply_filters('sensei_results_links', $results_link, $course_item->ID); $complete_html .= '</p>'; } } $complete_html .= '</section>'; $complete_html .= '</article>'; } // Active pagination if ($completed_count > $per_page) { $current_page = 1; if (isset($_GET['completed_page']) && 0 < intval($_GET['completed_page'])) { $current_page = $_GET['completed_page']; } $complete_html .= '<nav class="pagination woo-pagination">'; $total_pages = ceil($completed_count / $per_page); if ($current_page > 1) { $prev_link = add_query_arg('completed_page', $current_page - 1); $complete_html .= '<a class="prev page-numbers" href="' . esc_url($prev_link) . '">' . __('Previous', 'woothemes-sensei') . '</a> '; } for ($i = 1; $i <= $total_pages; $i++) { $link = add_query_arg('completed_page', $i); if ($i == $current_page) { $complete_html .= '<span class="page-numbers current">' . $i . '</span> '; } else { $complete_html .= '<a class="page-numbers" href="' . esc_url($link) . '">' . $i . '</a> '; } } if ($current_page < $total_pages) { $next_link = add_query_arg('completed_page', $current_page + 1); $complete_html .= '<a class="next page-numbers" href="' . esc_url($next_link) . '">' . __('Next', 'woothemes-sensei') . '</a> '; } $complete_html .= '</nav>'; } } // End If Statement if ($manage) { $no_active_message = __('You have no active courses.', 'woothemes-sensei'); $no_complete_message = __('You have not completed any courses yet.', 'woothemes-sensei'); } else { $no_active_message = __('This learner has no active courses.', 'woothemes-sensei'); $no_complete_message = __('This learner has not completed any courses yet.', 'woothemes-sensei'); } ob_start(); ?> <?php do_action('sensei_before_user_courses'); ?> <?php if ($manage && (!isset(Sensei()->settings->settings['messages_disable']) || !Sensei()->settings->settings['messages_disable'])) { ?> <p class="my-messages-link-container"> <a class="my-messages-link" href="<?php echo get_post_type_archive_link('sensei_message'); ?> " title="<?php _e('View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei'); ?> "> <?php _e('My Messages', 'woothemes-sensei'); ?> </a> </p> <?php } ?> <div id="my-courses"> <ul> <li><a href="#active-courses"><?php _e('Active Courses', 'woothemes-sensei'); ?> </a></li> <li><a href="#completed-courses"><?php _e('Completed Courses', 'woothemes-sensei'); ?> </a></li> </ul> <?php do_action('sensei_before_active_user_courses'); ?> <?php $course_page_url = Sensei_Course::get_courses_page_url(); ?> <div id="active-courses"> <?php if ('' != $active_html) { echo $active_html; } else { ?> <div class="sensei-message info"> <?php echo $no_active_message; ?> <a href="<?php echo $course_page_url; ?> "> <?php _e('Start a Course!', 'woothemes-sensei'); ?> </a> </div> <?php } // End If Statement ?> </div> <?php do_action('sensei_after_active_user_courses'); ?> <?php do_action('sensei_before_completed_user_courses'); ?> <div id="completed-courses"> <?php if ('' != $complete_html) { echo $complete_html; } else { ?> <div class="sensei-message info"> <?php echo $no_complete_message; ?> </div> <?php } // End If Statement ?> </div> <?php do_action('sensei_after_completed_user_courses'); ?> </div> <?php do_action('sensei_after_user_courses'); ?> <?php echo ob_get_clean(); do_action('sensei_after_learner_course_content', $user); }
/** * @deprecated since 1.9.0 */ public function sensei_course_meta_video() { _deprecated_function('Sensei_Frontend::sensei_course_meta_video', '1.9.0', 'Sensei_Course::the_course_video()'); Sensei_Course::the_course_video(); }
/** * Output the message that tells the user they have * no active courses. * * @since 1.9.0 */ public function active_no_course_message_output() { ?> <li class="user-active"> <div class="sensei-message info"> <?php _e('You have no active courses.', 'woothemes-sensei'); ?> <a href="<?php esc_attr_e(Sensei_Course::get_courses_page_url()); ?> "> <?php _e('Start a Course!', 'woothemes-sensei'); ?> </a> </div> </li> <?php }