PluginProbe
Tutor LMS – eLearning and online course solution / 3.9.2
Tutor LMS – eLearning and online course solution v3.9.2
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/OrderModel.php +65 -164 trunk3.9.2 View file →
@@ -9,24 +9,17 @@
9 9 */
10 10
11 11 namespace Tutor\Models;
12 12
13 -use DateTime;
14 13 use Exception;
15 -use Tutor\Cache\TutorCache;
16 -use Tutor\Components\Badge;
17 -use Tutor\Components\Button;
18 -use Tutor\Components\Constants\Variant;
19 14 use TUTOR\Earnings;
15 +use Tutor\Ecommerce\Tax;
16 +use Tutor\Ecommerce\Ecommerce;
17 +use Tutor\Helpers\QueryHelper;
18 +use Tutor\Helpers\DateTimeHelper;
20 19 use Tutor\Ecommerce\BillingController;
21 20 use Tutor\Ecommerce\CheckoutController;
22 -use Tutor\Ecommerce\Ecommerce;
23 21 use Tutor\Ecommerce\OrderActivitiesController;
24 -use Tutor\Ecommerce\Tax;
25 -use Tutor\Helpers\DateTimeHelper;
26 -use Tutor\Helpers\QueryHelper;
27 -use TUTOR\User;
28 -use TutorPro\Ecommerce\Invoice;
29 22
30 23 /**
31 24 * OrderModel Class
32 25 *
@@ -44,9 +37,8 @@
44 37 const ORDER_INCOMPLETE = 'incomplete';
45 38 const ORDER_COMPLETED = 'completed';
46 39 const ORDER_CANCELLED = 'cancelled';
47 40 const ORDER_TRASH = 'trash';
48 - const ORDER_PENDING = 'pending';
49 41
50 42 /**
51 43 * Payment status
52 44 *
@@ -58,9 +50,8 @@
58 50 const PAYMENT_FAILED = 'failed';
59 51 const PAYMENT_UNPAID = 'unpaid';
60 52 const PAYMENT_REFUNDED = 'refunded';
61 53 const PAYMENT_PARTIALLY_REFUNDED = 'partially-refunded';
62 - const PAYMENT_PENDING = 'pending';
63 54
64 55 /**
65 56 * Payment methods
66 57 *
@@ -299,9 +290,8 @@
299 290 self::ORDER_INCOMPLETE => __( 'Incomplete', 'tutor' ),
300 291 self::ORDER_COMPLETED => __( 'Completed', 'tutor' ),
301 292 self::ORDER_CANCELLED => __( 'Cancelled', 'tutor' ),
302 293 self::ORDER_TRASH => __( 'Trash', 'tutor' ),
303 - self::ORDER_PENDING => __( 'Pending', 'tutor' ),
304 294 );
305 295 }
306 296
307 297 /**
@@ -332,9 +322,8 @@
332 322 self::PAYMENT_UNPAID => __( 'Unpaid', 'tutor' ),
333 323 self::PAYMENT_FAILED => __( 'Failed', 'tutor' ),
334 324 self::PAYMENT_REFUNDED => __( 'Refunded', 'tutor' ),
335 325 self::PAYMENT_PARTIALLY_REFUNDED => __( 'Partially Refunded', 'tutor' ),
336 - self::PAYMENT_PENDING => __( 'Pending', 'tutor' ),
337 326 );
338 327 }
339 328
340 329 /**
@@ -531,13 +520,8 @@
531 520 $order_activities_model = new OrderActivitiesModel();
532 521 $order_data->activities = $order_activities_model->get_order_activities( $order_id );
533 522 $order_data->refunds = $this->get_order_refunds( $order_id );
534 523
535 - $enrollment_ids = $this->get_enrollment_ids( $order_id );
536 - if ( tutor_utils()->count( $enrollment_ids ) ) {
537 - $order_data->enrollment = EnrollmentModel::get_enrolment_by_enrol_id( $enrollment_ids[0] );
538 - }
539 -
540 524 unset( $student->billing_address->id );
541 525 unset( $student->billing_address->user_id );
542 526
543 527 return apply_filters( 'tutor_order_details', $order_data );
@@ -638,25 +622,22 @@
638 622 * items are found.
639 623 *
640 624 * @since 3.0.0
641 625 *
626 + * @global wpdb $wpdb WordPress database abstraction object.
627 + *
642 628 * @param int $order_id The ID of the order to retrieve items for.
643 629 *
644 630 * @return array The order items, each containing details and course titles, or an empty array if no items are found.
645 631 */
646 632 public function get_order_items_by_id( $order_id ) {
647 - $cache_key = 'tutor_get_order_items_by_id_' . $order_id;
648 - $cached = TutorCache::get( $cache_key );
633 + global $wpdb;
649 634
650 - if ( $cached ) {
651 - return $cached;
652 - }
653 -
654 - $primary_table = 'tutor_order_items AS oi';
635 + $primary_table = "{$wpdb->prefix}tutor_order_items AS oi";
655 636 $joining_tables = array(
656 637 array(
657 638 'type' => 'LEFT',
658 - 'table' => 'posts AS p',
639 + 'table' => "{$wpdb->prefix}posts AS p",
659 640 'on' => 'p.ID = oi.item_id',
660 641 ),
661 642 );
662 643
@@ -666,13 +647,15 @@
666 647
667 648 $courses_data = QueryHelper::get_joined_data( $primary_table, $joining_tables, $select_columns, $where, array(), 'id', 0, 0 );
668 649 $courses = $courses_data['results'];
669 650
670 - $bundle_model = tutor()->has_pro ? new \TutorPro\CourseBundle\Models\BundleModel() : null;
651 + if ( tutor()->has_pro ) {
652 + $bundle_model = new \TutorPro\CourseBundle\Models\BundleModel();
653 + }
671 654
672 655 if ( ! empty( $courses_data['total_count'] ) ) {
673 656 foreach ( $courses as &$course ) {
674 - if ( is_object( $bundle_model ) && tutor()->bundle_post_type === $course->type ) {
657 + if ( tutor()->has_pro && 'course-bundle' === $course->type ) {
675 658 $course->total_courses = count( $bundle_model->get_bundle_course_ids( $course->id ) );
676 659 }
677 660
678 661 $course->id = (int) $course->id;
@@ -686,12 +669,9 @@
686 669 }
687 670
688 671 unset( $course );
689 672
690 - $result = ! empty( $courses ) ? $courses : array();
691 - TutorCache::set( $cache_key, $result );
692 -
693 - return $result;
673 + return ! empty( $courses ) ? $courses : array();
694 674 }
695 675
696 676 /**
697 677 * Get order billing address with fallback customer billing address record support.
@@ -853,9 +833,9 @@
853 833 $wpdb->prepare(
854 834 "SELECT * FROM {$wpdb->postmeta}
855 835 WHERE meta_key=%s
856 836 AND meta_value LIKE %d",
857 - EnrollmentModel::ENROLLMENT_ORDER_ID_META,
837 + '_tutor_enrolled_by_order_id',
858 838 $order_id
859 839 )
860 840 );
861 841
@@ -1007,30 +987,23 @@
1007 987 /**
1008 988 * Get order of a user
1009 989 *
1010 990 * @since 3.0.0
1011 - * @since 4.0.0 params $order_status, $order and $args added.
1012 991 *
1013 992 * @param string $time_period $time_period Sorting time period,
1014 993 * supported time periods are: today, monthly & yearly.
1015 994 * @param string $start_date $start_date For date range sorting.
1016 995 * @param string $end_date $end_date For date range sorting.
1017 - * @param string $order_status $order_status Order status.
1018 996 * @param int $user_id User id for fetching order list.
1019 997 * @param int $limit Limit to fetch record.
1020 998 * @param int $offset Offset to fetch record.
1021 - * @param string $order Order to fetch record.
1022 - * @param array $args Optional additional WHERE conditions.
1023 999 *
1024 1000 * @throws \Exception Throw exception if database error occur.
1025 1001 *
1026 1002 * @return array
1027 1003 */
1028 - public function get_user_orders( $time_period = null, $start_date = null, $end_date = null, $order_status = '', int $user_id = 0, $limit = 10, int $offset = 0, $order = 'DESC', $args = array() ) {
1029 - $user_id = tutor_utils()->get_user_id( $user_id );
1030 - $order = QueryHelper::get_valid_sort_order( $order );
1031 - $order_status = esc_sql( $order_status );
1032 - $order_type_clause = '';
1004 + public function get_user_orders( $time_period = null, $start_date = null, $end_date = null, int $user_id = 0, $limit = 10, int $offset = 0 ) {
1005 + $user_id = $user_id ? $user_id : get_current_user_id();
1033 1006
1034 1007 $response = array(
1035 1008 'results' => array(),
1036 1009 'total_count' => 0,
@@ -1037,11 +1010,10 @@
1037 1010 );
1038 1011
1039 1012 global $wpdb;
1040 1013
1041 - $time_period_clause = '';
1042 - $date_range_clause = '';
1043 - $order_status_clause = ( empty( $order_status ) || 'all' === $order_status ) ? '' : "AND o.order_status = '{$order_status}'";
1014 + $time_period_clause = '';
1015 + $date_range_clause = '';
1044 1016
1045 1017 if ( $start_date && $end_date ) {
1046 1018 $date_range_clause = $wpdb->prepare( 'AND DATE(created_at_gmt) BETWEEN %s AND %s', $start_date, $end_date );
1047 1019 } elseif ( $time_period ) {
@@ -1053,12 +1025,8 @@
1053 1025 $time_period_clause = 'AND YEAR(o.created_at_gmt) = YEAR(CURDATE()) ';
1054 1026 }
1055 1027 }
1056 1028
1057 - if ( ! empty( $args['order_type'] ) ) {
1058 - $order_type_clause = ' AND ' . QueryHelper::prepare_where_clause( array( 'o.order_type' => esc_sql( $args['order_type'] ) ) );
1059 - }
1060 -
1061 1029 //phpcs:disable
1062 1030 $query = $wpdb->prepare(
1063 1031 "SELECT
1064 1032 SQL_CALC_FOUND_ROWS
@@ -1064,13 +1032,11 @@
1064 1032 SQL_CALC_FOUND_ROWS
1065 1033 o.*
1066 1034 FROM $this->table_name AS o
1067 1035 WHERE o.user_id = %d
1068 - {$order_type_clause}
1069 1036 {$time_period_clause}
1070 1037 {$date_range_clause}
1071 - {$order_status_clause}
1072 - ORDER BY o.id {$order}
1038 + ORDER BY o.id DESC
1073 1039 LIMIT %d OFFSET %d
1074 1040 ",
1075 1041 $user_id,
1076 1042 $limit,
@@ -1097,9 +1063,8 @@
1097 1063 *
1098 1064 * If period or date range not pass then it will return all time enrollment list
1099 1065 *
1100 1066 * @since 3.0.0
1101 - * @since 4.0.0 Minor query updates for the new graph.
1102 1067 *
1103 1068 * @param int $user_id User id, if user not have admin access
1104 1069 * then only this user's refund amount will fetched.
1105 1070 * @param string $period Time period.
@@ -1120,10 +1085,10 @@
1120 1085 $user_clause = '';
1121 1086 $date_range_clause = '';
1122 1087 $period_clause = '';
1123 1088 $course_clause = '';
1124 - $group_clause = ' GROUP BY DATE(o.created_at_gmt) ';
1125 - $select_query = " DATE_FORMAT(o.created_at_gmt, '%%b') AS label_name, DATE(o.created_at_gmt) AS date_format ";
1089 + $group_clause = ' GROUP BY DATE(date_format) ';
1090 + $discount_clause = 'o.coupon_amount as total';
1126 1091
1127 1092 if ( $start_date && $end_date ) {
1128 1093 $date_range_clause = $wpdb->prepare(
1129 1094 'AND o.created_at_gmt BETWEEN %s AND %s',
@@ -1129,23 +1094,14 @@
1129 1094 'AND o.created_at_gmt BETWEEN %s AND %s',
1130 1095 $start_date,
1131 1096 $end_date
1132 1097 );
1133 -
1134 - $diff_days = ( new DateTime( $start_date ) )->diff( new DateTime( $end_date ) )->days;
1135 -
1136 - if ( $diff_days > 31 ) {
1137 - $group_clause = ' GROUP BY MONTH(o.created_at_gmt) ';
1138 - $select_query = " DATE_FORMAT(o.created_at_gmt, '%%b') AS label_name ";
1139 -
1140 - }
1141 1098 } else {
1142 1099 $period_clause = QueryHelper::get_period_clause( 'o.created_at_gmt', $period );
1143 1100 }
1144 1101
1145 - if ( in_array( $period, array( 'last90days', 'last365days', 'yearly' ), true ) ) {
1146 - $group_clause = ' GROUP BY MONTH(o.created_at_gmt) ';
1147 - $select_query = " DATE_FORMAT(o.created_at_gmt, '%%b') AS label_name ";
1102 + if ( 'today' !== $period ) {
1103 + $group_clause = ' GROUP BY MONTH(date_format) ';
1148 1104 }
1149 1105
1150 1106 if ( $course_id ) {
1151 1107 $course_clause = $wpdb->prepare( 'AND i.item_id = %d', $course_id );
@@ -1174,9 +1130,9 @@
1174 1130 ),
1175 1131 0
1176 1132 )
1177 1133 ) AS total,
1178 - {$select_query}
1134 + o.created_at_gmt AS date_format
1179 1135 FROM
1180 1136 {$this->table_name} o
1181 1137 JOIN
1182 1138 {$item_table} i ON o.id = i.order_id
@@ -1216,9 +1172,9 @@
1216 1172 ),
1217 1173 0
1218 1174 )
1219 1175 ) AS total,
1220 - {$select_query}
1176 + o.created_at_gmt AS date_format
1221 1177 FROM {$this->table_name} AS o
1222 1178 WHERE 1 = %d
1223 1179 AND o.order_status = 'completed'
1224 1180 {$user_clause}
@@ -1249,15 +1205,15 @@
1249 1205
1250 1206 // Split each discount.
1251 1207 list( $admin_discount, $instructor_discount ) = array_values( tutor_split_amounts( $discount->total ) );
1252 1208
1253 - $discount->total = User::is_admin() && is_admin() ? $admin_discount : $instructor_discount;
1209 + $discount->total = is_admin() ? $admin_discount : $instructor_discount;
1254 1210 }
1255 1211
1256 1212 list( $admin_total, $instructor_total ) = array_values( tutor_split_amounts( $total_discount ) );
1257 1213
1258 1214 $response['discounts'] = $discount_items;
1259 - $response['total_discounts'] = User::is_admin() && is_admin() ? $admin_total : $instructor_total;
1215 + $response['total_discounts'] = is_admin() ? $admin_total : $instructor_total;
1260 1216 }
1261 1217
1262 1218 return $response;
1263 1219 }
@@ -1269,9 +1225,8 @@
1269 1225 *
1270 1226 * If period or date range not pass then it will return all time enrollment list
1271 1227 *
1272 1228 * @since 3.0.0
1273 - * @since 4.0.0 Minor query updates for the new graph.
1274 1229 *
1275 1230 * @param int $user_id User id, if user not have admin access
1276 1231 * then only this user's refund amount will fetched.
1277 1232 * @param string $period Time period.
@@ -1291,31 +1246,26 @@
1291 1246
1292 1247 $user_clause = '';
1293 1248 $date_range_clause = '';
1294 1249 $period_clause = '';
1295 - $group_clause = ' GROUP BY DATE(order_meta.created_at_gmt) ';
1296 - $select_query = " DATE_FORMAT(order_meta.created_at_gmt, '%%b') AS label_name, order_meta.created_at_gmt AS date_format ";
1250 + $course_clause = '';
1251 + $commission_clause = '';
1252 + $group_clause = ' GROUP BY DATE(o.created_at_gmt) ';
1297 1253
1298 1254 if ( $start_date && $end_date ) {
1299 1255 $date_range_clause = $wpdb->prepare(
1300 - 'AND DATE(order_meta.created_at_gmt) BETWEEN %s AND %s',
1256 + 'AND o.created_at_gmt BETWEEN %s AND %s',
1301 1257 $start_date,
1302 1258 $end_date
1303 1259 );
1260 + $group_clause = ' GROUP BY DATE(o.created_at_gmt) ';
1304 1261
1305 - $diff_days = ( new DateTime( $start_date ) )->diff( new DateTime( $end_date ) )->days;
1306 -
1307 - if ( $diff_days > 31 ) {
1308 - $group_clause = ' GROUP BY MONTH(order_meta.created_at_gmt) ';
1309 - $select_query = " DATE_FORMAT(order_meta.created_at_gmt, '%%b') AS label_name ";
1310 - }
1311 1262 } else {
1312 - $period_clause = QueryHelper::get_period_clause( 'order_meta.created_at_gmt', $period );
1263 + $period_clause = QueryHelper::get_period_clause( 'o.created_at_gmt', $period );
1313 1264 }
1314 1265
1315 - if ( in_array( $period, array( 'last90days', 'last365days', 'yearly' ), true ) ) {
1316 - $group_clause = ' GROUP BY MONTH(order_meta.created_at_gmt) ';
1317 - $select_query = " DATE_FORMAT(order_meta.created_at_gmt, '%%b') AS label_name ";
1266 + if ( 'today' !== $period ) {
1267 + $group_clause = ' GROUP BY MONTH(o.created_at_gmt) ';
1318 1268 }
1319 1269
1320 1270 if ( $course_id ) {
1321 1271 if ( $user_id ) {
@@ -1321,20 +1271,13 @@
1321 1271 if ( $user_id ) {
1322 1272 $user_clause = $wpdb->prepare( 'AND c.post_author = %d', $user_id );
1323 1273 }
1324 1274 } elseif ( $user_id ) {
1325 - $user_clause = $wpdb->prepare( 'AND c.post_author = %d', $user_id );
1275 + $user_clause = $wpdb->prepare( 'AND c.post_author = %d', $user_id );
1326 1276 }
1327 1277
1328 1278 // Refund query logic remains the same.
1329 - $item_table = $wpdb->prefix . 'tutor_order_items';
1330 - $order_meta_table = $wpdb->prefix . 'tutor_ordermeta';
1331 - $order_meta_in_clause = QueryHelper::prepare_in_clause(
1332 - array(
1333 - OrderActivitiesModel::META_KEY_REFUND,
1334 - OrderActivitiesModel::META_KEY_PARTIALLY_REFUND,
1335 - )
1336 - );
1279 + $item_table = $wpdb->prefix . 'tutor_order_items';
1337 1280
1338 1281 if ( $course_id ) {
1339 1282 //phpcs:disable
1340 1283 $refunds = $wpdb->get_results(
@@ -1351,10 +1294,9 @@
1351 1294 ELSE i.regular_price
1352 1295 END / o.total_price
1353 1296 )
1354 1297 ), 2
1355 - ) AS total,
1356 - {$select_query}
1298 + ) AS total
1357 1299 FROM
1358 1300 {$this->table_name} o
1359 1301 JOIN
1360 1302 {$item_table} i ON o.id = i.order_id
@@ -1361,11 +1303,8 @@
1361 1303 JOIN
1362 1304 {$wpdb->posts} c
1363 1305 ON c.ID = i.item_id
1364 1306 AND c.post_type = %s
1365 - JOIN {$order_meta_table} AS order_meta
1366 - ON order_meta.order_id = o.id
1367 - AND order_meta.meta_key IN ({$order_meta_in_clause})
1368 1307 WHERE
1369 1308 o.refund_amount > 0
1370 1309 AND i.item_id = %d
1371 1310 {$user_clause}
@@ -1370,10 +1309,11 @@
1370 1309 AND i.item_id = %d
1371 1310 {$user_clause}
1372 1311 {$period_clause}
1373 1312 {$date_range_clause}
1374 - {$group_clause}
1375 - ORDER BY order_meta.created_at_gmt ASC",
1313 + {$group_clause},
1314 + i.item_id
1315 + ",
1376 1316 tutor()->course_post_type,
1377 1317 $course_id
1378 1318 )
1379 1319 );
@@ -1380,9 +1320,9 @@
1380 1320 //phpcs:enable
1381 1321 } else {
1382 1322 $earning_table = $wpdb->tutor_earnings;
1383 1323 if ( $user_id ) {
1384 - $user_clause = "AND {$user_id} = (SELECT user_id FROM {$earning_table} WHERE user_id = {$user_id} LIMIT 1)";
1324 + $user_clause = "AND {$user_id} = (SELECT user_id FROM {$earning_table} LIMIT 1)";
1385 1325 }
1386 1326
1387 1327 //phpcs:disable
1388 1328 $refunds = $wpdb->get_results(
@@ -1388,20 +1328,19 @@
1388 1328 $refunds = $wpdb->get_results(
1389 1329 $wpdb->prepare(
1390 1330 "SELECT
1391 1331 COALESCE(SUM(o.refund_amount), 0) AS total,
1392 - {$select_query}
1332 + created_at_gmt AS date_format
1393 1333 FROM {$this->table_name} AS o
1394 - LEFT JOIN {$order_meta_table} AS order_meta
1395 - ON order_meta.order_id = o.id
1396 - AND order_meta.meta_key IN ({$order_meta_in_clause})
1334 + -- LEFT JOIN {$item_table} AS i ON i.order_id = o.id
1335 + -- LEFT JOIN {$wpdb->posts} AS c ON c.id = i.item_id
1397 1336 WHERE 1 = %d
1398 1337 AND o.refund_amount > %d
1399 1338 {$user_clause}
1400 1339 {$period_clause}
1401 1340 {$date_range_clause}
1402 - {$group_clause}
1403 - ORDER BY order_meta.created_at_gmt ASC",
1341 + {$group_clause},
1342 + o.id",
1404 1343 1,
1405 1344 0
1406 1345 )
1407 1346 );
@@ -1414,9 +1353,9 @@
1414 1353 $total_refund += $refund->total;
1415 1354
1416 1355 // Update total amount from list.
1417 1356 $split_refund = (object) tutor_split_amounts( $refund->total );
1418 - $refund->total = User::is_admin() && is_admin() ? $split_refund->admin : $split_refund->instructor;
1357 + $refund->total = is_admin() ? $split_refund->admin : $split_refund->instructor;
1419 1358 }
1420 1359
1421 1360 $split_total_refund = (object) tutor_split_amounts( $total_refund );
1422 1361
@@ -1421,9 +1360,9 @@
1421 1360 $split_total_refund = (object) tutor_split_amounts( $total_refund );
1422 1361
1423 1362 $response = array(
1424 1363 'refunds' => $refunds,
1425 - 'total_refunds' => User::is_admin() && is_admin() ? $split_total_refund->admin : $split_total_refund->instructor,
1364 + 'total_refunds' => is_admin() ? $split_total_refund->admin : $split_total_refund->instructor,
1426 1365 );
1427 1366
1428 1367 return $response;
1429 1368 }
@@ -1855,9 +1794,9 @@
1855 1794 if ( self::TYPE_SINGLE_ORDER === $order->order_type ) {
1856 1795 foreach ( $order_items as $item ) {
1857 1796 $course_id = $item->id;
1858 1797 if ( $course_id ) {
1859 - $is_enrolled = EnrollmentModel::is_enrolled( $course_id );
1798 + $is_enrolled = tutor_utils()->is_enrolled( $course_id );
1860 1799 if ( $is_enrolled ) {
1861 1800 $is_enrolled_any_course = true;
1862 1801 break;
1863 1802 }
@@ -1864,9 +1803,9 @@
1864 1803 }
1865 1804 }
1866 1805 } elseif ( tutor_utils()->count( $order_items ) ) {
1867 1806 $course_id = apply_filters( 'tutor_subscription_course_by_plan', $order_items[0]->id );
1868 - if ( EnrollmentModel::is_enrolled( $course_id ) ) {
1807 + if ( tutor_utils()->is_enrolled( $course_id ) ) {
1869 1808 $is_enrolled_any_course = true;
1870 1809 }
1871 1810 }
1872 1811 }
@@ -1962,30 +1901,21 @@
1962 1901 /**
1963 1902 * Retrieves statements for a specific user.
1964 1903 *
1965 1904 * @since 3.5.0
1966 - * @since 4.0.0 Added $order_by and $order option.
1967 1905 *
1968 - * @param string $post_type_in_clause Prepared SQL IN clause containing allowed course post types.
1969 - * @param string $course_query Optional SQL fragment to filter by course ID.
1970 - * @param string $date_query Optional SQL fragment to filter by statement date.
1971 - * @param int $user_id User (instructor) ID.
1972 - * @param int $offset Number of records to skip (pagination offset).
1973 - * @param int $limit Maximum number of records to return.
1974 - * @param string $order_by Column name to order results by.
1975 - * @param string $order Sort direction. Accepts 'ASC' or 'DESC'.
1906 + * @param string $post_type_in_clause SQL clause to filter the course post types.
1907 + * @param string $course_query SQL query string to further filter the courses .
1908 + * @param string $date_query SQL query string to filter by date range.
1909 + * @param int $user_id The user ID for which the statements are being retrieved.
1910 + * @param int $offset The offset for pagination.
1911 + * @param int $limit The number of rows to return.
1976 1912 *
1977 1913 * @return array
1978 1914 */
1979 - public function get_statements( $post_type_in_clause, $course_query, $date_query, $user_id, $offset, $limit, $order_by, $order ): array {
1915 + public function get_statements( $post_type_in_clause, $course_query, $date_query, $user_id, $offset, $limit ): array {
1980 1916 global $wpdb;
1981 1917
1982 - $order_clause = '';
1983 -
1984 - if ( sanitize_sql_orderby( $order ) ) {
1985 - $order_clause = "ORDER BY {$order_by} {$order}";
1986 - }
1987 -
1988 1918 //phpcs:disable
1989 1919 $statements = $wpdb->get_results(
1990 1920 $wpdb->prepare(
1991 1921 "SELECT
@@ -2005,10 +1935,11 @@
2005 1935 AND course.post_type IN ({$post_type_in_clause})
2006 1936 WHERE statements.user_id = %d
2007 1937 {$course_query}
2008 1938 {$date_query}
2009 - {$order_clause}
2010 - LIMIT %d, %d",
1939 + ORDER BY statements.created_at DESC
1940 + LIMIT %d, %d
1941 + ",
2011 1942 $user_id,
2012 1943 $offset,
2013 1944 $limit
2014 1945 )
@@ -2021,9 +1952,10 @@
2021 1952 INNER JOIN {$wpdb->posts} AS course ON course.ID = statements.course_id
2022 1953 AND course.post_type IN ({$post_type_in_clause})
2023 1954 WHERE statements.user_id = %d
2024 1955 {$course_query}
2025 - {$date_query}",
1956 + {$date_query}
1957 + ",
2026 1958 $user_id
2027 1959 )
2028 1960 );
2029 1961 //phpcs:enable
@@ -2193,9 +2125,9 @@
2193 2125 $checkout_url = add_query_arg( array( 'order_id' => $order_id ), CheckoutController::get_page_url() );
2194 2126
2195 2127 $link =
2196 2128 sprintf(
2197 - '<a href="%s" class="tutor-btn tutor-btn-link tutor-text-brand tutor-p-none tutor-min-h-fit">
2129 + '<a href="%s" class="tutor-btn tutor-btn-sm tutor-btn-outline-primary">
2198 2130 %s
2199 2131 </a>',
2200 2132 esc_url( $checkout_url ),
2201 2133 esc_html__( 'Pay', 'tutor' )
@@ -2213,37 +2145,6 @@
2213 2145 );
2214 2146 } else {
2215 2147 return $link;
2216 2148 }
2217 - }
2218 -
2219 - /**
2220 - * Get order item titles for order history display.
2221 - *
2222 - * @since 4.0.0
2223 - *
2224 - * @param object $order Order object.
2225 - *
2226 - * @return array<int, string> List of item titles.
2227 - */
2228 - public static function get_order_history_titles( $order ) {
2229 - $titles = array();
2230 - $items = ( new OrderModel() )->get_order_items_by_id( $order->id );
2231 - foreach ( $items as $item ) {
2232 -
2233 - if ( self::TYPE_SINGLE_ORDER === $order->order_type ) {
2234 - $titles[] = get_the_title( $item->id );
2235 - continue;
2236 - }
2237 -
2238 - $object_id = apply_filters( 'tutor_subscription_course_by_plan', $item->id, $order );
2239 - $plan_info = apply_filters( 'tutor_get_plan_info', null, $item->id );
2240 - if ( $plan_info && isset( $plan_info->is_membership_plan ) && $plan_info->is_membership_plan ) {
2241 - $titles[] = $plan_info->plan_name;
2242 - } else {
2243 - $titles[] = get_the_title( $object_id );
2244 - }
2245 - }
2246 -
2247 - return $titles;
2248 2149 }
2249 2150 }