Code Duplication    Length = 49-52 lines in 2 locations

core/db_models/EEM_Registration.model.php 2 locations

@@ 315-366 (lines=52) @@
312
	 * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
313
	 *                    (i.e. RAP)
314
	 */
315
	public function get_registrations_per_day_and_per_status_report( $period = '-1 month' ) {
316
		global $wpdb;
317
		$registration_table = $wpdb->prefix . 'esp_registration';
318
		$event_table = $wpdb->posts;
319
		$sql_date = date("Y-m-d H:i:s", strtotime($period) );
320
321
		//prepare the query interval for displaying offset
322
		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'dates.REG_date' );
323
324
		//inner date query
325
		$inner_date_query = "SELECT DISTINCT REG_date from $registration_table ";
326
		$inner_where = " WHERE";
327
		//exclude events not authored by user if permissions in effect
328
		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) {
329
			$inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
330
			$inner_where .= " post_author = " . get_current_user_id() . " AND";
331
		}
332
		$inner_where .= " REG_date >= '$sql_date'";
333
		$inner_date_query .= $inner_where;
334
335
		//start main query
336
		$select = "SELECT DATE($query_interval) as Registration_REG_date, ";
337
		$join = '';
338
		$join_parts = array();
339
		$select_parts = array();
340
341
		//loop through registration stati to do parts for each status.
342
		foreach ( EEM_Registration::reg_status_array() as $STS_ID => $STS_code ) {
343
			if ( $STS_ID === EEM_Registration::status_id_incomplete ) {
344
				continue;
345
			}
346
			$select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
347
			$join_parts[] = "$registration_table AS $STS_code ON $STS_code.REG_date = dates.REG_date AND $STS_code.STS_ID = '$STS_ID'";
348
		}
349
350
		//setup the selects
351
		$select .= implode(', ', $select_parts );
352
		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
353
354
		//setup the joins
355
		$join .= implode( " LEFT JOIN ", $join_parts );
356
357
		//now let's put it all together
358
		$query = $select . $join . ' GROUP BY Registration_REG_date';
359
360
		//and execute it
361
		$results = $wpdb->get_results(
362
			$query,
363
			ARRAY_A
364
		);
365
		return $results;
366
	}
367
368
369
@@ 413-461 (lines=49) @@
410
	 * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
411
	 *                    (i.e. RAP)
412
	 */
413
	public function get_registrations_per_event_and_per_status_report( $period = '-1 month' ) {
414
		global $wpdb;
415
		$registration_table = $wpdb->prefix . 'esp_registration';
416
		$event_table = $wpdb->posts;
417
		$sql_date = date("Y-m-d H:i:s", strtotime($period) );
418
419
		//inner date query
420
		$inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
421
		$inner_where = " WHERE";
422
		//exclude events not authored by user if permissions in effect
423
		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) {
424
			$inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
425
			$inner_where .= " post_author = " . get_current_user_id() . " AND";
426
		}
427
		$inner_where .= " REG_date >= '$sql_date'";
428
		$inner_date_query .= $inner_where;
429
430
		//build main query
431
		$select = "SELECT Event.post_title as Registration_Event, ";
432
		$join = '';
433
		$join_parts = array();
434
		$select_parts = array();
435
436
		//loop through registration stati to do parts for each status.
437
		foreach ( EEM_Registration::reg_status_array() as $STS_ID => $STS_code ) {
438
			if ( $STS_ID === EEM_Registration::status_id_incomplete ) {
439
				continue;
440
			}
441
			$select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
442
			$join_parts[] = "$registration_table AS $STS_code ON $STS_code.EVT_ID = dates.EVT_ID AND $STS_code.STS_ID = '$STS_ID' AND $STS_code.REG_date = dates.REG_date";
443
		}
444
445
		//setup the selects
446
		$select .= implode( ', ', $select_parts );
447
		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
448
449
		//setup remaining joins
450
		$join .= implode( " LEFT JOIN ", $join_parts );
451
452
		//now put it all together
453
		$query = $select . $join . ' GROUP BY Registration_Event';
454
455
		//and execute
456
		$results = $wpdb->get_results(
457
			$query,
458
			ARRAY_A
459
		);
460
		return $results;
461
	}
462
463
464
	/**