<div class="modules_accordion"> <!--modules will appear here--> <?php $unit_id = $unit_id == 0 ? -1 : $unit_id; if ($unit_pagination) { $modules = Unit_Module::get_modules($unit_id, $i); $pages_num = 1; foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { $module = new $class_name(); $module->admin_main($mod); } } } else { $modules = Unit_Module::get_modules($unit_id, 0); $pages_num = 1; foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { $module = new $class_name(); if ($module->name == 'page_break_module') { $pages_num++; if ($pages_num == $i) { $module->admin_main($mod); } } else { if ($pages_num == $i) { $module->admin_main($mod); } }
echo $user_object->first_name . ' ' . $user_object->last_name; ?> </h2> <?php foreach ($course_units as $course_unit) { ?> <table cellspacing="0" cellpadding="5"> <tr> <td colspan="4" style="background-color:#f5f5f5;"><?php echo $course_unit->post_title; ?> </td> </tr> </table> <?php $modules = Unit_Module::get_modules($course_unit->ID); $input_modules_count = 0; foreach ($modules as $mod) { if (isset($mod->module_type) && $mod->module_type !== '') { $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { $input_modules_count++; } } } } if ($input_modules_count == 0) { ?> <table cellspacing="0" cellpadding="5"> <tr>
" scope="col"><?php echo $col; ?> </th> <?php $n++; } ?> </tr> </thead> <?php foreach ($student_search->get_results() as $user) { $style = isset($style) && 'alternate' == $style ? '' : ' alternate'; $user_object = new Student($user->ID); $modules = Unit_Module::get_modules($current_unit->ID); $input_modules_count = 0; foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { $input_modules_count++; } } } $current_row = 0; foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { $response = call_user_func($class_name . '::get_response', $user_object->ID, $mod->ID);
function get_unit_modules($unit_id) { $modules = Unit_Module::get_modules($unit_id); return $modules; }
function student_workbook_table($args) { ob_start(); extract(shortcode_atts(array('module_column_title' => __('Element', 'cp'), 'title_column_title' => __('Title', 'cp'), 'submission_date_column_title' => __('Submitted', 'cp'), 'response_column_title' => __('Answer', 'cp'), 'grade_column_title' => __('Grade', 'cp'), 'comment_column_title' => __('Comment', 'cp'), 'module_response_description_label' => __('Description', 'cp'), 'comment_label' => __('Comment', 'cp'), 'view_link_label' => __('View', 'cp'), 'view_link_class' => 'assessment-view-response-link button button-units', 'comment_link_class' => 'assessment-view-response-link button button-units', 'pending_grade_label' => __('Pending', 'cp'), 'unit_unread_label' => __('Unit Unread', 'cp'), 'unit_read_label' => __('Unit Read', 'cp'), 'single_correct_label' => __('Correct', 'cp'), 'single_incorrect_label' => __('Incorrect', 'cp'), 'non_assessable_label' => __('**'), 'table_class' => 'widefat shadow-table assessment-archive-table', 'table_labels_th_class' => 'manage-column'), $args)); $module_column_title = sanitize_text_field($module_column_title); $title_column_title = sanitize_text_field($title_column_title); $submission_date_column_title = sanitize_text_field($submission_date_column_title); $response_column_title = sanitize_text_field($response_column_title); $grade_column_title = sanitize_text_field($grade_column_title); $comment_column_title = sanitize_text_field($comment_column_title); $module_response_description_label = sanitize_text_field($module_response_description_label); $comment_label = sanitize_text_field($comment_label); $view_link_label = sanitize_text_field($view_link_label); $view_link_class = sanitize_html_class($view_link_class); $comment_link_class = sanitize_html_class($comment_link_class); $pending_grade_label = sanitize_text_field($pending_grade_label); $unit_unread_label = sanitize_text_field($unit_unread_label); $unit_read_label = sanitize_text_field($unit_read_label); $non_assessable_label = sanitize_text_field($non_assessable_label); $table_class = sanitize_html_class($table_class); $table_labels_th_class = sanitize_html_class($table_labels_th_class); $single_correct_label = sanitize_text_field($single_correct_label); $single_incorrect_label = sanitize_text_field($single_incorrect_label); $columns = array("title" => $title_column_title, "submission_date" => $submission_date_column_title, "response" => $response_column_title, "grade" => $grade_column_title, "comment" => $comment_column_title); $col_sizes = array('45', '15', '10', '13', '5'); ?> <table cellspacing="0" class="<?php echo $table_class; ?> "> <thead> <tr> <?php $n = 0; foreach ($columns as $key => $col) { ?> <th class="<?php echo $table_labels_th_class; ?> column-<?php echo $key; ?> " width="<?php echo $col_sizes[$n] . '%'; ?> " id="<?php echo $key; ?> " scope="col"><?php echo $col; ?> </th> <?php $n++; } ?> </tr> </thead> <?php $user_object = new Student(get_current_user_ID()); $modules = Unit_Module::get_modules(get_the_ID()); $input_modules_count = 0; foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { $input_modules_count++; } } } $current_row = 0; $style = ''; foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { $response = call_user_func($class_name . '::get_response', $user_object->ID, $mod->ID); $visibility_class = count($response) >= 1 ? '' : 'less_visible_row'; if (count($response) >= 1) { $grade_data = Unit_Module::get_response_grade($response->ID); } if (isset($_GET['ungraded']) && $_GET['ungraded'] == 'yes') { if (count($response) >= 1 && !$grade_data) { $general_col_visibility = true; } else { $general_col_visibility = false; } } else { $general_col_visibility = true; } $style = isset($style) && 'alternate' == $style ? '' : ' alternate'; ?> <tr id='user-<?php echo $user_object->ID; ?> ' class="<?php echo $style; echo 'row-' . $current_row; ?> "> <?php if ($general_col_visibility) { ?> <td class="<?php echo $style . ' ' . $visibility_class; ?> "> <?php echo $mod->post_title; ?> </td> <td class="<?php echo $style . ' ' . $visibility_class; ?> "> <?php echo count($response) >= 1 ? date_i18n('M d, Y', strtotime($response->post_date)) : __('Not submitted', 'cp'); ?> </td> <td class="<?php echo $style . ' ' . $visibility_class; ?> "> <?php if (count($response) >= 1) { ?> <div id="response_<?php echo $response->ID; ?> " style="display:none;"> <?php if (isset($mod->post_content) && $mod->post_content !== '') { ?> <div class="module_response_description"> <label><?php echo $module_response_description_label; ?> </label> <?php echo $mod->post_content; ?> </div> <?php } ?> <?php echo call_user_func($class_name . '::get_response_form', get_current_user_ID(), $mod->ID); ?> <?php if (is_object($response) && !empty($response)) { $comment = Unit_Module::get_response_comment($response->ID); if (!empty($comment)) { ?> <label class="comment_label"><?php echo $comment_label; ?> </label> <div class="response_comment_front"><?php echo $comment; ?> </div> <?php } } ?> </div> <a class="<?php echo sanitize_html_class($view_link_class); ?> thickbox" href="#TB_inline?width=500&height=300&inlineId=response_<?php echo $response->ID; ?> "><?php echo sanitize_html_class($view_link_label); ?> </a> <?php } else { echo '-'; } ?> </td> <td class="<?php echo $style . ' ' . $visibility_class; ?> "> <?php if (isset($grade_data)) { $grade = $grade_data['grade']; $instructor_id = $grade_data['instructor']; $instructor_name = get_userdata($instructor_id); $grade_time = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $grade_data['time']); } if (count($response) >= 1) { if (isset($grade_data)) { if (get_post_meta($mod->ID, 'gradable_answer', true) == 'no') { echo $non_assessable_label; } else { if ('radio_input_module' == $class_name) { if (100 == $grade) { echo $single_correct_label; } else { echo $single_incorrect_label; } } else { echo $grade . '%'; } } } else { if (get_post_meta($mod->ID, 'gradable_answer', true) == 'no') { echo $non_assessable_label; } else { echo $pending_grade_label; } } } else { echo '-'; } ?> </td> <td class="<?php echo $style . ' ' . $visibility_class; ?> td-center"> <?php if (!empty($response)) { $comment = Unit_Module::get_response_comment($response->ID); if (!empty($comment)) { ?> <a alt="<?php echo strip_tags($comment); ?> " title="<?php echo strip_tags($comment); ?> " class="<?php echo $comment_link_class; ?> thickbox" href="#TB_inline?width=500&height=300&inlineId=response_<?php echo $response->ID; ?> "><i class="fa fa-comment"></i></a> <?php } } else { echo '<i class="fa fa-comment-o"></i>'; } ?> </td> <?php } //general col visibility ?> </tr> <?php $current_row++; } } } if (!isset($input_modules_count) || isset($input_modules_count) && $input_modules_count == 0) { ?> <tr> <td colspan="7"> <?php $unit_grade = do_shortcode('[course_unit_details field="student_unit_grade" unit_id="' . get_the_ID() . '"]'); _e('0 input elements in the selected unit.', 'cp'); ?> <?php if ($unit_grade == 0) { echo $unit_unread_label; } else { echo $unit_read_label; } ?> </td> </tr> <?php } ?> <?php if (0 < $current_row) { ?> <tfoot><tr><td colspan="6">** <?php _e('Non-assessable elements.', 'cp'); ?> </td></tr></tfoot> <?php } ?> </table> <?php $content = ob_get_clean(); return $content; }
public static function refresh_unit_completion($unit_id) { $modules = Unit_Module::get_modules($unit_id, 0, true); $input_modules = Unit_Module::get_input_module_types(); if (!empty($modules)) { // Traverse modules foreach ($modules as $module_id) { $module_type = Unit_Module::get_module_type($module_id); $module_is_input = in_array($module_type, $input_modules); // Only for input modules if ($module_is_input) { $module_meta = Unit_Module::get_module_meta($module_id); self::refresh_module_completion($unit_id, $module_id, $module_type, $module_meta); } } } }
private static function _create_input_module_meta($unit_id) { $modules = Unit_Module::get_modules($unit_id); foreach ($modules as $mod) { $module_id = $mod->ID; $module_type = get_post_meta($module_id, 'module_type', true); $module_type = !empty($module_type) ? is_array($module_type) ? $module_type[0] : $module_type : false; if ($module_type) { $input_module_types = Unit_Module::get_input_module_types(); if (in_array($module_type, $input_module_types)) { $mandatory_answer = get_post_meta($module_id, 'mandatory_answer', true); $gradable_answer = get_post_meta($module_id, 'gradable_answer', true); $minimum_grade_required = get_post_meta($module_id, 'minimum_grade_required', true); $limit_attempts = get_post_meta($module_id, 'limit_attempts', true); $limit_attempts_value = get_post_meta($module_id, 'limit_attempts_value', true); $module_meta = array('mandatory_answer' => !empty($mandatory_answer) ? is_array($mandatory_answer) ? $mandatory_answer[0] : $mandatory_answer : array(), 'gradable_answer' => !empty($gradable_answer) ? is_array($gradable_answer) ? $gradable_answer[0] : $gradable_answer : array(), 'minimum_grade_required' => !empty($minimum_grade_required) ? is_array($minimum_grade_required) ? $minimum_grade_required[0] : $minimum_grade_required : false, 'limit_attempts' => !empty($limit_attempts) ? is_array($limit_attempts) ? $limit_attempts[0] : $limit_attempts : false, 'limit_attempts_value' => !empty($limit_attempts_value) ? is_array($limit_attempts_value) ? $limit_attempts_value[0] : $limit_attempts_value : false); self::update_input_module_meta($unit_id, $module_id, $module_meta); } } } }
echo $key; ?> " scope="col"><?php echo $col; ?> </th> <?php $n++; } ?> </tr> </thead> <?php $user_object = new Student($_GET['student_id']); $modules = Unit_Module::get_modules($unit->ID); $input_modules_count = 0; foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) { $input_modules_count++; } } } $current_row = 0; $style = ''; foreach ($modules as $mod) { $class_name = $mod->module_type; if (class_exists($class_name)) { if (constant($class_name . '::FRONT_SAVE')) {
function coursepress_unit_pages($unit_id, $unit_pagination = false) { if ($unit_pagination) { $args = array('post_type' => 'module', 'post_status' => 'publish', 'posts_per_page' => 1, 'post_parent' => $unit_id, 'meta_key' => 'module_page', 'orderby' => 'meta_value_num', 'order' => 'DESC'); $modules = get_posts($args); $module_id = isset($modules[0]) ? $modules[0]->ID : 0; if ($module_id > 0) { $pages_num = count(get_post_meta($unit_id, 'page_title', true)); //$pages_num = get_post_meta( $module_id, 'module_page', true ); } else { $pages_num = 1; } } else { $pages_num = 1; $modules = Unit_Module::get_modules($unit_id); foreach ($modules as $mod) { if (Unit_Module::get_module_type($mod->ID) == 'page_break_module') { $pages_num++; } } } return $pages_num; }