Skip to content

Commit

Permalink
Merge pull request #691 from themeum/dev
Browse files Browse the repository at this point in the history
Tutor LMS v2.6.1
  • Loading branch information
shewa12 authored Feb 20, 2024
2 parents 9bc4cb9 + 532b3c4 commit 8f6aa38
Show file tree
Hide file tree
Showing 49 changed files with 2,240 additions and 894 deletions.
Binary file removed assets/images/images-v2/certificate-step-bg.jpg
Binary file not shown.
14 changes: 0 additions & 14 deletions assets/images/images-v2/email-heading.svg

This file was deleted.

Binary file removed assets/images/images-v2/email.png
Binary file not shown.
3 changes: 0 additions & 3 deletions assets/images/images-v2/signature-demo.svg

This file was deleted.

Binary file removed assets/images/instructor-layout/pp-cp.jpg
Binary file not shown.
Binary file removed assets/images/instructor-layout/pp-left-full.jpg
Binary file not shown.
Binary file removed assets/images/instructor-layout/pp-left-middle.jpg
Binary file not shown.
Binary file removed assets/images/instructor-layout/pp-top-full.jpg
Binary file not shown.
Binary file removed assets/images/instructor-layout/pp-top-left.jpg
Binary file not shown.
Binary file removed assets/images/public-profile/no-cp.jpg
Binary file not shown.
Binary file removed assets/images/public-profile/pp-circle.jpg
Binary file not shown.
Binary file removed assets/images/public-profile/pp-rectangle.jpg
Binary file not shown.
Binary file removed assets/images/whats-new.png
Binary file not shown.
10 changes: 6 additions & 4 deletions assets/react/admin-dashboard/quiz-attempts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ document.addEventListener('DOMContentLoaded', async function() {
const response = await post.json();
if (response.success && response.data) {
const navItems = document.querySelectorAll('.tutor-nav-item .tutor-ml-4');
let i = 0;
for (let [key, value] of Object.entries(response.data)) {
navItems[i].innerHTML = `(${value})`;
i++;
if (navItems.length) {
let i = 0;
for (let [key, value] of Object.entries(response.data)) {
navItems[i].innerHTML = `(${value})`;
i++;
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions assets/react/lib/tutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,15 @@ jQuery(document).ready(function($) {
beforeSend: function() {
$that.find('button').attr('disabled', 'disabled').addClass('is-loading');
},
success: function() {
tutor_toast(__('Success', 'tutor'), $that.data('toast_success_message'), 'success');
success: function(response) {
if (response.success) {
tutor_toast(__('Success', 'tutor'), $that.data('toast_success_message'), 'success');
} else {
tutor_toast(__('Error!', 'tutor'), response.data, 'error');
}
},
error: function(response) {
tutor_toast(__('Error!', 'tutor'), response.statusText, 'error');
},
complete: function() {
$that.find('button').removeAttr('disabled').removeClass('is-loading');
Expand Down
4 changes: 4 additions & 0 deletions assets/scss/front/_theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ body {
box-sizing: border-box;
}
}

.media-modal * {
box-sizing: content-box;
}
}

//common and reset css
Expand Down
36 changes: 32 additions & 4 deletions classes/Q_and_A.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ public function __construct() {
add_action( 'wp_ajax_tutor_q_and_a_load_more', __CLASS__ . '::load_more' );
}

/**
* Check user has access to QnA.
*
* @since 2.6.1
*
* @param int $user_id user id.
* @param int $course_id course id.
*
* @return boolean
*/
public static function has_qna_access( $user_id, $course_id ) {
$is_public_course = Course_List::is_public( $course_id );

$has_access = $is_public_course
|| User::is_admin()
|| tutor_utils()->is_instructor_of_this_course( $user_id, $course_id )
|| tutor_utils()->is_enrolled( $course_id );
return $has_access;
}

/**
* Undocumented function
*
Expand All @@ -60,8 +80,17 @@ public function __construct() {
*/
public function tutor_qna_create_update() {
tutor_utils()->checking_nonce();

$user_id = get_current_user_id();
$course_id = Input::post( 'course_id', 0, Input::TYPE_INT );

if ( ! $this->has_qna_access( $user_id, $course_id ) ) {
wp_send_json_error( array( 'message' => tutor_utils()->error_message() ) );
}

global $wpdb;
$qna_text = Input::post( 'answer', '', Input::TYPE_KSES_POST );
$qna_text = Input::post( 'answer', '', tutor()->has_pro ? Input::TYPE_KSES_POST : Input::TYPE_TEXTAREA );

if ( ! $qna_text ) {
// Content validation.
wp_send_json_error( array( 'message' => __( 'Empty Content Not Allowed!', 'tutor' ) ) );
Expand All @@ -73,9 +102,8 @@ public function tutor_qna_create_update() {
$context = Input::post( 'context' );

// Prepare user info.
$user_id = get_current_user_id();
$user = get_userdata( $user_id );
$date = gmdate( 'Y-m-d H:i:s', tutor_time() );
$user = get_userdata( $user_id );
$date = gmdate( 'Y-m-d H:i:s', tutor_time() );

// Insert data prepare.
$data = apply_filters(
Expand Down
79 changes: 56 additions & 23 deletions classes/Quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ public static function quiz_question_layouts() {
*/
public static function quiz_question_orders() {
$orders = array(
'rand' => __( 'Random', 'tutor' ),
'sorting' => __( 'Sorting', 'tutor' ),
'asc' => __( 'Ascending', 'tutor' ),
'desc' => __( 'Descending', 'tutor' ),
);
'rand' => __( 'Random', 'tutor' ),
'sorting' => __( 'Sorting', 'tutor' ),
'asc' => __( 'Ascending', 'tutor' ),
'desc' => __( 'Descending', 'tutor' ),
);

return apply_filters( 'tutor_quiz_layouts', $orders );
}
Expand Down Expand Up @@ -317,16 +317,34 @@ public function start_the_quiz() {
die( 'Please sign in to do this operation' );
}

global $wpdb;

$user_id = get_current_user_id();
$user = get_userdata( $user_id );

$quiz_id = Input::post( 'quiz_id', 0, Input::TYPE_INT );

$quiz = get_post( $quiz_id );
$course = CourseModel::get_course_by_quiz( $quiz_id );
if ( empty( $course->ID ) ) {

self::quiz_attempt( $course->ID, $quiz_id, $user_id );
wp_safe_redirect( get_permalink( $quiz_id ) );
die();
}

/**
* Manage quiz attempt
*
* @since 2.6.1
*
* @param integer $course_id course id.
* @param integer $quiz_id quiz id.
* @param integer $user_id user id.
*
* @return int inserted id|0
*/
public static function quiz_attempt( int $course_id, int $quiz_id, int $user_id, $attempt_status = 'attempt_started' ) {
global $wpdb;

if ( ! $course_id ) {
die( 'There is something went wrong with course, please check if quiz attached with a course' );
}

Expand Down Expand Up @@ -366,24 +384,26 @@ public function start_the_quiz() {
$tutor_quiz_option['time_limit']['time_limit_seconds'] = $time_limit_seconds;

$attempt_data = array(
'course_id' => $course->ID,
'course_id' => $course_id,
'quiz_id' => $quiz_id,
'user_id' => $user_id,
'total_questions' => $max_question_allowed,
'total_answered_questions' => 0,
'attempt_info' => maybe_serialize( $tutor_quiz_option ),
'attempt_status' => 'attempt_started',
'attempt_status' => $attempt_status,
'attempt_ip' => tutor_utils()->get_ip(),
'attempt_started_at' => $date,
);

$wpdb->insert( $wpdb->prefix . 'tutor_quiz_attempts', $attempt_data );
$attempt_id = (int) $wpdb->insert_id;

do_action( 'tutor_quiz/start/after', $quiz_id, $user_id, $attempt_id );

wp_safe_redirect( get_permalink( $quiz_id ) );
die();
if ( $attempt_id ) {
do_action( 'tutor_quiz/start/after', $quiz_id, $user_id, $attempt_id );
return $attempt_id;
} else {
return 0;
}
}

/**
Expand Down Expand Up @@ -442,7 +462,6 @@ public static function tutor_quiz_attemp_submit() {
tutor_utils()->checking_nonce();

// Prepare attempt info.
global $wpdb;
$user_id = get_current_user_id();
$attempt_id = Input::post( 'attempt_id', 0, Input::TYPE_INT );
$attempt = tutor_utils()->get_attempt( $attempt_id );
Expand All @@ -456,17 +475,33 @@ public static function tutor_quiz_attemp_submit() {
if ( ! $attempt || $user_id != $attempt->user_id ) {
die( 'Operation not allowed, attempt not found or permission denied' );
}
self::manage_attempt_answers( $attempt_answers, $attempt, $attempt_id, $course_id, $user_id );
return true;
}

// Before ook.
/**
* Manage attempt answers
*
* Evaluate each attempt answer and update the attempts table & insert in the attempt_answers table.
*
* @since 2.6.1
*
* @param array $attempt_answers attempt answers.
* @param object $attempt single attempt.
* @param int $attempt_id attempt id.
* @param int $course_id course id.
* @param int $user_id user id.
*
* @return void
*/
public static function manage_attempt_answers( $attempt_answers, $attempt, $attempt_id, $course_id, $user_id ) {
global $wpdb;
// Before hook.
do_action( 'tutor_quiz/attempt_analysing/before', $attempt_id );

// Loop through every single attempt answer
// Single quiz can have multiple question. So multiple answer should be saved.
foreach ( $attempt_answers as $attempt_id => $attempt_answer ) {

/**
* Get total marks of all question comes
*/
// Get total marks of all question comes.
$question_ids = tutor_utils()->avalue_dot( 'quiz_question_ids', $attempt_answer );
$question_ids = array_filter(
$question_ids,
Expand Down Expand Up @@ -710,8 +745,6 @@ function ( $ans ) {

// After hook.
do_action( 'tutor_quiz/attempt_ended', $attempt_id, $course_id, $user_id );

return true;
}


Expand Down
2 changes: 1 addition & 1 deletion classes/RestAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function init_routes() {
'methods' => 'GET',
'callback' => array(
$this->announcement_obj,
'course_annoucement',
'course_announcement',
),
'args' => array(
'id' => array(
Expand Down
12 changes: 0 additions & 12 deletions classes/Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function __construct() {
add_shortcode( 'tutor_course', array( $this, 'tutor_course' ) );

add_shortcode( 'tutor_instructor_list', array( $this, 'tutor_instructor_list' ) );
add_action( 'tutor_options_after_instructors', array( $this, 'tutor_instructor_layout' ) );
add_action( 'wp_ajax_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) );
add_action( 'wp_ajax_nopriv_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) );

Expand Down Expand Up @@ -460,15 +459,4 @@ function( $cat ) {
wp_send_json_success( array( 'html' => ob_get_clean() ) );
exit;
}

/**
* Show layout selection dashboard in instructor setting
*
* @since 1.0.0
*
* @return void
*/
public function tutor_instructor_layout() {
tutor_load_template( 'instructor-setting', array( 'templates' => $this->instructor_layout ) );
}
}
2 changes: 1 addition & 1 deletion classes/Tutor_Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public function tutor_setup_attributes() {
),
'enable_q_and_a_on_course' => array(
'type' => 'switch',
'lable' => __( 'Question and Anwser', 'tutor' ),
'lable' => __( 'Question and Answer', 'tutor' ),
'desc' => __( 'Allows a Q&A forum on each course.', 'tutor' ),
),
'courses_col_per_row' => array(
Expand Down
Loading

0 comments on commit 8f6aa38

Please sign in to comment.