Code Duplication    Length = 38-40 lines in 3 locations

caffeinated/admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 2 locations

@@ 474-511 (lines=38) @@
471
	 *
472
	 * @return string
473
	 */
474
	private function _registrations_per_day_report( $period = '-1 month' ) {
475
		$report_ID = 'reg-admin-registrations-per-day-report-dv';
476
477
		$REG = EEM_Registration::instance();
478
479
		$results = $REG->get_registrations_per_day_report( $period );
480
481
		$results = (array) $results;
482
		$regs = array();
483
		$subtitle = '';
484
485
		if( $results ) {
486
			$regs[] = array( __( 'Date (only days with registrations are shown)', 'event_espresso' ), __('Total Registrations', 'event_espresso' ) );
487
			foreach ( $results as $result ) {
488
				$regs[] = array( $result->regDate, (int) $result->total );
489
			}
490
491
			//setup the date range.
492
			EE_Registry::instance()->load_helper( 'DTT_Helper' );
493
			$beginning_date = new DateTime( "now " . $period, new DateTimeZone( EEH_DTT_Helper::get_timezone() ) );
494
			$ending_date = new DateTime( "now", new DateTimeZone( EEH_DTT_Helper::get_timezone() ) );
495
			$subtitle = sprintf( _x( 'For the period: %s to %s', 'Used to give date range', 'event_espresso' ), $beginning_date->format( 'Y-m-d' ), $ending_date->format( 'Y-m-d' ) );
496
		}
497
498
		$report_title = __( 'Total Registrations per Day', 'event_espresso' );
499
500
		$report_params = array(
501
			'title' 	=> $report_title,
502
			'subtitle' => $subtitle,
503
			'id' 		=> $report_ID,
504
			'regs' 	=> $regs,
505
			'noResults' => empty( $regs ),
506
			'noRegsMsg' => sprintf( __('%sThere are currently no registration records in the last month for this report.%s', 'event_espresso'), '<h2>' . $report_title . '</h2><p>', '</p>' ),
507
		);
508
		wp_localize_script( 'ee-reg-reports-js', 'regPerDay', $report_params );
509
510
		return $report_ID;
511
	}
512
513
514
	/**
@@ 520-557 (lines=38) @@
517
	 *
518
	 * @return string
519
	 */
520
	private function _registrations_per_event_report( $period = '-1 month' ) {
521
522
		$report_ID = 'reg-admin-registrations-per-event-report-dv';
523
524
		$REG = EEM_Registration::instance();
525
526
		$results = $REG->get_registrations_per_event_report( $period );
527
		$results = (array) $results;
528
		$regs = array();
529
		$subtitle = '';
530
531
		if ( $results ) {
532
			$regs[] = array( __( 'Event', 'event_espresso' ), __('Total Registrations', 'event_espresso' ) );
533
			foreach ( $results as $result ) {
534
				$regs[] = array( wp_trim_words( $result->event_name, 4, '...' ), (int) $result->total );
535
			}
536
537
			//setup the date range.
538
			EE_Registry::instance()->load_helper( 'DTT_Helper' );
539
			$beginning_date = new DateTime( "now " . $period, new DateTimeZone( EEH_DTT_Helper::get_timezone() ) );
540
			$ending_date = new DateTime( "now", new DateTimeZone( EEH_DTT_Helper::get_timezone() ) );
541
			$subtitle = sprintf( _x( 'For the period: %s to %s', 'Used to give date range', 'event_espresso' ), $beginning_date->format( 'Y-m-d' ), $ending_date->format( 'Y-m-d' ) );
542
		}
543
544
		$report_title = __( 'Total Registrations per Event', 'event_espresso' );
545
546
		$report_params = array(
547
			'title' 	=> $report_title,
548
			'subtitle' => $subtitle,
549
			'id' 		=> $report_ID,
550
			'regs' 	=> $regs,
551
			'noResults' => empty( $regs ),
552
			'noRegsMsg' => sprintf( __('%sThere are currently no registration records in the last month for this report.%s', 'event_espresso'), '<h2>' . $report_title . '</h2><p>', '</p>' ),
553
		);
554
		wp_localize_script( 'ee-reg-reports-js', 'regPerEvent', $report_params );
555
556
		return $report_ID;
557
	}
558
559
560

caffeinated/admin/extend/transactions/Extend_Transactions_Admin_Page.core.php 1 location

@@ 146-185 (lines=40) @@
143
	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
144
	 * @return string
145
	 */
146
	private function _revenue_per_day_report( $period = '-1 month' ) {
147
148
		$report_ID = 'txn-admin-revenue-per-day-report-dv';
149
150
		$TXN = EEM_Transaction::instance();
151
152
		$results = $TXN->get_revenue_per_day_report( $period );
153
		$results = (array) $results;
154
		$revenue = array();
155
		$subtitle = '';
156
157
		if ( $results ) {
158
			$revenue[] = array( __( 'Date (only shows dates that have a revenue greater than 1)', 'event_espresso' ), __( 'Total Revenue', 'event_espresso' ) );
159
			foreach ( $results as $result ) {
160
				if ( $result->revenue > 1 ) {
161
					$revenue[] = array( $result->txnDate, (float) $result->revenue );
162
				}
163
			}
164
165
			//setup the date range.
166
			EE_Registry::instance()->load_helper( 'DTT_Helper' );
167
			$beginning_date = new DateTime( 'now' . $period, new DateTimeZone( EEH_DTT_Helper::get_timezone() ) );
168
			$ending_date = new DateTime( 'now', new DateTimeZone( EEH_DTT_Helper::get_timezone() ) );
169
			$subtitle = sprintf( _x( 'For the period: %s to %s', 'Used to give date range', 'event_espresso' ), $beginning_date->format( 'Y-m-d' ), $ending_date->format( 'Y-m-d' ) );
170
		}
171
172
		$report_title = __( 'Total Revenue per Day' );
173
174
		$report_params = array(
175
			'title' 		=> $report_title,
176
			'subtitle' => $subtitle,
177
			'id' 			=> $report_ID,
178
			'revenue' => $revenue,
179
			'noResults' => empty( $revenue ),
180
			'noTxnMsg'	=> sprintf( __( '%sThere are currently no transaction records in the last month for this report.%s', 'event_espresso' ), '<h2>' . $report_title . '</h2><p>', '</p>' )
181
		);
182
		wp_localize_script( 'ee-txn-reports-js', 'txnRevPerDay', $report_params );
183
184
		return $report_ID;
185
	}
186
187
188