Skip to content

Commit

Permalink
Merge pull request #489 from themeum/dev
Browse files Browse the repository at this point in the history
Release v2.2.2
  • Loading branch information
shewa12 authored Jun 22, 2023
2 parents 9a6d96e + 907950f commit 7b3f2bc
Show file tree
Hide file tree
Showing 19 changed files with 24,494 additions and 33,213 deletions.
7 changes: 3 additions & 4 deletions assets/react/admin-dashboard/segments/import-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function tutor_option_history_load(dataset) {
/* import and list dom */

const export_settings_all = () => {
const export_settings = document.querySelector('#export_settings'); //document.querySelector("#export_settings");
const export_settings = document.querySelector('#tutor_export_settings');
if (export_settings) {
export_settings.onclick = (e) => {
var formData = new FormData();
Expand Down Expand Up @@ -152,7 +152,7 @@ const time_now = () => {
};

const reset_default_options = () => {
const reset_options = document.querySelector('#reset_options');
const reset_options = document.querySelector('#tutor_reset_options');
if (reset_options) {
reset_options.onclick = function() {
modalConfirmation(reset_options);
Expand All @@ -178,7 +178,7 @@ const reset_all_settings_xhttp = (modalOpener, modalElement) => {
};

const import_history_data = () => {
const import_options = document.querySelector('#import_options');
const import_options = document.querySelector('#tutor_import_options');
if (import_options) {
import_options.onclick = (e) => {
modalConfirmation(import_options);
Expand Down Expand Up @@ -242,7 +242,6 @@ const export_single_settings = () => {

xhttp.onreadystatechange = function() {
if (xhttp.readyState === 4) {
// let fileName = "tutor_options_" + _tutorobject.tutor_time_now;
let fileName = export_id;
json_download(xhttp.response, fileName);
}
Expand Down
4 changes: 2 additions & 2 deletions classes/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function tutor_place_rating() {

$user_id = get_current_user_id();
$user = get_userdata( $user_id );
$date = date( 'Y-m-d H:i:s', tutor_time() );
$date = date( 'Y-m-d H:i:s', tutor_time() ); //phpcs:ignore

if ( ! tutor_utils()->has_enrolled_content_access( 'course', $course_id ) ) {
wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) );
Expand Down Expand Up @@ -483,7 +483,7 @@ public function process_tutor_login() {
*
* @since 2.1.4
*/
if ( ! wp_verify_nonce( $_POST[ tutor()->nonce ], tutor()->nonce_action ) ) {
if ( ! wp_verify_nonce( $_POST[ tutor()->nonce ], tutor()->nonce_action ) ) { //phpcs:ignore
$validation_error->add( 401, __( 'Nonce verification failed', 'tutor' ) );
\set_transient( self::LOGIN_ERRORS_TRANSIENT_KEY, $validation_error->get_error_messages() );
return;
Expand Down
4 changes: 4 additions & 0 deletions classes/Instructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Instructor {
* Constructor
*
* @since 1.0.0
*
* @param bool $register_hook register hook or not.
*
* @return void
*/
public function __construct( $register_hook = true ) {
Expand Down Expand Up @@ -171,6 +174,7 @@ public function register_instructor() {
if ( $user ) {
wp_set_current_user( $user_id, $user->user_login );
wp_set_auth_cookie( $user_id );
do_action( 'tutor_after_instructor_signup', $user_id );
}
}

Expand Down
2 changes: 1 addition & 1 deletion classes/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public function student_public_profile_title() {
$user = $wpdb->get_row( $wpdb->prepare( "SELECT display_name from {$wpdb->users} WHERE user_login = %s limit 1; ", $user_name ) );

if ( ! empty( $user->display_name ) ) {
return sprintf( "%s's Profile page ", $user->display_name );
return sprintf( "%s's %s", $user->display_name, __( 'Profile Page', 'tutor' ) );
}
}
return '';
Expand Down
28 changes: 19 additions & 9 deletions classes/Tutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,16 @@ final class Tutor {
* @var $course_list
* @since 2.0.0
*/
private $Course_List;
public $course_list;

//phpcs:disable
public $q_and_a_list;
public $q_attempt;
public $rest_api;
public $setup;
public $private_course_access;
public $course_filter;
//phpcs:enable

/**
* Course Embed
Expand Down Expand Up @@ -557,7 +566,7 @@ public function __construct() {
* @return void
*/
public function activated_tutor( $plugin, $network_wide = null ) {
if ( $plugin == tutor()->basename ) {
if ( tutor()->basename === $plugin ) {
if ( ( ! get_option( 'tutor_wizard' ) ) && version_compare( TUTOR_VERSION, '1.5.6', '>' ) ) {
update_option( 'tutor_wizard', 'active' );
wp_safe_redirect( admin_url( 'admin.php?page=tutor-setup' ) );
Expand All @@ -571,20 +580,20 @@ public function activated_tutor( $plugin, $network_wide = null ) {
*
* @since 1.0.0
*
* @param string $className class name to load.
* @param string $class_name class name to load.
*
* @return void
*/
private function loader( $className ) {
if ( ! class_exists( $className ) ) {
$className = preg_replace(
private function loader( $class_name ) {
if ( ! class_exists( $class_name ) ) {
$class_name = preg_replace(
array( '/([a-z])([A-Z])/', '/\\\/' ),
array( '$1$2', DIRECTORY_SEPARATOR ),
$className
$class_name
);

$className = str_replace( 'TUTOR' . DIRECTORY_SEPARATOR, 'classes' . DIRECTORY_SEPARATOR, $className );
$file_name = $this->path . $className . '.php';
$class_name = str_replace( 'TUTOR' . DIRECTORY_SEPARATOR, 'classes' . DIRECTORY_SEPARATOR, $class_name );
$file_name = $this->path . $class_name . '.php';

if ( file_exists( $file_name ) ) {
require_once $file_name;
Expand Down Expand Up @@ -766,6 +775,7 @@ public static function create_database() {
quiz_id bigint(20) DEFAULT NULL,
question_title text,
question_description longtext,
answer_explanation longtext DEFAULT '',
question_type varchar(50) DEFAULT NULL,
question_mark decimal(9,2) DEFAULT NULL,
question_settings longtext,
Expand Down
147 changes: 3 additions & 144 deletions classes/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -4896,39 +4896,6 @@ public function get_question_types( $type = null ) {
return $types;
}

/**
* Get quiz answer options by question ID
*
* @since 1.0.0
*
* @param int $question_id question id.
*
* @return mixed
*/
public function get_quiz_answer_options_by_question( $question_id ) {
global $wpdb;

$answer_options = $wpdb->get_results(
$wpdb->prepare(
"SELECT {$wpdb->comments}.comment_ID,
{$wpdb->comments}.comment_post_ID,
{$wpdb->comments}.comment_content
FROM {$wpdb->comments}
WHERE {$wpdb->comments}.comment_post_ID = %d
AND {$wpdb->comments}.comment_type = %s
ORDER BY {$wpdb->comments}.comment_karma ASC;
",
$question_id,
'quiz_answer_option'
)
);

if ( is_array( $answer_options ) && count( $answer_options ) ) {
return $answer_options;
}
return false;
}

/**
* Get attached quiz.
*
Expand Down Expand Up @@ -5242,45 +5209,6 @@ public function get_all_quiz_attempts_by_user( $user_id = 0 ) {
return false;
}

/**
* Get quiz answers by ids
*
* @since 1.0.0
*
* @param array $ids ids.
*
* @return array|bool|null|object
*/
public function get_quiz_answers_by_ids( $ids ) {
$ids = (array) $ids;

if ( ! count( $ids ) ) {
return false;
}

$in_ids = implode( ',', $ids );

global $wpdb;

$query = $wpdb->get_results(
$wpdb->prepare(
"SELECT comment_ID,
comment_content
FROM {$wpdb->comments}
WHERE comment_type = %s
AND comment_ID IN({$in_ids})
",
'quiz_answer_option'
)
);

if ( is_array( $query ) && count( $query ) ) {
return $query;
}

return false;
}

/**
* Get the users / students / course levels
*
Expand Down Expand Up @@ -5323,7 +5251,7 @@ public function student_register_url() {
$student_register_page = (int) $this->get_option( 'student_register_page' );

if ( $student_register_page ) {
return get_the_permalink( $student_register_page );
return apply_filters( 'tutor_student_register_url', get_the_permalink( $student_register_page ) );
}

return false;
Expand All @@ -5340,7 +5268,7 @@ public function instructor_register_url() {
$instructor_register_page = (int) $this->get_option( 'instructor_register_page' );

if ( $instructor_register_page ) {
return get_the_permalink( $instructor_register_page );
return apply_filters( 'tutor_instructor_register_url', get_the_permalink( $instructor_register_page ) );
}

return false;
Expand All @@ -5358,7 +5286,7 @@ public function instructor_register_url() {
public function tutor_dashboard_url( $sub_url = '' ) {
$page_id = (int) $this->get_option( 'tutor_dashboard_page_id' );
$page_id = apply_filters( 'tutor_dashboard_page_id', $page_id );
return trailingslashit( get_the_permalink( $page_id ) ) . $sub_url;
return apply_filters( 'tutor_dashboard_url', trailingslashit( get_the_permalink( $page_id ) ) . $sub_url );
}

/**
Expand Down Expand Up @@ -7103,55 +7031,6 @@ public function get_gradebooks() {
return $results;
}


/**
* Get Attempt row by grade method settings
*
* @since 1.4.2
*
* @param int $quiz_id quiz id.
* @param int $user_id user id.
*
* @return array|bool|null|object
*/
public function get_quiz_attempt( $quiz_id = 0, $user_id = 0 ) {
global $wpdb;

$quiz_id = $this->get_post_id( $quiz_id );
$user_id = $this->get_user_id( $user_id );

$attempt = false;

$quiz_grade_method = get_tutor_option( 'quiz_grade_method', 'highest_grade' );
$from_string = "FROM {$wpdb->tutor_quiz_attempts} WHERE quiz_id = %d AND user_id = %d AND attempt_status != 'attempt_started' ";

if ( $quiz_grade_method === 'highest_grade' ) {

$attempt = $wpdb->get_row( $wpdb->prepare( "SELECT * {$from_string} ORDER BY earned_marks DESC LIMIT 1; ", $quiz_id, $user_id ) );
} elseif ( $quiz_grade_method === 'average_grade' ) {

$attempt = $wpdb->get_row(
$wpdb->prepare(
"SELECT {$wpdb->tutor_quiz_attempts}.*,
COUNT(attempt_id) AS attempt_count,
AVG(total_marks) AS total_marks,
AVG(earned_marks) AS earned_marks {$from_string}
",
$quiz_id,
$user_id
)
);
} elseif ( $quiz_grade_method === 'first_attempt' ) {

$attempt = $wpdb->get_row( $wpdb->prepare( "SELECT * {$from_string} ORDER BY attempt_id ASC LIMIT 1; ", $quiz_id, $user_id ) );
} elseif ( $quiz_grade_method === 'last_attempt' ) {

$attempt = $wpdb->get_row( $wpdb->prepare( "SELECT * {$from_string} ORDER BY attempt_id DESC LIMIT 1; ", $quiz_id, $user_id ) );
}

return $attempt;
}

/**
* Print Course Status Context
*
Expand Down Expand Up @@ -9489,26 +9368,6 @@ public function get_total_enrolled_course() {
return $wpdb->get_var( $wpdb->prepare( $sql, tutor()->course_post_type ) );
}

/**
* Get total number of quiz
*
* @since 2.0.2
*
* @return int
*/
public function get_total_quiz() {
global $wpdb;

$sql = "SELECT COUNT(DISTINCT quiz.ID)
FROM {$wpdb->posts} quiz
INNER JOIN {$wpdb->posts} topic ON quiz.post_parent=topic.ID
INNER JOIN {$wpdb->posts} course ON topic.post_parent=course.ID
WHERE course.post_type=%s
AND quiz.post_type='tutor_quiz'";

return $wpdb->get_var( $wpdb->prepare( $sql, tutor()->course_post_type ) );
}

/**
* Get total number of question
*
Expand Down
5 changes: 2 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var gulp = require('gulp'),
sass = require('gulp-sass'),
sass = require('gulp-sass')(require('sass')),
sourcemaps = require('gulp-sourcemaps'),
rename = require('gulp-rename'),
prefix = require('gulp-autoprefixer'),
Expand Down Expand Up @@ -79,9 +79,8 @@ for (let task in scss_blueprints) {
.src(blueprint.src)
.pipe(plumber({ errorHandler: onError }))
.pipe(sourcemaps.init({ loadMaps: true, largeFile: true }))
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(sass({ outputStyle: 'compressed', sass: require('sass') }))
.pipe(rename(blueprint.destination))
.pipe(sourcemaps.write('.', { addComment: process.env._GULP_ENV != 'build' }))
.pipe(gulp.dest(blueprint.dest_path || 'assets/css'));
});
}
Expand Down
2 changes: 1 addition & 1 deletion includes/tutor-template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ function get_tutor_course_thumbnail_src( $size = 'post-thumbnail', $id = 0 ) {
$src = wp_get_attachment_image_url( $post_thumbnail_id, $size, false );
} else {
$placeholder_url = tutor()->url . 'assets/images/placeholder.svg';
$src = apply_filters( 'tutor_course_thumbnail_placeholder', $post_id, $placeholder_url );
$src = apply_filters( 'tutor_course_thumbnail_placeholder', $placeholder_url, $post_id );
}

return $src;
Expand Down
Loading

0 comments on commit 7b3f2bc

Please sign in to comment.