<label><?php _e('Page Label', 'cp'); ?> <span class="delete_unit_page"> <a class="button button-units button-delete-unit"><i class="fa fa-trash-o"></i> <?php _e('Delete Page', 'cp'); ?> </a> </span> </label> <div class="description"><?php _e('The label will be displayed on the Course Overview and Unit page', 'cp'); ?> </div> <input type="text" value="<?php echo esc_attr($unit->get_unit_page_name($i)); ?> " name="page_title[page_<?php echo $i; ?> ]" id="page_title_<?php echo $i; ?> " class="page_title" /> <label class="show_page_title"> <input type="checkbox" name="show_page_title[]" value="yes" <?php echo isset($show_title[$i - 1]) && $show_title[$i - 1] == 'yes' ? 'checked' : !isset($show_title[$i - 1]) ? 'checked' : ''; ?> /> <input type="hidden" name="show_page_title_field[]" value="<?php echo isset($show_title[$i - 1]) && $show_title[$i - 1] == 'yes' || !isset($show_title[$i - 1]) ? 'yes' : 'no';
if ($unit_pages == 0) { ?> <li> <label><?php _e('There are currently no pages to display', 'cp'); ?> </label> </li> <?php } else { ?> <li class="course_structure_page_li"> <?php for ($i = 1; $i <= $unit_pages; $i++) { $pages_num = 1; $page_title = $unit_class->get_unit_page_name($i); ?> <label for="page_<?php echo $unit->ID . '_' . $i; ?> "> <div class="tree-page-left"> <?php echo isset($page_title) && $page_title !== '' ? $page_title : __('Untitled Page', 'cp'); ?> </div> <div class="tree-page-right"> <input type='checkbox' class="module_show" id='show-<?php echo $unit->ID . '_' . $i; ?>
function course_unit_details($atts) { global $post_id, $wp, $coursepress; extract(shortcode_atts(apply_filters('shortcode_atts_course_unit_details', array('unit_id' => 0, 'field' => 'post_title', 'format' => 'true', 'additional' => '2', 'style' => 'flat', 'class' => 'course-name-content', 'tooltip_alt' => __('Percent of the unit completion', 'cp'), 'knob_fg_color' => '#24bde6', 'knob_bg_color' => '#e0e6eb', 'knob_data_thickness' => '.35', 'knob_data_width' => '70', 'knob_data_height' => '70', 'unit_title' => '', 'unit_page_title_tag' => 'h3', 'unit_page_title_tag_class' => '', 'last_visited' => 'false', 'parent_course_preceding_content' => __('Course: ', 'cp'), 'student_id' => get_current_user_ID(), 'decimal_places' => '0')), $atts)); $unit_id = (int) $unit_id; $field = sanitize_html_class($field); $format = sanitize_text_field($format); $format = 'true' == $format ? true : false; $additional = sanitize_text_field($additional); $style = sanitize_html_class($style); $tooltip_alt = sanitize_text_field($tooltip_alt); $knob_fg_color = sanitize_text_field($knob_fg_color); $knob_bg_color = sanitize_text_field($knob_bg_color); $knob_data_thickness = sanitize_text_field($knob_data_thickness); $knob_data_width = (int) $knob_data_width; $knob_data_height = (int) $knob_data_height; $unit_title = sanitize_text_field($unit_title); $unit_page_title_tag = sanitize_html_class($unit_page_title_tag); $unit_page_title_tag_class = sanitize_html_class($unit_page_title_tag_class); $parent_course_preceding_content = sanitize_text_field($parent_course_preceding_content); $student_id = (int) $student_id; $last_visited = sanitize_text_field($last_visited); $last_visited = 'true' == $last_visited ? true : false; $class = sanitize_html_class($class); $decimal_places = sanitize_text_field($decimal_places); if ($unit_id == 0) { $unit_id = get_the_ID(); } $unit = new Unit($unit_id); if (!isset($unit->details)) { $unit->details = new stdClass(); } $student = new Student(get_current_user_id()); $class = sanitize_html_class($class); if ($field == 'is_unit_available') { $unit->details->{$field} = Unit::is_unit_available($unit_id); } if ($field == 'unit_page_title') { $paged = isset($wp->query_vars['paged']) ? absint($wp->query_vars['paged']) : 1; $page_name = $unit->get_unit_page_name($paged); if ($unit_title !== '') { $page_title_prepend = $unit_title . ': '; } else { $page_title_prepend = ''; } $show_title_array = get_post_meta($unit_id, 'show_page_title', true); $show_title = false; if (isset($show_title_array[$paged - 1]) && 'yes' == $show_title_array[$paged - 1]) { $show_title = true; } if (!empty($page_name) && $show_title) { $unit->details->{$field} = '<' . $unit_page_title_tag . '' . ($unit_page_title_tag_class !== '' ? ' class="' . $unit_page_title_tag_class . '"' : '') . '>' . $page_title_prepend . $unit->get_unit_page_name($paged) . '</' . $unit_page_title_tag . '>'; } else { $unit->details->{$field} = ''; } } if ($field == 'parent_course') { $course = new Course($unit->course_id); $unit->details->{$field} = $parent_course_preceding_content . '<a href="' . $course->get_permalink() . '" class="' . $class . '">' . $course->details->post_title . '</a>'; } /* ------------ */ $front_save_count = 0; $modules = Unit_Module::get_modules($unit_id); $mandatory_answers = 0; $mandatory = 'no'; foreach ($modules as $mod) { $mandatory = get_post_meta($mod->ID, 'mandatory_answer', true); if ($mandatory == 'yes') { $mandatory_answers++; } $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { $front_save_count++; } } } $input_modules_count = $front_save_count; /* ------------ */ //$input_modules_count = do_shortcode( '[course_unit_details field="input_modules_count" unit_id="' . $unit_id . '"]' ); $responses_count = 0; $modules = Unit_Module::get_modules($unit_id); foreach ($modules as $module) { if (Unit_Module::did_student_respond($module->ID, $student_id)) { $responses_count++; } } $student_modules_responses_count = $responses_count; //$student_modules_responses_count = do_shortcode( '[course_unit_details field="student_module_responses" unit_id="' . $unit_id . '"]' ); if ($student_modules_responses_count > 0) { $percent_value = $mandatory_answers > 0 ? round(100 / $mandatory_answers * $student_modules_responses_count, 0) : 0; $percent_value = $percent_value > 100 ? 100 : $percent_value; //in case that student gave answers on all mandatory plus optional questions } else { $percent_value = 0; } if ($input_modules_count == 0) { $grade = 0; $front_save_count = 0; $assessable_answers = 0; $responses = 0; $graded = 0; //$input_modules_count = do_shortcode( '[course_unit_details field="input_modules_count" unit_id="' . get_the_ID() . '"]' ); $modules = Unit_Module::get_modules($unit_id); if ($input_modules_count > 0) { foreach ($modules as $mod) { $class_name = $mod->module_type; $assessable = get_post_meta($mod->ID, 'gradable_answer', true); if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { if ($assessable == 'yes') { $assessable_answers++; } $front_save_count++; $response = call_user_func($class_name . '::get_response', $student_id, $mod->ID); if (isset($response->ID)) { $grade_data = Unit_Module::get_response_grade($response->ID); $grade = $grade + $grade_data['grade']; if (get_post_meta($response->ID, 'response_grade')) { $graded++; } $responses++; } } else { //read only module } } } $percent_value = $format == true ? ($responses == $graded && $responses == $front_save_count ? '<span class="grade-active">' : '<span class="grade-inactive">') . ($grade > 0 ? round($grade / $assessable_answers, 0) : 0) . '</span>' : ($grade > 0 ? round($grade / $assessable_answers, 0) : 0); } else { $student = new Student($student_id); if ($student->is_unit_visited($unit_id, $student_id)) { $grade = 100; $percent_value = $format == true ? '<span class="grade-active">' . $grade . '</span>' : $grade; } else { $grade = 0; $percent_value = $format == true ? '<span class="grade-inactive">' . $grade . '</span>' : $grade; } } //$percent_value = do_shortcode( '[course_unit_details field="student_unit_grade" unit_id="' . get_the_ID() . '"]' ); } //redirect to the parent course page if not enrolled if (!current_user_can('manage_options')) { if (!$coursepress->check_access($unit->course_id, $unit_id)) { // if( defined('DOING_AJAX') && DOING_AJAX ) { cp_write_log('doing ajax'); } //ob_start(); wp_redirect(get_permalink($unit->course_id)); exit; } } if ($field == 'percent') { // $completion = new Course_Completion( $unit->course_id ); // $completion->init_student_status(); // $percent_value = $completion->unit_progress( $unit_id ); $percent_value = number_format_i18n(Student_Completion::calculate_unit_completion($student_id, $unit->course_id, $unit_id), $decimal_places); $assessable_input_modules_count = do_shortcode('[course_unit_details field="assessable_input_modules_count"]'); if ($style == 'flat') { $unit->details->{$field} = '<span class="percentage">' . ($format == true ? $percent_value . '%' : $percent_value) . '</span>'; } elseif ($style == 'none') { $unit->details->{$field} = $percent_value; } else { $unit->details->{$field} = '<a class="tooltip" alt="' . $tooltip_alt . '"><input class="knob" data-fgColor="' . $knob_fg_color . '" data-bgColor="' . $knob_bg_color . '" data-thickness="' . $knob_data_thickness . '" data-width="' . $knob_data_width . '" data-height="' . $knob_data_height . '" data-readOnly=true value="' . $percent_value . '"></a>'; } } if ($field == 'permalink') { if ($last_visited) { $last_visited_page = cp_get_last_visited_unit_page($unit_id); $unit->details->{$field} = Unit::get_permalink($unit_id, $unit->course_id) . 'page/' . trailingslashit($last_visited_page); } else { $unit->details->{$field} = Unit::get_permalink($unit_id, $unit->course_id); } } if ($field == 'input_modules_count') { $front_save_count = 0; $modules = Unit_Module::get_modules($unit_id); foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { $front_save_count++; } } } $unit->details->{$field} = $front_save_count; } if ($field == 'mandatory_input_modules_count') { $front_save_count = 0; $mandatory_answers = 0; $modules = Unit_Module::get_modules($unit_id); foreach ($modules as $mod) { $mandatory_answer = get_post_meta($mod->ID, 'mandatory_answer', true); $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { if ($mandatory_answer == 'yes') { $mandatory_answers++; } //$front_save_count++; } } } $unit->details->{$field} = $mandatory_answers; } if ($field == 'assessable_input_modules_count') { $front_save_count = 0; $assessable_answers = 0; $modules = Unit_Module::get_modules($unit_id); foreach ($modules as $mod) { $assessable = get_post_meta($mod->ID, 'gradable_answer', true); $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { if ($assessable == 'yes') { $assessable_answers++; } //$front_save_count++; } } } if (isset($unit->details->{$field})) { $unit->details->{$field} = $assessable_answers; } } if ($field == 'student_module_responses') { $responses_count = 0; $mandatory_answers = 0; $modules = Unit_Module::get_modules($unit_id); foreach ($modules as $module) { $mandatory = get_post_meta($module->ID, 'mandatory_answer', true); if ($mandatory == 'yes') { $mandatory_answers++; } if (Unit_Module::did_student_respond($module->ID, $student_id)) { $responses_count++; } } if ($additional == 'mandatory') { if ($responses_count > $mandatory_answers) { $unit->details->{$field} = $mandatory_answers; } else { $unit->details->{$field} = $responses_count; } //so we won't have 7 of 6 mandatory answered but mandatory number as a max number } else { $unit->details->{$field} = $responses_count; } } if ($field == 'student_unit_grade') { $grade = 0; $front_save_count = 0; $responses = 0; $graded = 0; $input_modules_count = do_shortcode('[course_unit_details field="input_modules_count" unit_id="' . get_the_ID() . '"]'); $modules = Unit_Module::get_modules($unit_id); $mandatory_answers = 0; $assessable_answers = 0; if ($input_modules_count > 0) { foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { $front_save_count++; $response = call_user_func($class_name . '::get_response', $student_id, $mod->ID); $assessable = get_post_meta($mod->ID, 'gradable_answer', true); $mandatory = get_post_meta($mod->ID, 'mandatory_answer', true); if ($assessable == 'yes') { $assessable_answers++; } if (isset($response->ID)) { if ($assessable == 'yes') { $grade_data = Unit_Module::get_response_grade($response->ID); $grade = $grade + $grade_data['grade']; if (get_post_meta($response->ID, 'response_grade')) { $graded++; } $responses++; } } } else { //read only module } } } $unit->details->{$field} = $format == true ? ($responses == $graded && $responses == $front_save_count ? '<span class="grade-active">' : '<span class="grade-inactive">') . ($grade > 0 ? round($grade / $assessable_answers, 0) : 0) . '%</span>' : ($grade > 0 ? round($grade / $assessable_answers, 0) : 0); } else { $student = new Student($student_id); if ($student->is_unit_visited($unit_id, $student_id)) { $grade = 100; $unit->details->{$field} = $format == true ? '<span class="grade-active">' . $grade . '%</span>' : $grade; } else { $grade = 0; $unit->details->{$field} = $format == true ? '<span class="grade-inactive">' . $grade . '%</span>' : $grade; } } } if ($field == 'student_unit_modules_graded') { $grade = 0; $front_save_count = 0; $responses = 0; $graded = 0; $modules = Unit_Module::get_modules($unit_id); foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { $front_save_count++; $response = call_user_func($class_name . '::get_response', $student_id, $mod->ID); if (isset($response->ID)) { $grade_data = Unit_Module::get_response_grade($response->ID); $grade = $grade + $grade_data['grade']; if (get_post_meta($response->ID, 'response_grade')) { $graded++; } $responses++; } } else { //read only module } } } $unit->details->{$field} = $graded; } if (isset($unit->details->{$field})) { return $unit->details->{$field}; } }
/** * Renders the course structure. * * Used in shortcodes on the front end to render the course hierarchy. * * @param string $try_title * @param bool $show_try * @param bool $hide_title * @param bool $echo */ function course_structure_front($try_title = '', $show_try = true, $hide_title = false, $echo = true) { $show_unit = $this->details->show_unit_boxes; $preview_unit = $this->details->preview_unit_boxes; $show_page = $this->details->show_page_boxes; $preview_page = $this->details->preview_page_boxes; $units = $this->get_units(); $content = ''; if (!$echo) { ob_start(); } echo $hide_title ? '' : '<label>' . $this->details->post_title . '</label>'; ?> <ul class="tree"> <li> <ul> <?php foreach ($units as $unit) { $unit_class = new Unit($unit->ID); $unit_pages = $unit_class->get_number_of_unit_pages(); // $modules = Unit_Module::get_modules( $unit->ID ); if (isset($show_unit[$unit->ID]) && $show_unit[$unit->ID] == 'on' && $unit->post_status == 'publish') { ?> <li> <label for="unit_<?php echo $unit->ID; ?> " class="course_structure_unit_label"> <div class="tree-unit-left"><?php echo $unit->post_title; ?> </div> <div class="tree-unit-right"> <?php if ($this->details->course_structure_time_display == 'on') { ?> <span><?php echo $unit_class->get_unit_time_estimation($unit->ID); ?> </span> <?php } ?> <?php if (isset($preview_unit[$unit->ID]) && $preview_unit[$unit->ID] == 'on') { ?> <a href="<?php echo Unit::get_permalink($unit->ID); ?> ?try" class="preview_option"><?php if ($try_title == '') { _e('Try Now', 'cp'); } else { echo $try_title; } ?> </a> <?php } ?> </div> </label> <ul> <?php for ($i = 1; $i <= $unit_pages; $i++) { if (isset($show_page[$unit->ID . '_' . $i]) && $show_page[$unit->ID . '_' . $i] == 'on') { ?> <li class="course_structure_page_li"> <?php $pages_num = 1; $page_title = $unit_class->get_unit_page_name($i); ?> <label for="page_<?php echo $unit->ID . '_' . $i; ?> "> <div class="tree-page-left"> <?php echo isset($page_title) && $page_title !== '' ? $page_title : __('Untitled Page', 'cp'); ?> </div> <div class="tree-page-right"> <?php if ($this->details->course_structure_time_display == 'on') { ?> <span><?php echo $unit_class->get_unit_page_time_estimation($unit->ID, $i); ?> </span> <?php } ?> <?php if (isset($preview_page[$unit->ID . '_' . $i]) && $preview_page[$unit->ID . '_' . $i] == 'on') { ?> <a href="<?php echo Unit::get_permalink($unit->ID); ?> page/<?php echo $i; ?> ?try" class="preview_option"><?php if ($try_title == '') { _e('Try Now', 'cp'); } else { echo $try_title; } ?> </a> <?php } ?> </div> </label> <?php ?> </li> <?php } } //page visible ?> </ul> </li> <?php } //unit visible if (!$echo) { trim(ob_get_clean()); } } ?> </ul> <?php }