function module_status($atts) { ob_start(); extract(shortcode_atts(array('course_id' => in_the_loop() ? get_the_ID() : '', 'unit_id' => false, 'message' => __('%d of %d mandatory elements completed.', 'cp'), 'format' => 'true'), $atts, 'module_status')); $message = sanitize_text_field($message); $format = sanitize_text_field($format); $format = 'true' == $format ? true : false; if ($course_id) { $course_id = (int) $course_id; } $unit_id = (int) $unit_id; if (empty($unit_id)) { return ''; } $criteria = Unit::get_module_completion_data($unit_id); $unit_status = Unit::get_unit_availability_status($unit_id); $unit_available = Unit::is_unit_available($unit_id, $unit_status); $input_modules_count = count($criteria['all_input_ids']); $assessable_input_modules_count = count($criteria['gradable_modules']); $mandatory_input_elements = count($criteria['mandatory_modules']); $mandatory_responses = Student_Completion::get_mandatory_steps_completed(get_current_user_id(), $course_id, $unit_id); // $all_responses = do_shortcode( '[course_unit_details field="student_module_responses"]' ); // $is_unit_available = do_shortcode( '[course_unit_details field="is_unit_available"]' ); // $input_modules_count = do_shortcode( '[course_unit_details field="input_modules_count"]' ); // $assessable_input_modules_count = do_shortcode( '[course_unit_details field="assessable_input_modules_count"]' ); // $mandatory_input_elements = do_shortcode( '[course_unit_details field="mandatory_input_modules_count"]' ); // $mandatory_responses = do_shortcode( '[course_unit_details field="student_module_responses" additional="mandatory"]' ); // $all_responses = do_shortcode( '[course_unit_details field="student_module_responses"]' ); $unit = new Unit($unit_id); $unit->status = $unit_status; if ($input_modules_count > 0) { ?> <span class="unit-archive-single-module-status"><?php if ($unit_available) { if ($mandatory_input_elements > 0) { echo sprintf($message, $mandatory_responses, $mandatory_input_elements); } } else { if (isset($unit->status) && $unit->status['mandatory_required']['enabled'] && !$unit->status['mandatory_required']['result'] && !$unit->status['completion_required']['enabled']) { esc_html_e('All mandatory answers are required in previous unit.', 'cp'); } elseif (isset($unit->status) && $unit->status['completion_required']['enabled'] && !$unit->status['completion_required']['result']) { esc_html_e('Previous unit must be completed successfully.', 'cp'); } if (isset($unit->status) && !$unit->status['date_restriction']['result']) { echo __('Available', 'cp') . ' ' . date_i18n(get_option('date_format'), strtotime(do_shortcode('[course_unit_details field="unit_availability"]'))); } } ?> </span> <?php } else { ?> <span class="unit-archive-single-module-status"><?php if ($unit_available) { // _e('Read-only','cp'); } else { if (isset($unit->status) && $unit->status['mandatory_required']['enabled'] && !$unit->status['mandatory_required']['result'] && !$unit->status['completion_required']['enabled']) { esc_html_e('All mandatory answers are required in previous unit.', 'cp'); } elseif (isset($unit->status) && $unit->status['completion_required']['enabled'] && !$unit->status['completion_required']['result']) { esc_html_e('Previous unit must be completed successfully.', 'cp'); } if (isset($unit->status) && !empty($unit->status) && !$unit->status['date_restriction']['result']) { echo __('Available', 'cp') . ' ' . date_i18n(get_option('date_format'), strtotime(do_shortcode('[course_unit_details field="unit_availability"]'))); } } ?> </span> <?php } $content = ob_get_clean(); return $content; }
<div class="clearfix"></div> <ul class="units-archive-list"> <?php if (have_posts()) { ?> <?php $args = array('order' => 'ASC', 'post_type' => 'unit', 'post_status' => current_user_can('manage_options') ? 'any' : 'publish', 'meta_key' => 'unit_order', 'orderby' => 'meta_value_num', 'posts_per_page' => '-1', 'meta_query' => array('relation' => 'AND', array('key' => 'course_id', 'value' => $course_id))); $posts = query_posts($args); while (have_posts()) { the_post(); $additional_class = ''; $additional_li_class = ''; $unit_id = get_the_ID(); $is_unit_available = Unit::is_unit_available($unit_id); if (!$is_unit_available) { $additional_class = 'locked-unit'; $additional_li_class = 'li-locked-unit'; } $unit_progress = do_shortcode('[course_unit_percent course_id="' . $course_id . '" unit_id="' . $unit_id . '" format="true" style="extended"]'); ?> <li class="<?php echo $additional_li_class; ?> "> <div class='<?php echo $additional_class; ?> '></div> <div class="unit-archive-single">
<?php if (have_posts()) { ?> <?php while (have_posts()) { the_post(); $draft = get_post_status() !== 'publish'; $show_draft = $draft && cp_can_see_unit_draft(); if ($draft && !$show_draft) { continue; } $additional_class = ''; $additional_li_class = ''; $unit_id = get_the_ID(); $additional_content = ''; if (!Unit::is_unit_available($unit_id)) { $additional_class = 'locked-unit'; $additional_li_class = 'li-locked-unit'; $additional_content = '<div class="' . esc_attr($additional_class) . '"></div>'; } $unit_progress = do_shortcode('[course_unit_percent course_id="' . $course_id . '" unit_id="' . $unit_id . '" format="true" style="flat"]'); ?> <li class="<?php echo esc_attr($additional_li_class); ?> "> <?php echo $additional_content; ?> <?php echo do_shortcode('[course_unit_title link="yes" last_page="no"]');
function action_parse_request(&$wp) { global $wp_query; do_action('coursepress_pre_parse_action'); /* Show instructor invite pages */ $pg = $this->instructor_invite_confirmation(); /* Show Units archive template */ if (array_key_exists('course_category', $wp->query_vars)) { $category_template_file = locate_template(array('archive-course-' . $wp->query_vars['course_category'] . '.php')); if ($category_template_file != '') { do_shortcode('[courses_loop]'); require_once $category_template_file; exit; } else { $theme_file = locate_template(array('archive-course.php')); if ($theme_file != '') { do_shortcode('[courses_loop]'); require_once $theme_file; exit; } else { $theme_file = locate_template(array('archive.php')); if ($theme_file != '') { do_shortcode('[courses_loop]'); require_once $theme_file; exit; } } } } /* Show Discussion single template */ if (array_key_exists('discussion_name', $wp->query_vars)) { $this->remove_pre_next_post(); $vars['discussion_name'] = $wp->query_vars['discussion_name']; $vars['course_id'] = Course::get_course_id_by_name($wp->query_vars['coursename']); } /* Add New Discussion template */ if (array_key_exists('discussion_archive', $wp->query_vars) || array_key_exists('discussion_name', $wp->query_vars) && $wp->query_vars['discussion_name'] == $this->get_discussion_slug_new()) { $this->remove_pre_next_post(); $vars['course_id'] = Course::get_course_id_by_name($wp->query_vars['coursename']); if (array_key_exists('discussion_name', $wp->query_vars) && $wp->query_vars['discussion_name'] == $this->get_discussion_slug_new()) { $this->units_archive_subpage = 'discussions'; $theme_file = locate_template(array('page-add-new-discussion.php')); if ($theme_file != '') { require_once $theme_file; exit; } else { $args = array('slug' => $wp->request, 'title' => __('Add New Discussion', 'cp'), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/page-add-new-discussion.php', $vars), 'type' => 'discussion', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } } else { /* Archive Discussion template */ $this->units_archive_subpage = 'discussions'; $theme_file = locate_template(array('archive-discussions.php')); if ($theme_file != '') { //do_shortcode( '[course_notifications_loop]' ); require_once $theme_file; exit; } else { $course_id = do_shortcode('[get_parent_course_id]'); // DISCUSSIONS $args = array('slug' => $wp->request, 'title' => get_the_title($course_id), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/course-discussion-archive.php', $vars), 'type' => 'discussions', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); do_shortcode('[course_discussion_loop]'); } } } /* Show Instructor single template only if the user is an instructor of at least 1 course */ if (array_key_exists('instructor_username', $wp->query_vars)) { //&& 0 < Instructor::get_courses_number( cp_get_userdatabynicename( $wp->query_vars[ 'instructor_username' ] )->ID ) $this->remove_pre_next_post(); $vars = array(); $vars['instructor_username'] = $wp->query_vars['instructor_username']; $user = wp_cache_get($wp->query_vars['instructor_username'], 'cp_instructor_hash'); if (false === $user) { if (get_option('show_instructor_username', 1) == 1) { $username = str_replace('%20', ' ', $wp->query_vars['instructor_username']); //support for usernames with spaces $user = Instructor::instructor_by_login($username); } else { $user = Instructor::instructor_by_hash($wp->query_vars['instructor_username']); wp_cache_set($wp->query_vars['instructor_username'], $user, 'cp_instructor_hash'); } } $vars['user'] = $user; $theme_file = locate_template(array('single-instructor.php')); // $course_count = Instructor::get_courses_number( $vars['user']->ID ); // if ( $course_count <= 1 ) { // exit; // } if ($theme_file != '') { require_once $theme_file; exit; } else { $args = array('slug' => $wp->request, 'title' => __($vars['user']->display_name, 'cp'), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/instructor-single.php', $vars), 'type' => 'virtual_page'); $pg = new CoursePress_Virtual_Page($args); } $user_id = get_current_user_id(); $this->set_latest_activity($user_id); } $url = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); $inbox_page = false; $new_message_page = false; $sent_messages_page = false; if (preg_match('/' . $this->get_inbox_slug() . '/', $url)) { $inbox_page = true; } if (preg_match('/' . $this->get_new_message_slug() . '/', $url)) { $new_message_page = true; } if (preg_match('/' . $this->get_sent_messages_slug() . '/', $url)) { $sent_messages_page = true; } if ($inbox_page) { $this->inbox_subpage = 'inbox'; $theme_file = locate_template(array('page-inbox.php')); if ($theme_file != '') { require_once $theme_file; exit; } else { $args = array('slug' => $wp->request, 'title' => __('Inbox', 'cp'), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/page-inbox.php', array(), true), 'type' => 'page', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } } if ($sent_messages_page) { $this->inbox_subpage = 'sent_messages'; $theme_file = locate_template(array('page-sent-messages.php')); if ($theme_file != '') { //do_shortcode( '[course_units_loop]' ); require_once $theme_file; exit; } else { $args = array('slug' => $wp->request, 'title' => __('Sent Message', 'cp'), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/page-sent-messages.php', array(), true), 'type' => 'page', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } } if ($new_message_page) { $this->inbox_subpage = 'new_message'; $theme_file = locate_template(array('page-new-message.php')); if ($theme_file != '') { //do_shortcode( '[course_units_loop]' ); require_once $theme_file; exit; } else { $args = array('slug' => $wp->request, 'title' => __('New Message', 'cp'), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/page-new-message.php', array(), true), 'type' => 'page', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } } /* Show Units archive template */ if (array_key_exists('coursename', $wp->query_vars) && !array_key_exists('unitname', $wp->query_vars)) { $this->remove_pre_next_post(); $units_archive_page = false; $units_archive_grades_page = false; $notifications_archive_page = false; $units_workbook_page = false; $url = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); if (preg_match('/' . $this->get_units_slug() . '/', $url)) { $units_archive_page = true; } if (preg_match('/' . $this->get_grades_slug() . '/', $url)) { $units_archive_grades_page = true; } if (preg_match('/' . $this->get_workbook_slug() . '/', $url)) { $units_workbook_page = true; } if (preg_match('/' . $this->get_notifications_slug() . '/', $url)) { $notifications_archive_page = true; } $vars = array(); $vars['course_id'] = Course::get_course_id_by_name($wp->query_vars['coursename']); if ($notifications_archive_page) { $this->units_archive_subpage = 'notifications'; $theme_file = locate_template(array('archive-notifications.php')); if ($theme_file != '') { do_shortcode('[course_notifications_loop]'); require_once $theme_file; exit; } else { $course_id = do_shortcode('[get_parent_course_id]'); // NOTIFICATIONS $args = array('slug' => $wp->request, 'title' => get_the_title($course_id), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/course-notifications-archive.php', $vars), 'type' => 'notifications', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); do_shortcode('[course_notifications_loop]'); } } if ($units_archive_page) { $this->units_archive_subpage = 'units'; $theme_file = locate_template(array('archive-unit.php')); if ($theme_file != '') { do_shortcode('[course_units_loop]'); require_once $theme_file; exit; } else { $course_id = do_shortcode('[get_parent_course_id]'); // COURSE UNITS $args = array('slug' => $wp->request, 'title' => get_the_title($course_id), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/course-units-archive.php', $vars), 'type' => 'unit', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); do_shortcode('[course_units_loop]'); } $user_id = get_current_user_id(); $this->set_latest_activity($user_id); $this->upgrade_user_meta($user_id, $course_id); } if ($units_archive_grades_page) { $this->units_archive_subpage = 'grades'; $theme_file = locate_template(array('archive-unit-grades.php')); if ($theme_file != '') { do_shortcode('[course_units_loop]'); require_once $theme_file; exit; } else { $course_id = do_shortcode('[get_parent_course_id]'); // COURSE GRADES $args = array('slug' => $wp->request, 'title' => get_the_title($course_id), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/course-units-archive-grades.php', $vars), 'type' => 'unit', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); do_shortcode('[course_units_loop]'); } $this->set_latest_activity(get_current_user_id()); } if ($units_workbook_page) { $this->units_archive_subpage = 'workbook'; $theme_file = locate_template(array('archive-unit-workbook.php')); if ($theme_file != '') { do_shortcode('[course_units_loop]'); require_once $theme_file; exit; } else { $course_id = do_shortcode('[get_parent_course_id]'); // WORKBOOK do_shortcode('[course_units_loop]'); $args = array('slug' => $wp->request, 'title' => get_the_title($course_id), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/archive-unit-workbook.php', $vars), 'type' => 'unit', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); do_shortcode('[course_units_loop]'); } $this->set_latest_activity(get_current_user_id()); } } /* Show Unit single template */ if (array_key_exists('coursename', $wp->query_vars) && array_key_exists('unitname', $wp->query_vars)) { $this->remove_pre_next_post(); $vars = array(); $unit = new Unit(); $vars['course_id'] = Course::get_course_id_by_name($wp->query_vars['coursename']); $vars['unit_id'] = $unit->get_unit_id_by_name($wp->query_vars['unitname'], $vars['course_id']); //$this->set_course_visited( get_current_user_id(), Course::get_course_id_by_name( $wp->query_vars['coursename'] ) ); $unit = new Unit($vars['unit_id']); $this->set_unit_visited(get_current_user_id(), $vars['unit_id']); $theme_file = locate_template(array('single-unit.php')); $forced_previous_completion_template = locate_template(array('single-previous-unit.php')); if (!Unit::is_unit_available($vars['unit_id']) && (!current_user_can('manage_options') && !CoursePress_Capabilities::can_update_course($vars['course_id']))) { if ($forced_previous_completion_template != '') { do_shortcode('[course_unit_single]'); //required for getting unit results require_once $forced_previous_completion_template; exit; } else { $args = array('slug' => $wp->request, 'title' => $unit->details->post_title, 'content' => __('This Unit is not available at the moment. Please check back later.', 'cp'), 'type' => 'page', 'is_page' => true, 'is_singular' => false, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } } else { if ($theme_file != '') { global $wp; do_shortcode('[course_unit_single unit_id="' . $vars['unit_id'] . '"]'); //required for getting unit results require_once $theme_file; do_action('wp'); //fix for gravity exit; } else { $args = array('slug' => $wp->request, 'title' => isset($unit->details) ? get_the_title($unit->details->post_parent) : '', 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/course-units-single.php', $vars), 'type' => 'unit', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } $this->set_latest_activity(get_current_user_id()); } } }