Skip to content

Commit e0ff8cd

Browse files
committed
$args condition change
1 parent 33fdaca commit e0ff8cd

3 files changed

Lines changed: 48 additions & 33 deletions

File tree

classes/Utils.php

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Tutor\Ecommerce\Tax;
1515
use Tutor\Cache\TutorCache;
1616
use Tutor\Models\QuizModel;
17-
use Tutor\Helpers\UrlHelper;
1817
use Tutor\Helpers\HttpHelper;
1918
use Tutor\Models\CourseModel;
2019
use Tutor\Ecommerce\Ecommerce;
@@ -4254,7 +4253,7 @@ public function get_reviews_by_user( $user_id = 0, $offset = 0, $limit = null, $
42544253
* @param int $limit limit.
42554254
* @param string $course_id course id.
42564255
* @param string $date_filter date filter.
4257-
* @param array $args Optional query arguments.
4256+
* @param array $args Optional additional WHERE conditions.
42584257
*
42594258
* @return array|null|object
42604259
*/
@@ -4271,8 +4270,12 @@ public function get_reviews_by_instructor( $instructor_id = 0, $offset = 0, $lim
42714270
$date_query = '';
42724271
$where_clause = '';
42734272

4274-
if ( ! empty( $args['where'] ) && is_array( $args['where'] ) ) {
4275-
$where_clause = count( $args['where'] ) ? ' AND ' . QueryHelper::prepare_where_clause( $args['where'] ) : '';
4273+
if ( ! empty( $args['from'] ) && ! empty( $args['to'] ) ) {
4274+
$from = Input::sanitize( $args['from'] );
4275+
$to = Input::sanitize( $args['to'] );
4276+
4277+
$where['comment_date'] = array( 'BETWEEN', array( $from, $to ) );
4278+
$where_clause = ' AND ' . QueryHelper::prepare_where_clause( $where );
42764279
}
42774280

42784281
if ( '' !== $course_id ) {
@@ -4362,11 +4365,11 @@ public function get_reviews_by_instructor( $instructor_id = 0, $offset = 0, $lim
43624365
* @since 4.0.0 Added $where Parameter.
43634366
*
43644367
* @param int $instructor_id instructor id.
4365-
* @param array $where Optional additional WHERE conditions.
4368+
* @param array $args Optional additional WHERE conditions.
43664369
*
43674370
* @return object
43684371
*/
4369-
public function get_instructor_ratings( $instructor_id, $where = array() ) {
4372+
public function get_instructor_ratings( $instructor_id, $args = array() ) {
43704373
global $wpdb;
43714374

43724375
$ratings = array(
@@ -4375,16 +4378,21 @@ public function get_instructor_ratings( $instructor_id, $where = array() ) {
43754378
'rating_avg' => 0.00,
43764379
);
43774380

4378-
// Prepare where clause.
4379-
$where_clause = QueryHelper::prepare_where_clause(
4380-
$this->sanitize_array(
4381-
$where + array(
4382-
'courses.user_id' => $instructor_id,
4383-
'courses.meta_key' => '_tutor_instructor_course_id',
4384-
)
4385-
)
4381+
$where = array(
4382+
'courses.user_id' => (int) $instructor_id,
4383+
'courses.meta_key' => '_tutor_instructor_course_id',
43864384
);
43874385

4386+
if ( ! empty( $args['from'] ) && ! empty( $args['to'] ) ) {
4387+
$from = Input::sanitize( $args['from'] );
4388+
$to = Input::sanitize( $args['to'] );
4389+
4390+
$where['reviews.comment_date'] = array( 'BETWEEN', array( $from, $to ) );
4391+
}
4392+
4393+
// Prepare where clause.
4394+
$where_clause = QueryHelper::prepare_where_clause( $where );
4395+
43884396
$rating = $wpdb->get_row(
43894397
"SELECT COUNT(rating.meta_value) as rating_count, SUM(rating.meta_value) as rating_sum
43904398
FROM {$wpdb->usermeta} courses
@@ -6257,24 +6265,24 @@ public function get_earning_statements( $user_id = 0, $filter_data = array() ) {
62576265
* @since 1.1.2
62586266
* @since 4.0.0 Condition added for different monetizations and also added $html_markup for woocommece
62596267
*
6260-
* @param int $price price.
6261-
* @param bool $html_markup Whether to include HTML markup ( Only for woocommerce as it returns html markup ).
6268+
* @param int $price price.
6269+
* @param bool $html_markup Whether to include HTML markup ( Only for woocommerce as it returns html markup ).
62626270
*
62636271
* @return int|string
62646272
*/
62656273
public function tutor_price( $price = 0, $html_markup = true ) {
62666274

62676275
$monetize_by = $this->get_option( 'monetize_by' );
6268-
6276+
62696277
if ( Ecommerce::MONETIZE_BY === $monetize_by ) {
62706278
return tutor_get_formatted_price( $price );
6271-
} elseif ( function_exists( 'wc_price' ) && 'wc' === $monetize_by ) {
6279+
} elseif ( function_exists( 'wc_price' ) && 'wc' === $monetize_by ) {
62726280
return wc_price( $price, array( 'in_span' => $html_markup ) );
62736281
} elseif ( function_exists( 'edd_currency_filter' ) && 'edd' === $monetize_by ) {
62746282
return edd_currency_filter( edd_format_amount( $price ) );
6275-
} elseif ( function_exists( 'pmpro_formatPrice' ) && 'pmpro' === $monetize_by ) {
6283+
} elseif ( function_exists( 'pmpro_formatPrice' ) && 'pmpro' === $monetize_by ) {
62766284
return pmpro_formatPrice( floatval( $price ) );
6277-
} else {
6285+
} else {
62786286
return number_format_i18n( floatval( $price ) );
62796287
}
62806288
}

models/WithdrawModel.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
namespace Tutor\Models;
1212

13+
use Tutor\Helpers\QueryHelper;
14+
use TUTOR\Input;
15+
1316
/**
1417
* WithdrawModel Class
1518
*
@@ -29,8 +32,8 @@ class WithdrawModel {
2932
* @since 2.0.7
3033
* @since 4.0.0 $args parameter added.
3134
*
32-
* @param int $instructor_id instructor id.
33-
* @param array $args Optional query.
35+
* @param int $instructor_id instructor id.
36+
* @param array $args Optional additional WHERE conditions.
3437
* @return array|object|null|void
3538
*/
3639
public static function get_withdraw_summary( $instructor_id, $args = array() ) {
@@ -39,8 +42,12 @@ public static function get_withdraw_summary( $instructor_id, $args = array() ) {
3942
$args = tutor_utils()->sanitize_array( $args );
4043
$where_clause = '';
4144

42-
if ( ! empty( $args['where'] ) ) {
43-
$where_clause = ' AND ' . $args['where'];
45+
if ( ! empty( $args['from'] ) && ! empty( $args['to'] ) ) {
46+
$from = Input::sanitize( $args['from'] );
47+
$to = Input::sanitize( $args['to'] );
48+
49+
$where['created_at'] = array( 'BETWEEN', array( $from, $to ) );
50+
$where_clause = ' AND ' . QueryHelper::prepare_where_clause( $where );
4451
}
4552

4653
$maturity_days = tutor_utils()->get_option( 'minimum_days_for_balance_to_be_available' );

templates/dashboard/instructor/home.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ function ( $carry, $section ) {
100100
$is_all_time = empty( $start_date ) && empty( $end_date );
101101
$previous_dates = $is_all_time ? array() : Instructor::get_comparison_date_range( $start_date, $end_date );
102102

103-
$date_range = fn( $from, $to, $column ) => array(
104-
$column => array( 'BETWEEN', array( $from, $to ) ),
103+
$date_range = fn( $from, $to ): array => array(
104+
'from' => $from,
105+
'to' => $to,
105106
);
106107

107108
$stat = function ( $current, $previous, $previous_dates ) {
@@ -127,7 +128,7 @@ function ( $carry, $section ) {
127128
if ( ! $is_all_time ) {
128129
$previous_period_earnings = WithdrawModel::get_withdraw_summary(
129130
$user->ID,
130-
$date_range( $previous_dates['previous_start_date'], $previous_dates['previous_end_date'], 'created_at' )
131+
$date_range( $previous_dates['previous_start_date'], $previous_dates['previous_end_date'] )
131132
)->total_income ?? 0;
132133
}
133134
}
@@ -144,14 +145,14 @@ function ( $carry, $section ) {
144145
? Instructor::get_instructor_total_students_by_date_range( $previous_dates['previous_start_date'], $previous_dates['previous_end_date'], $user->ID )
145146
: 0;
146147

148+
147149
// Total Ratings.
148-
$total_ratings_where = ! $is_all_time ? $date_range( $start_date, $end_date, 'reviews.comment_date' ) : array();
150+
$total_ratings_where = ! $is_all_time ? $date_range( $start_date, $end_date ) : array();
149151
$total_ratings = tutor_utils()->get_instructor_ratings( $user->ID, $total_ratings_where );
150152
$previous_period_ratings = ! $is_all_time
151-
? tutor_utils()->get_instructor_ratings( $user->ID, $date_range( $previous_dates['previous_start_date'], $previous_dates['previous_end_date'], 'reviews.comment_date' ) )
153+
? tutor_utils()->get_instructor_ratings( $user->ID, $date_range( $previous_dates['previous_start_date'], $previous_dates['previous_end_date'] ) )
152154
: (object) array( 'rating_avg' => 0 );
153155

154-
155156
/**
156157
* -------------------------
157158
* Hover (comparison) data
@@ -326,11 +327,10 @@ function ( $carry, $section ) {
326327
// );
327328

328329
// Recent Reviews.
329-
$review_where = array( 'comment_post_ID' => array( 'IN', $instructor_course_ids ) );
330+
$review_args = array();
330331
if ( ! $is_all_time ) {
331-
$review_where['comment_date'] = array( 'BETWEEN', array( $start_date, $end_date ) );
332+
$review_args = $date_range( $start_date, $end_date );
332333
}
333-
$review_args = array( 'where' => $review_where );
334334
$reviews = tutor_utils()->get_reviews_by_instructor( $user->ID, 0, 3, '', '', $review_args );
335335
$recent_reviews = Instructor::format_instructor_recent_reviews( $reviews->results );
336336
?>

0 commit comments

Comments
 (0)