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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Ajax.php
tutor / classes Last commit date
Addons.php 6 years ago Admin.php 6 years ago Ajax.php 6 years ago Assets.php 6 years ago Course.php 6 years ago Course_Widget.php 6 years ago Dashboard.php 6 years ago Gutenberg.php 6 years ago Instructor.php 6 years ago Instructors_List.php 6 years ago Lesson.php 6 years ago Options.php 6 years ago Post_types.php 6 years ago Q_and_A.php 6 years ago Question.php 6 years ago Question_Answers_List.php 6 years ago Quiz.php 6 years ago Quiz_Attempts_List.php 6 years ago Rewrite_Rules.php 6 years ago Shortcode.php 6 years ago Student.php 6 years ago Students_List.php 6 years ago Taxonomies.php 6 years ago Template.php 6 years ago Theme_Compatibility.php 6 years ago Tools.php 6 years ago Tutor.php 6 years ago TutorEDD.php 6 years ago Tutor_Base.php 6 years ago Tutor_List_Table.php 6 years ago Upgrader.php 6 years ago User.php 6 years ago Utils.php 6 years ago Video_Stream.php 6 years ago Withdraw.php 6 years ago Withdraw_Requests_List.php 6 years ago WooCommerce.php 6 years ago
Ajax.php
253 lines
1 <?php
2 namespace TUTOR;
3
4 if ( ! defined( 'ABSPATH' ) )
5 exit;
6
7 class Ajax{
8 public function __construct() {
9 add_action('wp_ajax_sync_video_playback', array($this, 'sync_video_playback'));
10 add_action('wp_ajax_nopriv_sync_video_playback', array($this, 'sync_video_playback_noprev'));
11 add_action('wp_ajax_tutor_place_rating', array($this, 'tutor_place_rating'));
12
13 add_action('wp_ajax_tutor_ask_question', array($this, 'tutor_ask_question'));
14 add_action('wp_ajax_tutor_add_answer', array($this, 'tutor_add_answer'));
15
16 add_action('wp_ajax_tutor_course_add_to_wishlist', array($this, 'tutor_course_add_to_wishlist'));
17 add_action('wp_ajax_nopriv_tutor_course_add_to_wishlist', array($this, 'tutor_course_add_to_wishlist'));
18
19 /**
20 * Addon Enable Disable Control
21 */
22 add_action('wp_ajax_addon_enable_disable', array($this, 'addon_enable_disable'));
23 }
24
25 /**
26 * Update video information and data when necessary
27 *
28 * @since v.1.0.0
29 */
30 public function sync_video_playback(){
31 tutor_utils()->checking_nonce();
32
33 $duration = sanitize_text_field($_POST['duration']);
34 $currentTime = sanitize_text_field($_POST['currentTime']);
35 $post_id = sanitize_text_field($_POST['post_id']);
36
37 /**
38 * Update posts attached video
39 */
40 $video = tutor_utils()->get_video($post_id);
41
42 if ($duration) {
43 $video['duration_sec'] = $duration; //secs
44 $video['playtime'] = tutor_utils()->playtime_string( $duration );
45 $video['runtime'] = tutor_utils()->playtime_array( $duration );
46 }
47 tutor_utils()->update_video($post_id, $video);
48
49 /**
50 * Sync Lesson Reading Info by Users
51 */
52
53 $user_id = get_current_user_id();
54
55 $best_watch_time = tutor_utils()->get_lesson_reading_info($post_id, $user_id, 'video_best_watched_time');
56 if ($best_watch_time < $currentTime){
57 tutor_utils()->update_lesson_reading_info($post_id, $user_id, 'video_best_watched_time', $currentTime);
58 }
59
60 if (tutor_utils()->avalue_dot('is_ended', $_POST)){
61 tutor_utils()->mark_lesson_complete($post_id);
62 }
63 exit();
64 }
65
66 public function sync_video_playback_noprev(){
67
68 }
69
70
71 public function tutor_place_rating(){
72 global $wpdb;
73
74 //TODO: Check nonce
75
76 $rating = sanitize_text_field(tutor_utils()->avalue_dot('rating', $_POST));
77 $course_id = sanitize_text_field(tutor_utils()->avalue_dot('course_id', $_POST));
78 $review = wp_kses_post(tutor_utils()->avalue_dot('review', $_POST));
79
80 $user_id = get_current_user_id();
81 $user = get_userdata($user_id);
82 $date = date("Y-m-d H:i:s");
83
84 do_action('tutor_before_rating_placed');
85
86 $previous_rating_id = $wpdb->get_var("select comment_ID from {$wpdb->comments} WHERE comment_post_ID={$course_id} AND user_id = {$user_id} AND comment_type = 'tutor_course_rating' LIMIT 1;");
87
88 $review_ID = $previous_rating_id;
89 if ( $previous_rating_id){
90 $wpdb->update( $wpdb->comments, array('comment_content' => $review),
91 array('comment_ID' => $previous_rating_id)
92 );
93 $wpdb->update( $wpdb->commentmeta, array('meta_value' => $rating),
94 array('comment_id' => $previous_rating_id, 'meta_key' => 'tutor_rating')
95 );
96 }else{
97 $data = array(
98 'comment_post_ID' => $course_id,
99 'comment_approved' => 'approved',
100 'comment_type' => 'tutor_course_rating',
101 'comment_date' => $date,
102 'comment_date_gmt' => get_gmt_from_date($date),
103 'user_id' => $user_id,
104 'comment_author' => $user->user_login,
105 'comment_agent' => 'TutorLMSPlugin',
106 );
107 if ($review){
108 $data['comment_content'] = $review;
109 }
110
111 $wpdb->insert($wpdb->comments, $data);
112 $comment_id = (int) $wpdb->insert_id;
113 $review_ID = $comment_id;
114
115 if ($comment_id && $rating){
116 $result = $wpdb->insert( $wpdb->commentmeta, array(
117 'comment_id' => $comment_id,
118 'meta_key' => 'tutor_rating',
119 'meta_value' => $rating
120 ) );
121
122 do_action('tutor_after_rating_placed', $comment_id);
123 }
124 }
125
126 $data = array('msg' => __('Rating placed success', 'tutor'), 'review_id' => $review_ID, 'review' => $review);
127 wp_send_json_success($data);
128 }
129
130 public function tutor_ask_question(){
131 tutor_utils()->checking_nonce();
132
133 global $wpdb;
134
135 $course_id = (int) sanitize_text_field($_POST['tutor_course_id']);
136 $question_title = sanitize_text_field($_POST['question_title']);
137 $question = wp_kses_post($_POST['question']);
138
139 if (empty($question) || empty($question_title)){
140 wp_send_json_error(__('Empty question title or body', 'tutor'));
141 }
142
143 $user_id = get_current_user_id();
144 $user = get_userdata($user_id);
145 $date = date("Y-m-d H:i:s");
146
147 do_action('tutor_before_add_question', $course_id);
148 $data = apply_filters('tutor_add_question_data', array(
149 'comment_post_ID' => $course_id,
150 'comment_author' => $user->user_login,
151 'comment_date' => $date,
152 'comment_date_gmt' => get_gmt_from_date($date),
153 'comment_content' => $question,
154 'comment_approved' => 'waiting_for_answer',
155 'comment_agent' => 'TutorLMSPlugin',
156 'comment_type' => 'tutor_q_and_a',
157 'user_id' => $user_id,
158 ));
159
160 $wpdb->insert($wpdb->comments, $data);
161 $comment_id = (int) $wpdb->insert_id;
162
163 if ($comment_id){
164 $result = $wpdb->insert( $wpdb->commentmeta, array(
165 'comment_id' => $comment_id,
166 'meta_key' => 'tutor_question_title',
167 'meta_value' => $question_title
168 ) );
169 }
170 do_action('tutor_after_add_question', $course_id, $comment_id);
171
172 wp_send_json_success(__('Question has been added successfully', 'tutor'));
173 }
174
175
176 public function tutor_add_answer(){
177 tutor_utils()->checking_nonce();
178 global $wpdb;
179
180 $answer = wp_kses_post($_POST['answer']);
181 if ( ! $answer){
182 wp_send_json_error(__('Please write answer', 'tutor'));
183 }
184
185 $question_id = (int) sanitize_text_field($_POST['question_id']);
186 $question = tutor_utils()->get_qa_question($question_id);
187
188 $user_id = get_current_user_id();
189 $user = get_userdata($user_id);
190 $date = date("Y-m-d H:i:s");
191
192 do_action('tutor_before_answer_to_question');
193 $data = apply_filters('tutor_add_answer_data', array(
194 'comment_post_ID' => $question->comment_post_ID,
195 'comment_author' => $user->user_login,
196 'comment_date' => $date,
197 'comment_date_gmt' => get_gmt_from_date($date),
198 'comment_content' => $answer,
199 'comment_approved' => 'approved',
200 'comment_agent' => 'TutorLMSPlugin',
201 'comment_type' => 'tutor_q_and_a',
202 'comment_parent' => $question_id,
203 'user_id' => $user_id,
204 ));
205
206 $wpdb->insert($wpdb->comments, $data);
207 $comment_id = (int) $wpdb->insert_id;
208 do_action('tutor_after_answer_to_question', $comment_id);
209
210 wp_send_json_success(__('Answer has been added successfully', 'tutor'));
211 }
212
213
214 public function tutor_course_add_to_wishlist(){
215 $course_id = (int) sanitize_text_field($_POST['course_id']);
216 if ( ! is_user_logged_in()){
217 wp_send_json_error(array('redirect_to' => wp_login_url( wp_get_referer() ) ) );
218 }
219 global $wpdb;
220
221 $user_id = get_current_user_id();
222 $if_added_to_list = $wpdb->get_row("select * from {$wpdb->usermeta} WHERE user_id = {$user_id} AND meta_key = '_tutor_course_wishlist' AND meta_value = {$course_id} ;");
223
224 if ( $if_added_to_list){
225 $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => '_tutor_course_wishlist', 'meta_value' => $course_id ));
226 wp_send_json_success(array('status' => 'removed', 'msg' => __('Course removed from wish list', 'tutor')));
227 }else{
228 add_user_meta($user_id, '_tutor_course_wishlist', $course_id);
229 wp_send_json_success(array('status' => 'added', 'msg' => __('Course added to wish list', 'tutor')));
230 }
231 }
232
233 /**
234 * Method for enable / disable addons
235 */
236 public function addon_enable_disable(){
237 $addonsConfig = maybe_unserialize(get_option('tutor_addons_config'));
238
239 $isEnable = (bool) sanitize_text_field(tutor_utils()->avalue_dot('isEnable', $_POST));
240 $addonFieldName = sanitize_text_field(tutor_utils()->avalue_dot('addonFieldName', $_POST));
241
242 if ($isEnable){
243 $addonsConfig[$addonFieldName]['is_enable'] = 1;
244 }else{
245 $addonsConfig[$addonFieldName]['is_enable'] = 0;
246 }
247
248 update_option('tutor_addons_config', $addonsConfig);
249
250 wp_send_json_success();
251 }
252
253 }