PluginProbe
Tutor LMS – eLearning and online course solution / 3.7.3
Tutor LMS – eLearning and online course solution v3.7.3
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
← All changes | models/CourseModel.php +8 -174 3.9.143.7.3 View file →
@@ -44,29 +44,27 @@
44 44 const MODE_FLEXIBLE = 'flexible';
45 45 const MODE_STRICT = 'strict';
46 46
47 47 /**
48 - * Course attachment/downloadable resources meta key
48 + * Course mapped with the product using this meta key
49 49 *
50 50 * @var string
51 51 */
52 - const ATTACHMENT_META_KEY = '_tutor_attachments';
52 + const WC_PRODUCT_META_KEY = '_tutor_course_product_id';
53 53
54 54 /**
55 - * Course benefits meta key
55 + * Course attachment/downloadable resources meta key
56 56 *
57 57 * @var string
58 58 */
59 - const BENEFITS_META_KEY = '_tutor_course_benefits';
59 + const ATTACHMENT_META_KEY = '_tutor_attachments';
60 60
61 61 /**
62 - * The constant representing the status when a course is completed.
62 + * Course benefits meta key
63 63 *
64 - * @since 3.8.1
65 - *
66 64 * @var string
67 65 */
68 - const COURSE_COMPLETED = 'course_completed';
66 + const BENEFITS_META_KEY = '_tutor_course_benefits';
69 67
70 68 /**
71 69 * Get available status list.
72 70 *
@@ -505,11 +503,11 @@
505 503 do_action( 'tutor_before_delete_quiz_content', $content_id, null );
506 504
507 505 $questions_ids = $wpdb->get_col( $wpdb->prepare( "SELECT question_id FROM {$wpdb->prefix}tutor_quiz_questions WHERE quiz_id = %d ", $content_id ) );
508 506 if ( is_array( $questions_ids ) && count( $questions_ids ) ) {
509 - $in_clause = QueryHelper::prepare_in_clause( $questions_ids );
507 + $in_question_ids = "'" . implode( "','", $questions_ids ) . "'";
510 508 //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
511 - $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}tutor_quiz_question_answers WHERE belongs_question_id IN({$in_clause}) " ) );
509 + $wpdb->query( "DELETE FROM {$wpdb->prefix}tutor_quiz_question_answers WHERE belongs_question_id IN({$in_question_ids}) " );
512 510 }
513 511 $wpdb->delete( $wpdb->prefix . 'tutor_quiz_questions', array( 'quiz_id' => $content_id ) );
514 512 }
515 513
@@ -1152,170 +1150,6 @@
1152 1150 }
1153 1151 }
1154 1152
1155 1153 return $category_options;
1156 - }
1157 -
1158 - /**
1159 - * Retrieve all course completion records for a specific course, including meta data.
1160 - *
1161 - * @since 3.8.1
1162 - *
1163 - * @param int $course_id The ID of the course.
1164 - *
1165 - * @return array Array of course completion objects with meta, empty array if none found, or on database error.
1166 - */
1167 - public function get_course_completion_data_by_course_id( int $course_id ): array {
1168 -
1169 - global $wpdb;
1170 -
1171 - $where = array(
1172 - 'comment_type' => self::COURSE_COMPLETED,
1173 - 'comment_post_ID' => $course_id,
1174 - 'comment_agent' => 'TutorLMSPlugin',
1175 - );
1176 -
1177 - $result = QueryHelper::get_all( $wpdb->comments, $where, 'comment_post_ID', -1 );
1178 -
1179 - if ( empty( $result ) ) {
1180 - return array();
1181 - }
1182 -
1183 - return array_map(
1184 - function ( $item ) {
1185 -
1186 - return array(
1187 - 'completion' => $item,
1188 - 'completion_meta' => get_comment_meta( $item->comment_ID ),
1189 - );
1190 - },
1191 - $result
1192 - );
1193 - }
1194 -
1195 - /**
1196 - * Return completed courses by user_id
1197 - *
1198 - * @since 1.0.0
1199 - *
1200 - * @param int $user_id user id.
1201 - * @param int $offset offset.
1202 - * @param int $posts_per_page posts per page.
1203 - * @param array $args Args to override the defaults.
1204 - *
1205 - * @return bool|\WP_Query
1206 - */
1207 - public static function get_completed_courses_by_user( $user_id = 0, $offset = 0, $posts_per_page = -1, $args = array() ) {
1208 - $user_id = tutor_utils()->get_user_id( $user_id );
1209 - $course_ids = tutor_utils()->get_completed_courses_ids_by_user( $user_id );
1210 -
1211 - if ( count( $course_ids ) ) {
1212 - $course_post_type = tutor()->course_post_type;
1213 - $course_args = array(
1214 - 'post_type' => $course_post_type,
1215 - 'post_status' => 'publish',
1216 - 'post__in' => $course_ids,
1217 - 'posts_per_page' => $posts_per_page,
1218 - 'offset' => $offset,
1219 - );
1220 -
1221 - $args = apply_filters( 'tutor_get_completed_courses_by_user', $args, $user_id, $course_post_type );
1222 - $course_args = wp_parse_args( $args, $course_args );
1223 -
1224 - return new \WP_Query( $course_args );
1225 - }
1226 -
1227 - return false;
1228 - }
1229 -
1230 - /**
1231 - * Get the active course by user
1232 - *
1233 - * @since 1.0.0
1234 - *
1235 - * @param int $user_id user id.
1236 - * @param int $offset offset.
1237 - * @param int $posts_per_page posts per page.
1238 - * @param array $args Args to override the defaults.
1239 - *
1240 - * @return bool|\WP_Query
1241 - */
1242 - public static function get_active_courses_by_user( $user_id = 0, $offset = 0, $posts_per_page = -1, $args = array() ) {
1243 - $user_id = tutor_utils()->get_user_id( $user_id );
1244 - $course_ids = tutor_utils()->get_completed_courses_ids_by_user( $user_id );
1245 - $enrolled_course_ids = tutor_utils()->get_enrolled_courses_ids_by_user( $user_id );
1246 - $active_courses = array_diff( $enrolled_course_ids, $course_ids );
1247 -
1248 - if ( count( $active_courses ) ) {
1249 - $course_post_type = tutor()->course_post_type;
1250 - $course_args = array(
1251 - 'post_type' => apply_filters( 'tutor_active_courses_post_types', array( $course_post_type ) ),
1252 - 'post_status' => 'publish',
1253 - 'post__in' => $active_courses,
1254 - 'posts_per_page' => $posts_per_page,
1255 - 'offset' => $offset,
1256 - );
1257 -
1258 - $args = apply_filters( 'tutor_get_active_courses_by_user', $args, $user_id, $course_post_type );
1259 - $course_args = wp_parse_args( $args, $course_args );
1260 -
1261 - return new \WP_Query( $course_args );
1262 - }
1263 -
1264 - return false;
1265 - }
1266 -
1267 - /**
1268 - * Get the enrolled courses by user
1269 - *
1270 - * @since 1.0.0
1271 - * @since 2.5.0 $filters param added to query enrolled courses with additional filters.
1272 - *
1273 - * @since 3.4.0 $filters replaced with $args to override the defaults.
1274 - *
1275 - * @param integer $user_id user id.
1276 - * @param mixed $post_status post status.
1277 - * @param integer $offset offset.
1278 - * @param integer $posts_per_page post per page.
1279 - * @param array $args Args to override the defaults.
1280 - *
1281 - * @return bool|\WP_Query
1282 - */
1283 - public static function get_enrolled_courses_by_user( $user_id = 0, $post_status = 'publish', $offset = 0, $posts_per_page = -1, $args = array() ) {
1284 - $user_id = tutor_utils()->get_user_id( $user_id );
1285 - $course_ids = array_unique( tutor_utils()->get_enrolled_courses_ids_by_user( $user_id ) );
1286 -
1287 - if ( count( $course_ids ) ) {
1288 - $course_post_type = tutor()->course_post_type;
1289 - $course_args = array(
1290 - 'post_type' => $course_post_type,
1291 - 'post_status' => $post_status,
1292 - 'post__in' => $course_ids,
1293 - 'offset' => $offset,
1294 - 'posts_per_page' => $posts_per_page,
1295 - );
1296 -
1297 - $args = apply_filters( 'tutor_get_enrolled_courses_by_user', $args, $user_id, $course_post_type );
1298 - $course_args = wp_parse_args( $args, $course_args );
1299 -
1300 - $result = new \WP_Query( $course_args );
1301 -
1302 - if ( is_object( $result ) && is_array( $result->posts ) ) {
1303 -
1304 - // Sort courses according to the id list.
1305 - $new_array = array();
1306 -
1307 - foreach ( $course_ids as $id ) {
1308 - foreach ( $result->posts as $post ) {
1309 - $post->ID == $id ? $new_array[] = $post : 0;
1310 - }
1311 - }
1312 -
1313 - $result->posts = $new_array;
1314 - }
1315 -
1316 - return $result;
1317 - }
1318 -
1319 - return false;
1320 1154 }
1321 1155 }