private static function _total_steps_required($unit_id)
 {
     $criteria = Unit::get_module_completion_data($unit_id);
     if (empty($criteria)) {
         return false;
     }
     $total_answers = count($criteria['mandatory_modules']);
     $total_pages = Unit::get_page_count($unit_id);
     return $total_answers + $total_pages;
 }
 function get_unit_pages($unit)
 {
     $pages_num = 1;
     if (!cp_unit_uses_new_pagination($unit->ID)) {
         // Legacy
         $modules = $unit->modules;
         foreach ($modules as $mod) {
             $class_name = $mod->module_type;
             if ('page_break_module' == $class_name) {
                 $pages_num++;
             }
         }
     } else {
         // New unit builder 1.2.3.5+
         $pages_num = Unit::get_page_count($unit->ID);
     }
     return $pages_num;
 }
Exemplo n.º 3
0
 function update_course_meta_on_unit_creation($post_id, $course_id)
 {
     if (!$course_id) {
         $post = get_post($post_id);
         $course_id = $post->post_parent;
     }
     // Update course structure
     $structure_option = get_post_meta($course_id, 'course_structure_options', true);
     $structure_option = !empty($structure_option) && 'on' == $structure_option ? 'on' : 'off';
     $show_unit_boxes = get_post_meta($course_id, 'show_unit_boxes', true);
     $keys = array_keys($show_unit_boxes);
     // We only want to do this once to prevent accidental override.
     if (!in_array($post_id, $keys)) {
         $show_unit_boxes[$post_id] = $structure_option;
     }
     update_post_meta($course_id, 'show_unit_boxes', $show_unit_boxes);
     $show_page_boxes = get_post_meta($course_id, 'show_page_boxes', true);
     $keys = array_keys($show_page_boxes);
     $page_count = Unit::get_page_count($post_id);
     for ($i = 1; $i <= $page_count; $i++) {
         $key = $post_id . '_' . $i;
         // Avoid accidental overrides.
         if (!in_array($key, $keys)) {
             $show_page_boxes[$key] = $structure_option;
         }
     }
     update_post_meta($course_id, 'show_page_boxes', $show_page_boxes);
 }