Code Duplication    Length = 44-44 lines in 2 locations

includes/class-sensei-analysis-course-list-table.php 1 location

@@ 472-515 (lines=44) @@
469
	 * @since  1.7.0
470
	 * @return array statuses
471
	 */
472
	private function get_course_statuses( $args ) {
473
474
		$activity_args = array(
475
				'post_id' => $this->course_id,
476
				'type' => 'sensei_course_status',
477
				'number' => $args['number'],
478
				'offset' => $args['offset'],
479
				'orderby' => $args['orderby'],
480
				'order' => $args['order'],
481
				'status' => 'any',
482
			);
483
484
		// Searching users on statuses requires sub-selecting the statuses by user_ids
485
		if ( $this->search ) {
486
			$user_args = array(
487
				'search' => '*' . $this->search . '*',
488
				'fields' => 'ID',
489
			);
490
			// Filter for extending
491
			$user_args = apply_filters( 'sensei_analysis_course_search_users', $user_args );
492
			if ( !empty( $user_args ) ) {
493
				$learners_search = new WP_User_Query( $user_args );
494
				// Store for reuse on counts
495
				$activity_args['user_id'] = (array) $learners_search->get_results();
496
			}
497
		} // End If Statement
498
499
		$activity_args = apply_filters( 'sensei_analysis_course_filter_statuses', $activity_args );
500
501
		// WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice
502
		$this->total_items = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) );
503
504
		// Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views?
505
		if ( $this->total_items < $activity_args['offset'] ) {
506
			$new_paged = floor( $this->total_items / $activity_args['number'] );
507
			$activity_args['offset'] = $new_paged * $activity_args['number'];
508
		}
509
		$statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true );
510
		// Need to always return an array, even with only 1 item
511
		if ( !is_array($statuses) ) {
512
			$statuses = array( $statuses );
513
		}
514
		return $statuses;
515
	} // End get_course_statuses()
516
517
	/**
518
	 * Return array of Courses' lessons

includes/class-sensei-analysis-lesson-list-table.php 1 location

@@ 259-302 (lines=44) @@
256
	 * @since  1.7.0
257
	 * @return array statuses
258
	 */
259
	private function get_lesson_statuses( $args ) {
260
261
		$activity_args = array( 
262
				'post_id' => $this->lesson_id,
263
				'type' => 'sensei_lesson_status',
264
				'number' => $args['number'],
265
				'offset' => $args['offset'],
266
				'orderby' => $args['orderby'],
267
				'order' => $args['order'],
268
				'status' => 'any',
269
			);
270
271
		// Searching users on statuses requires sub-selecting the statuses by user_ids
272
		if ( $this->search ) {
273
			$user_args = array(
274
				'search' => '*' . $this->search . '*',
275
				'fields' => 'ID',
276
			);
277
			// Filter for extending
278
			$user_args = apply_filters( 'sensei_analysis_lesson_search_users', $user_args );
279
			if ( !empty( $user_args ) ) {
280
				$learners_search = new WP_User_Query( $user_args );
281
				// Store for reuse on counts
282
				$activity_args['user_id'] = (array) $learners_search->get_results();
283
			}
284
		} // End If Statement
285
286
		$activity_args = apply_filters( 'sensei_analysis_lesson_filter_statuses', $activity_args );
287
288
		// WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice
289
		$this->total_items = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) );
290
291
		// Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views?
292
		if ( $this->total_items < $activity_args['offset'] ) {
293
			$new_paged = floor( $total_statuses / $activity_args['number'] );
294
			$activity_args['offset'] = $new_paged * $activity_args['number'];
295
		}
296
		$statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true );
297
		// Need to always return an array, even with only 1 item
298
		if ( !is_array($statuses) ) {
299
			$statuses = array( $statuses );
300
		}
301
		return $statuses;
302
	} // End get_lesson_statuses()
303
304
	/**
305
	 * no_items sets output when no items are found