RestApi
1 year ago
abstracts
1 year ago
admin
1 year ago
blocks
1 year ago
elementor
2 years ago
export
1 year ago
fields
1 year ago
interfaces
8 years ago
libraries
3 years ago
log-handlers
4 years ago
shortcodes
1 year ago
stats
3 years ago
templates
5 years ago
class-everest-forms.php
1 year ago
class-evf-ajax.php
1 year ago
class-evf-autoloader.php
8 years ago
class-evf-background-process-import-entries.php
2 years ago
class-evf-background-updater.php
8 years ago
class-evf-cache-helper.php
6 years ago
class-evf-cron.php
2 years ago
class-evf-deprecated-action-hooks.php
6 years ago
class-evf-deprecated-filter-hooks.php
5 years ago
class-evf-emails.php
1 year ago
class-evf-fields.php
2 years ago
class-evf-form-handler.php
2 years ago
class-evf-form-task.php
1 year ago
class-evf-forms-features.php
2 years ago
class-evf-frontend-scripts.php
1 year ago
class-evf-install.php
2 years ago
class-evf-integrations.php
2 years ago
class-evf-log-levels.php
8 years ago
class-evf-logger.php
5 years ago
class-evf-post-types.php
5 years ago
class-evf-privacy.php
6 years ago
class-evf-report-cron.php
2 years ago
class-evf-reporting.php
2 years ago
class-evf-session-handler.php
7 years ago
class-evf-shortcodes.php
4 years ago
class-evf-smart-tags.php
1 year ago
class-evf-template-loader.php
2 years ago
class-evf-validation.php
6 years ago
evf-conditional-functions.php
6 years ago
evf-core-functions.php
1 year ago
evf-deprecated-functions.php
6 years ago
evf-entry-functions.php
2 years ago
evf-formatting-functions.php
4 years ago
evf-notice-functions.php
4 years ago
evf-template-functions.php
4 years ago
evf-template-hooks.php
8 years ago
evf-update-functions.php
5 years ago
class-evf-reporting.php
124 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Routine entries reporting functionality. |
| 4 | * |
| 5 | * @package EverestForms\Classes |
| 6 | * @since 2.0.9 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Reporting Class. |
| 13 | */ |
| 14 | class EVF_Reporting { |
| 15 | |
| 16 | /** |
| 17 | * Constructor. |
| 18 | * |
| 19 | * @since 2.0.9 |
| 20 | */ |
| 21 | public function __construct() { |
| 22 | add_action( 'init', array( $this, 'evf_schedule_entries_report_email' ) ); |
| 23 | add_action( 'everest_forms_settings_saved', array( $this, 'evf_cron_schedule_clearer' ) ); |
| 24 | add_action( 'everest_forms_stats_report_schedule', array( $this, 'evf_schedule_run' ), 10, 2 ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Clears the scheduled events. |
| 29 | * |
| 30 | * @since 2.0.9 |
| 31 | */ |
| 32 | public function evf_cron_schedule_clearer() { |
| 33 | $evf_report_cron = new EVF_Report_Cron(); |
| 34 | $evf_report_cron->evf_schedule_clear_all(); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Runs the scheduling events. |
| 39 | * |
| 40 | * @since 2.0.9 |
| 41 | */ |
| 42 | public function evf_schedule_run() { |
| 43 | $evf_report_cron = new EVF_Report_Cron(); |
| 44 | $evf_report_cron->evf_report_form_statistics_send(); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Schedule the entries reporting routine email. |
| 49 | * |
| 50 | * @since 2.0.9 |
| 51 | */ |
| 52 | public static function evf_schedule_entries_report_email() { |
| 53 | |
| 54 | // Clearing the existing statistics routine email this needs to be done in case the scheduling is changed). |
| 55 | $evf_report_cron = new EVF_Report_Cron(); |
| 56 | |
| 57 | // Check if the routine emailing for form entries is enabled or not. |
| 58 | $everest_forms_enable_routine_entries_reporting = get_option( 'everest_forms_enable_entries_reporting' ); |
| 59 | $everest_forms_entries_reporting_frequency = ''; |
| 60 | $everest_forms_entries_reporting_day = ''; |
| 61 | |
| 62 | if ( isset( $everest_forms_enable_routine_entries_reporting ) && 'yes' === $everest_forms_enable_routine_entries_reporting ) { |
| 63 | |
| 64 | // Get the frequency of sending the summary of routine basis. |
| 65 | $everest_forms_entries_reporting_frequency = get_option( 'everest_forms_entries_reporting_frequency' ); |
| 66 | |
| 67 | switch ( $everest_forms_entries_reporting_frequency ) { |
| 68 | |
| 69 | case 'Daily': |
| 70 | $evf_entries_report_summary_offset = '+1 day'; |
| 71 | $evf_recurrence = 'daily'; |
| 72 | break; |
| 73 | |
| 74 | case 'Weekly': |
| 75 | $everest_forms_entries_reporting_day = get_option( 'everest_forms_entries_reporting_day' ); |
| 76 | |
| 77 | switch ( $everest_forms_entries_reporting_day ) { |
| 78 | |
| 79 | case 'tuesday': |
| 80 | $evf_entries_report_summary_offset = 'next tuesday'; |
| 81 | break; |
| 82 | case 'wednesday': |
| 83 | $evf_entries_report_summary_offset = 'next wednesday'; |
| 84 | break; |
| 85 | case 'thursday': |
| 86 | $evf_entries_report_summary_offset = 'next thursday'; |
| 87 | break; |
| 88 | case 'friday': |
| 89 | $evf_entries_report_summary_offset = 'next friday'; |
| 90 | break; |
| 91 | case 'saturday': |
| 92 | $evf_entries_report_summary_offset = 'next saturday'; |
| 93 | break; |
| 94 | case 'sunday': |
| 95 | $evf_entries_report_summary_offset = 'next sunday'; |
| 96 | break; |
| 97 | default: |
| 98 | $evf_entries_report_summary_offset = 'next monday'; |
| 99 | } |
| 100 | |
| 101 | $evf_recurrence = 'weekly'; |
| 102 | break; |
| 103 | |
| 104 | case 'Monthly': |
| 105 | $evf_entries_report_summary_offset = 'first day of next month'; |
| 106 | $evf_recurrence = 'monthly'; |
| 107 | break; |
| 108 | } |
| 109 | |
| 110 | // Get midnight time of offset. |
| 111 | $evf_midnight_time_offset = gmdate( 'Y-m-d 00:00:00', strtotime( $evf_entries_report_summary_offset ) ); |
| 112 | |
| 113 | // Get UTC time of offset. |
| 114 | $evf_midnight_time_offset_utc = get_gmt_from_date( $evf_midnight_time_offset ); |
| 115 | |
| 116 | // Get next run. |
| 117 | $evf_report_next_run = strtotime( $evf_midnight_time_offset_utc . ' +6 hours' ); |
| 118 | |
| 119 | // Add to report schedule. |
| 120 | $evf_report_cron->evf_schedule_add( $evf_recurrence, $evf_report_next_run ); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 |