public static function save_response_grade($response_id = '', $response_grade = '', $user_id = false, $course_id = false, $unit_id = false, $module_id = false) { if ((isset($_POST['response_id']) || $response_id !== '') && (isset($_POST['response_grade']) || $response_grade !== '')) { $grade_data = array('grade' => $response_grade !== '' && is_numeric($response_grade) ? $response_grade : $_POST['response_grade'], 'instructor' => get_current_user_ID(), 'time' => current_time('timestamp')); update_post_meta($response_id !== '' && is_numeric($response_id) ? $response_id : $_POST['response_id'], 'response_grade', $grade_data); if (!$user_id) { $user_id = isset($_POST['student_id']) ? (int) $_POST['student_id'] : false; $course_id = isset($_POST['course_id']) ? (int) $_POST['course_id'] : false; $unit_id = isset($_POST['unit_id']) ? (int) $_POST['unit_id'] : false; $module_id = isset($_POST['module_id']) ? (int) $_POST['module_id'] : false; } if (!empty($user_id) && !empty($course_id) && !empty($unit_id) && !empty($module_id)) { $mandatory_answer = get_post_meta($module_id, 'mandatory_answer', true); if (!empty($mandatory_answer) && 'yes' == $mandatory_answer) { Student_Completion::record_mandatory_answer($user_id, $course_id, $unit_id, $module_id); } Student_Completion::record_gradable_result($user_id, $course_id, $unit_id, $module_id, floatval($grade_data['grade'])); } return true; } else { return false; } }