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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 7 years ago Admin.php 7 years ago Ajax.php 7 years ago Assets.php 7 years ago Course.php 7 years ago Gutenberg.php 7 years ago Instructor.php 7 years ago Instructors_List.php 7 years ago Lesson.php 7 years ago Options.php 7 years ago Post_types.php 7 years ago Q_and_A.php 7 years ago Question.php 7 years ago Question_Answers_List.php 7 years ago Quiz.php 7 years ago Quiz_Attempts_List.php 7 years ago Rewrite_Rules.php 7 years ago Shortcode.php 7 years ago Student.php 7 years ago Students_List.php 7 years ago Template.php 7 years ago Theme_Compatibility.php 7 years ago Tools.php 7 years ago Tutor_Base.php 7 years ago Tutor_List_Table.php 7 years ago User.php 7 years ago Utils.php 7 years ago Video_Stream.php 7 years ago init.php 7 years ago
Ajax.php
260 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
79 $review = wp_kses_post(tutor_utils()->avalue_dot('review', $_POST));
80
81
82 $user_id = get_current_user_id();
83 $user = get_userdata($user_id);
84 $date = date("Y-m-d H:i:s");
85
86 do_action('tutor_before_rating_placed');
87
88 $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;");
89
90 $review_ID = $previous_rating_id;
91 if ( $previous_rating_id){
92 if ($review){
93 $wpdb->update( $wpdb->comments, array('comment_content' => $review),
94 array('comment_ID' => $previous_rating_id)
95 );
96 }
97
98 if ($rating){
99 $wpdb->update( $wpdb->commentmeta, array('meta_value' => $rating),
100 array('comment_id' => $previous_rating_id, 'meta_key' => 'tutor_rating')
101 );
102 }
103 }else{
104 $data = array(
105 'comment_post_ID' => $course_id,
106 'comment_approved' => 'approved',
107 'comment_type' => 'tutor_course_rating',
108 'comment_date' => $date,
109 'comment_date_gmt' => get_gmt_from_date($date),
110 'user_id' => $user_id,
111 'comment_author' => $user->user_login,
112 'comment_agent' => 'TutorLMSPlugin',
113 );
114 if ($review){
115 $data['comment_content'] = $review;
116 }
117
118 $wpdb->insert($wpdb->comments, $data);
119 $comment_id = (int) $wpdb->insert_id;
120 $review_ID = $comment_id;
121
122 if ($comment_id && $rating){
123 $result = $wpdb->insert( $wpdb->commentmeta, array(
124 'comment_id' => $comment_id,
125 'meta_key' => 'tutor_rating',
126 'meta_value' => $rating
127 ) );
128
129 do_action('tutor_after_rating_placed', $comment_id);
130 }
131 }
132
133 $data = array('msg' => __('Rating placed success', 'tutor'), 'review_id' => $review_ID, 'review' => $review);
134 wp_send_json_success($data);
135 }
136
137 public function tutor_ask_question(){
138 tutor_utils()->checking_nonce();
139
140 global $wpdb;
141
142 $course_id = (int) sanitize_text_field($_POST['tutor_course_id']);
143 $question_title = sanitize_text_field($_POST['question_title']);
144 $question = wp_kses_post($_POST['question']);
145
146 if (empty($question) || empty($question_title)){
147 wp_send_json_error(__('Empty question title or body', 'tutor'));
148 }
149
150 $user_id = get_current_user_id();
151 $user = get_userdata($user_id);
152 $date = date("Y-m-d H:i:s");
153
154 do_action('tutor_before_add_question', $course_id);
155 $data = apply_filters('tutor_add_question_data', array(
156 'comment_post_ID' => $course_id,
157 'comment_author' => $user->user_login,
158 'comment_date' => $date,
159 'comment_date_gmt' => get_gmt_from_date($date),
160 'comment_content' => $question,
161 'comment_approved' => 'waiting_for_answer',
162 'comment_agent' => 'TutorLMSPlugin',
163 'comment_type' => 'tutor_q_and_a',
164 'user_id' => $user_id,
165 ));
166
167 $wpdb->insert($wpdb->comments, $data);
168 $comment_id = (int) $wpdb->insert_id;
169
170 if ($comment_id){
171 $result = $wpdb->insert( $wpdb->commentmeta, array(
172 'comment_id' => $comment_id,
173 'meta_key' => 'tutor_question_title',
174 'meta_value' => $question_title
175 ) );
176 }
177 do_action('tutor_after_add_question', $course_id, $comment_id);
178
179 wp_send_json_success(__('Question has been added successfully', 'tutor'));
180 }
181
182
183 public function tutor_add_answer(){
184 tutor_utils()->checking_nonce();
185 global $wpdb;
186
187 $answer = wp_kses_post($_POST['answer']);
188 if ( ! $answer){
189 wp_send_json_error(__('Please write answer', 'tutor'));
190 }
191
192 $question_id = (int) sanitize_text_field($_POST['question_id']);
193 $question = tutor_utils()->get_qa_question($question_id);
194
195 $user_id = get_current_user_id();
196 $user = get_userdata($user_id);
197 $date = date("Y-m-d H:i:s");
198
199 do_action('tutor_before_answer_to_question');
200 $data = apply_filters('tutor_add_answer_data', array(
201 'comment_post_ID' => $question->comment_post_ID,
202 'comment_author' => $user->user_login,
203 'comment_date' => $date,
204 'comment_date_gmt' => get_gmt_from_date($date),
205 'comment_content' => $answer,
206 'comment_approved' => 'approved',
207 'comment_agent' => 'TutorLMSPlugin',
208 'comment_type' => 'tutor_q_and_a',
209 'comment_parent' => $question_id,
210 'user_id' => $user_id,
211 ));
212
213 $wpdb->insert($wpdb->comments, $data);
214 $comment_id = (int) $wpdb->insert_id;
215 do_action('tutor_after_answer_to_question', $comment_id);
216
217 wp_send_json_success(__('Answer has been added successfully', 'tutor'));
218 }
219
220
221 public function tutor_course_add_to_wishlist(){
222 $course_id = (int) sanitize_text_field($_POST['course_id']);
223 if ( ! is_user_logged_in()){
224 wp_send_json_error(array('redirect_to' => wp_login_url( wp_get_referer() ) ) );
225 }
226 global $wpdb;
227
228 $user_id = get_current_user_id();
229 $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} ;");
230
231 if ( $if_added_to_list){
232 $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => '_tutor_course_wishlist', 'meta_value' => $course_id ));
233 wp_send_json_success(array('status' => 'removed', 'msg' => __('Course removed from wish list', 'tutor')));
234 }else{
235 update_user_meta($user_id, '_tutor_course_wishlist', $course_id);
236 wp_send_json_success(array('status' => 'added', 'msg' => __('Course added to wish list', 'tutor')));
237 }
238 }
239
240 /**
241 * Method for enable / disable addons
242 */
243 public function addon_enable_disable(){
244 $addonsConfig = maybe_unserialize(get_option('tutor_addons_config'));
245
246 $isEnable = (bool) sanitize_text_field(tutor_utils()->avalue_dot('isEnable', $_POST));
247 $addonFieldName = sanitize_text_field(tutor_utils()->avalue_dot('addonFieldName', $_POST));
248
249 if ($isEnable){
250 $addonsConfig[$addonFieldName]['is_enable'] = 1;
251 }else{
252 $addonsConfig[$addonFieldName]['is_enable'] = 0;
253 }
254
255 update_option('tutor_addons_config', $addonsConfig);
256
257 wp_send_json_success();
258 }
259
260 }