function init_gradable_modules_passed($student_id = 0) { foreach ($this->units as $unit) { $unit->gradable_passed = array(); foreach ($unit->gradable_module_ids as $key => $mod_id) { $module = $unit->modules[$mod_id]; $module = new $module->module_type($module->ID); $class_name = Unit_Module::get_module_type($module->ID); $response = call_user_func($class_name . '::get_response', $student_id, $unit->modules[$mod_id]->ID); $minimum_grade = get_post_meta($unit->modules[$mod_id]->ID, 'minimum_grade_required', true); $grade = false; $success = false; if (!empty($response)) { $grade = Unit_Module::get_response_grade($response->ID); $success = $grade['grade'] >= $minimum_grade ? true : false; if ($success) { do_action('coursepress_set_gradable_question_passed', $this->student_id, $this->id, $unit->ID, $mod_id); } } $unit->gradable_passed[$key] = $success; } } }
</td> </tr> </table> <?php } foreach ($modules as $mod) { if (isset($mod->module_type) && $mod->module_type !== '') { $class_name = $mod->module_type; $class_name = $mod->module_type; if (class_exists($class_name)) { $assessable = get_post_meta($mod->ID, 'gradable_answer', true); 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'; $id = isset($response->ID) ? $response->ID : 0; $grade_data = Unit_Module::get_response_grade($id); ?> <table cellspacing="0" cellpadding="5"> <tr> <td style="border-bottom: 1px solid #cccccc;"> <?php echo $mod->label; ?> </td> <td style="border-bottom: 1px solid #cccccc;"> <?php echo $mod->post_title; ?> </td>
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; }
$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); $visibility_class = count($response) >= 1 ? '' : 'less_visible_row_2'; if (count($response) >= 1) { $grade_data = Unit_Module::get_response_grade($response->ID); } $assessable = get_post_meta($mod->ID, 'gradable_answer', true); if (isset($_GET['ungraded']) && $_GET['ungraded'] == 'yes') { if (count($response) >= 1 && !$grade_data && $assessable == 'yes') { $general_col_visibility = true; } else { $general_col_visibility = false; } } else { $general_col_visibility = true; } ?> <tr id='user-<?php echo $user_object->ID; ?>
public static function refresh_module_completion($unit_id, $module_id, $module_type, $meta) { $unit_object = new Unit($unit_id); $unit = $unit_object->get_unit(); $course_id = $unit->post_parent; $students = Course::get_course_students_ids($course_id); foreach ($students as $idx => $student_id) { // Did the student answer it? $response = call_user_func($module_type . '::get_response', $student_id, $module_id, 'inherit', -1, true); // Yes if (!empty($response)) { if ('yes' == $meta['mandatory_answer']) { self::record_mandatory_answer($student_id, $course_id, $unit_id, $module_id); //cp_write_log( 'Record mandatory answer: Module: ' . $module_id ); } if ('yes' == $meta['gradable_answer']) { foreach ($response as $answer) { $result = Unit_Module::get_response_grade($answer); if (0 < $result['grade']) { self::record_gradable_result($student_id, $course_id, $unit_id, $module_id, $result['grade']); } //cp_write_log( 'Record gradable result: Module: ' . $module_id . ' Result: ' . $result['grade'] ); } } } // End responses } }
public static function front_main($data) { $data->name = __CLASS__; $preview_data = CoursePress::instance()->preview_data; $preview = false; if (isset($preview_data) && !empty($preview_data)) { $response = array(); $all_responses = array(); $preview = true; } else { $response = text_input_module::get_response(get_current_user_id(), $data->ID); $all_responses = text_input_module::get_response(get_current_user_id(), $data->ID, 'private', -1); } $grade = false; if (count($response) == 0) { global $coursepress; if ($coursepress->is_preview(Unit_Module::get_module_unit_id($data->ID))) { $enabled = 'disabled'; } else { $enabled = 'enabled'; } } else { $enabled = 'disabled'; $grade = Unit_Module::get_response_grade($response->ID); } ?> <div id="module-<?php echo $data->ID; ?> " class="<?php echo $data->name; ?> front-single-module<?php echo radio_input_module::FRONT_SAVE == true ? '-save' : ''; ?> "> <?php if ($data->post_title != '' && parent::display_title_on_front($data)) { ?> <h2 class="module_title"><?php echo $data->post_title; ?> </h2> <?php } ?> <?php if ($data->post_content != '') { ?> <div class="module_description"><?php echo apply_filters('element_content_filter', apply_filters('the_content', $data->post_content)); ?> </div> <?php } ?> <ul class='radio_answer_check_li radio_answer_group' <?php echo $data->mandatory_answer == 'yes' ? 'data-mandatory="yes"' : 'data-mandatory="no"'; ?> > <?php $student_answer = -1; if (!empty($data) && !empty($data->checked_answer) && !empty($data->answers)) { if (!empty($response)) { $student_answer = array_search($response->post_content, $data->answers); } $correct_answer = array_search($data->checked_answer, $data->answers); foreach ($data->answers as $key => $answer) { $correct = 'unanswered'; if (-1 != $student_answer && $key == $student_answer && $key == $correct_answer) { // $correct = $answer == $response->post_content ? 'correct' : 'unanswered'; $correct = 'correct'; } else { if (-1 != $student_answer && $key == $student_answer) { $correct = 'incorrect'; } } ?> <li> <div class="<?php echo $correct; ?> "> <input class="radio_answer_check" type="radio" name="<?php echo $data->name . '_front_' . $data->ID; ?> " value='<?php echo esc_attr($answer); ?> ' <?php echo $enabled; ?> <?php echo isset($response->post_content) && trim($response->post_content) == $answer ? 'checked' : ''; ?> /><?php echo $answer; ?> </div> </li> <?php } } ?> </ul> <?php echo parent::grade_status_and_resubmit($data, $grade, $all_responses, $response, false); ?> </div> <?php }
public static function front_main($data) { $data->name = __CLASS__; $preview_data = CoursePress::instance()->preview_data; $preview = false; if (isset($preview_data) && !empty($preview_data)) { $response = array(); $all_responses = array(); $preview = true; } else { $response = file_input_module::get_response(get_current_user_id(), $data->ID); $all_responses = file_input_module::get_response(get_current_user_id(), $data->ID, 'private', -1); } $grade = false; if (count($response) == 0) { global $coursepress; if ($coursepress->is_preview(Unit_Module::get_module_unit_id($data->ID))) { $enabled = 'disabled'; } else { $enabled = 'enabled'; } } else { $enabled = 'disabled'; $grade = Unit_Module::get_response_grade($response->ID); } ?> <div id="module-<?php echo $data->ID; ?> " class="<?php echo $data->name; ?> front-single-module<?php echo file_input_module::FRONT_SAVE == true ? '-save' : ''; ?> "> <?php if ($data->post_title != '' && parent::display_title_on_front($data)) { ?> <h2 class="module_title"><?php echo $data->post_title; ?> </h2> <?php } ?> <?php if ($data->post_content != '') { ?> <div class="module_description"><?php echo apply_filters('element_content_filter', apply_filters('the_content', $data->post_content)); ?> </div> <?php } ?> <div class="module_file_input"> <?php if (count($response) == 0) { ?> <input type="file" <?php echo $data->mandatory_answer == 'yes' ? 'data-mandatory="yes"' : 'data-mandatory="no"'; ?> name="<?php echo $data->name . '_front_' . $data->ID; ?> " id="<?php echo $data->name . '_front_' . $data->ID; ?> " <?php echo $enabled; ?> /> <?php } else { _e('File successfully uploaded. ', 'cp'); // printf( '<a target="_blank" href="%s" style="padding-left: 20px">%s</a>', $response->guid, __( 'View/Download File', 'cp' ) ); } ?> </div> <?php parent::grade_status_and_resubmit($data, $grade, $all_responses, $response); ?> </div> <?php /* $unit_module_main = new Unit_Module(); if ( is_object( $response ) && !empty( $response ) ) { $comment = Unit_Module::get_response_comment( $response->ID ); if ( !empty( $comment ) ) { ?> <div class="response_comment_front"><?php echo $comment; ?></div> <?php } } */ ?> <?php }
public static function get_ungraded_response_count($course_id = '') { $counter = 0; if ($course_id == '') { $args = array('post_type' => array('module_response', 'attachment'), 'post_status' => array('publish', 'inherit'), 'posts_per_page' => -1, 'meta_key' => 'course_id', 'meta_value' => $course_id, 'meta_query' => array('relation' => 'AND', array('key' => 'response_grade', 'compare' => 'NOT EXISTS', 'value' => ''))); $ungraded_responses = get_posts($args); //Count only ungraded responses from STUDENTS! foreach ($ungraded_responses as $key => $ungraded_response) { // Only show count for courses an Instructor can actually assess $course_id = get_post_meta($ungraded_response->ID, 'course_id', true); if (!CoursePress_Capabilities::is_course_instructor($course_id)) { continue; } if (get_post_meta($ungraded_response->post_parent, 'gradable_answer', true) != 'yes') { unset($ungraded_responses[$key]); continue; } if (get_user_option('role', $ungraded_response->post_author) !== 'student') { unset($ungraded_responses[$key]); continue; } $module = get_post($ungraded_response->post_parent); if ($module) { $class_name = $module->module_type; $response = call_user_func($class_name . '::get_response', $ungraded_response->post_author, $module->ID); if (count($response) >= 1) { $grade_data = Unit_Module::get_response_grade($response->ID); if ($grade_data) { // If there are more than one response submitted and it is already graded. unset($ungraded_responses[$key]); continue; } } $unit = get_post($module->post_parent); $course_id = $unit->post_parent; // Count only answers from students that are still enrolled in the course. if (!get_user_option('enrolled_course_date_' . $course_id, $ungraded_response->post_author)) { unset($ungraded_responses[$key]); continue; } } $counter += 1; } return $counter; } else { $args = array('post_type' => array('module_response', 'attachment'), 'post_status' => array('publish', 'inherit'), 'posts_per_page' => -1, 'meta_query' => array('relation' => 'AND', array('key' => 'response_grade', 'compare' => 'NOT EXISTS', 'value' => ''), array('key' => 'course_id', 'value' => $course_id))); if (!CoursePress_Capabilities::is_course_instructor($course_id)) { return 0; } $ungraded_responses = get_posts($args); //Count only ungraded responses from STUDENTS! foreach ($ungraded_responses as $key => $ungraded_response) { if (get_post_meta($ungraded_response->post_parent, 'gradable_answer', true) != 'yes') { unset($ungraded_responses[$key]); continue; } if (get_user_option('role', $ungraded_response->post_author) !== 'student') { unset($ungraded_responses[$key]); continue; } $module = get_post($ungraded_response->post_parent); if ($module) { $class_name = $module->module_type; $response = call_user_func($class_name . '::get_response', $ungraded_response->post_author, $module->ID); if (count($response) >= 1) { $grade_data = Unit_Module::get_response_grade($response->ID); if ($grade_data) { // If there are more than one response submitted and it is already graded. unset($ungraded_responses[$key]); continue; } } $unit = get_post($module->post_parent); $course_id = $unit->post_parent; // Count only answers from students that are still enrolled in the course. if (!get_user_option('enrolled_course_date_' . $course_id, $ungraded_response->post_author)) { unset($ungraded_responses[$key]); continue; } } } return count($ungraded_responses); } }
public static function front_main($data) { $data->name = __CLASS__; $preview_data = CoursePress::instance()->preview_data; $preview = false; if (isset($preview_data) && !empty($preview_data)) { $response = array(); $all_responses = array(); $preview = true; } else { $response = text_input_module::get_response(get_current_user_id(), $data->ID); $all_responses = text_input_module::get_response(get_current_user_id(), $data->ID, 'private', -1); } $grade = false; if (count($response) == 0) { global $coursepress; if ($coursepress->is_preview(Unit_Module::get_module_unit_id($data->ID))) { $enabled = 'disabled'; } else { $enabled = 'enabled'; } } else { $enabled = 'disabled'; $grade = Unit_Module::get_response_grade($response->ID); } ?> <?php if (isset($data->checked_length) && $data->checked_length == 'single' || !isset($data->checked_length)) { ?> <div id="module-<?php echo $data->ID; ?> " class="<?php echo $data->name; ?> front-single-module<?php echo text_input_module::FRONT_SAVE == true ? '-save' : ''; ?> "> <?php if ($data->post_title != '' && parent::display_title_on_front($data)) { ?> <h2 class="module_title"><?php echo $data->post_title; ?> </h2> <?php } ?> <?php if ($data->post_content != '') { ?> <div class="module_description"><?php echo apply_filters('element_content_filter', apply_filters('the_content', $data->post_content)); ?> </div> <?php } ?> <?php if (is_object($response) && count($response) >= 1 && trim($response->post_content) !== '') { ?> <div class="front_response_content"> <?php echo $response->post_content; ?> </div> <?php } else { ?> <div class="module_textarea_input"> <input <?php echo $data->mandatory_answer == 'yes' ? 'data-mandatory="yes"' : 'data-mandatory="no"'; ?> type="text" name="<?php echo $data->name . '_front_' . $data->ID; ?> " id="<?php echo $data->name . '_front_' . $data->ID; ?> " placeholder="<?php echo isset($data->placeholder_text) && $data->placeholder_text !== '' ? esc_attr($data->placeholder_text) : ' '; ?> " value="<?php echo is_object($response) && count($response >= 1) ? esc_attr($response->post_content) : ''; ?> " <?php echo $enabled; ?> /> </div> <?php } ?> <?php parent::grade_status_and_resubmit($data, $grade, $all_responses, $response); ?> </div> <?php } else { ?> <div id="module-<?php echo $data->ID; ?> " class="<?php echo $data->name; ?> front-single-module<?php echo text_input_module::FRONT_SAVE == true ? '-save' : ''; ?> "> <?php if ($data->post_title != '' && parent::display_title_on_front($data)) { ?> <h2 class="module_title"><?php echo $data->post_title; ?> </h2> <?php } ?> <?php if ($data->post_content != '') { ?> <div class="module_description"><?php echo apply_filters('element_content_filter', $data->post_content); ?> </div> <?php } ?> <div class="module_textarea_input"> <?php if (count($response) >= 1 && trim($response->post_content) !== '') { ?> <div class="front_response_content"> <?php echo $response->post_content; ?> </div> <?php } else { ?> <textarea <?php echo $data->mandatory_answer == 'yes' ? 'data-mandatory="yes"' : 'data-mandatory="no"'; ?> class="<?php echo $data->name . '_front'; ?> " name="<?php echo $data->name . '_front_' . $data->ID; ?> " id="<?php echo $data->name . '_front_' . $data->ID; ?> " placeholder="<?php echo isset($data->placeholder_text) && esc_attr($data->placeholder_text) !== '' ? $data->placeholder_text : ' '; ?> " <?php echo $enabled; ?> ></textarea> <?php } ?> </div> <?php parent::grade_status_and_resubmit($data, $grade, $all_responses, $response); ?> </div> <?php } }