Skip to content

Commit

Permalink
you can now specify excluded days per recurrence
Browse files Browse the repository at this point in the history
  • Loading branch information
liedekef committed Jan 10, 2025
1 parent f3b08e9 commit 48332b3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
15 changes: 14 additions & 1 deletion eme-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function eme_new_event() {
'event_url' => '',
'recurrence_id' => 0,
];
// while in EME itself event_image_url can't be set when defining an event, it can be set in the frontend submit or a sync plugin
$event['event_properties'] = eme_init_event_props( );
return $event;
}
Expand Down Expand Up @@ -486,6 +485,7 @@ function eme_events_page() {
$event['event_start'] = "$event_start_date $event_start_time";
$event['event_end'] = "$event_end_date $event_end_time";
$recurrence['recurrence_freq'] = isset( $_POST['recurrence_freq'] ) ? eme_sanitize_request( $_POST['recurrence_freq'] ) : '';
$recurrence['exclude_days'] = isset( $_POST['recurrence_exclude_days'] ) ? eme_sanitize_request( $_POST['recurrence_exclude_days'] ) : '';
if ( $recurrence['recurrence_freq'] == 'specific' ) {
$recurrence['specific_days'] = isset( $_POST['recurrence_start_date'] ) ? eme_sanitize_request( $_POST['recurrence_start_date'] ) : $event_start_date;
$recurrence['recurrence_start_date'] = '';
Expand All @@ -506,6 +506,9 @@ function eme_events_page() {
if ( ! eme_are_dates_valid( $recurrence['specific_days'] ) ) {
$recurrence['specific_days'] = '';
}
if ( ! eme_are_dates_valid( $recurrence['exclude_days'] ) ) {
$recurrence['exclude_days'] = '';
}
if ( $recurrence['recurrence_freq'] == 'weekly' ) {
if ( isset( $_POST['recurrence_bydays'] ) ) {
$recurrence['recurrence_byday'] = implode( ',', eme_sanitize_request( $_POST['recurrence_bydays'] ) );
Expand Down Expand Up @@ -7308,8 +7311,18 @@ function eme_meta_box_div_recurrence_info( $recurrence, $edit_recurrence = 0 ) {
</span>
</p>
</div>
<br>
<?php esc_html_e( 'Exclude days: ', 'events-made-easy' ); ?>
<input id="rec-excludedays-to-submit" type="hidden" name="recurrence_exclude_days" value="">
<input id="localized-rec-excludedays" type="text" name="localized_recurrence_excludedays" value="" style="background: #FCFFAA;" readonly="readonly" data-multiple-dates='true' data-date='<?php echo eme_js_datetime( $recurrence['exclude_days'] ); ?>' data-alt-field='rec-excludedays-to-submit' class='eme_formfield_fdate'>
<p class="eme_smaller">
<?php
esc_html_e( 'No events will be created on excluded days.', 'events-made-easy' );
?>
</p>
<?php
if ( ! empty( $holidays_array_by_id ) ) {
echo "<br>";
esc_html_e( 'Holidays: ', 'events-made-easy' );
echo eme_ui_select( $recurrence['holidays_id'], 'holidays_id', $holidays_array_by_id );
?>
Expand Down
4 changes: 3 additions & 1 deletion eme-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// we define all db-constants here, this also means the uninstall can include this file and use it
// and doesn't need to include the main file
define( 'EME_DB_VERSION', 401 ); // increase this if the db schema changes or the options change
define( 'EME_DB_VERSION', 402 ); // increase this if the db schema changes or the options change
define( 'EME_EVENTS_TBNAME', 'eme_events' );
define( 'EME_EVENTS_CF_TBNAME', 'eme_events_cf' );
define( 'EME_RECURRENCE_TBNAME', 'eme_recurrence' );
Expand Down Expand Up @@ -555,6 +555,7 @@ function eme_create_recurrence_table( $charset, $collate, $db_version, $db_prefi
specific_days text,
specific_months varchar(256),
holidays_id mediumint(9) DEFAULT 0,
exclude_days text,
UNIQUE KEY (recurrence_id)
) $charset $collate;";
maybe_create_table( $table_name, $sql );
Expand All @@ -564,6 +565,7 @@ function eme_create_recurrence_table( $charset, $collate, $db_version, $db_prefi
eme_maybe_drop_column( $table_name, 'modif_date' );
eme_maybe_drop_column( $table_name, 'creation_date' );
maybe_add_column( $table_name, 'specific_months', "ALTER TABLE $table_name ADD specific_months varchar(256);" );
maybe_add_column( $table_name, 'exclude_days', "ALTER TABLE $table_name ADD exclude_days text;" );
maybe_add_column( $table_name, 'holidays_id', "ALTER TABLE $table_name ADD holidays_id mediumint(9) DEFAULT 0;" );
if ( $db_version < 3 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY recurrence_byday tinytext NOT NULL ;" );
Expand Down
15 changes: 11 additions & 4 deletions eme-recurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function eme_new_recurrence() {
'specific_days' => '',
'event_duration' => 1,
'holidays_id' => 0,
'exclude_days' => '',
];
return $recurrence;
}
Expand Down Expand Up @@ -66,10 +67,16 @@ function eme_get_recurrence_days( $recurrence ) {
$only_the_next_10 = 0;
}

$holidays = [];
$excluded_days = [];
if ( isset( $recurrence['holidays_id'] ) && $recurrence['holidays_id'] > 0 ) {
$holidays = eme_get_holiday_listinfo( $recurrence['holidays_id'] );
$excluded_days = eme_get_holiday_listinfo( $recurrence['holidays_id'] );
}
if (!empty($recurrence['exclude_days'])) {
$extra_excluded_days = explode( ',', $recurrence['exclude_days'] );
foreach ($extra_excluded_days as $excluded_day) {
$excluded_days[$excluded_day] = 1;
}
}

$last_week_start = [ 25, 22, 25, 24, 25, 24, 25, 25, 24, 25, 24, 25 ];
if (empty($recurrence['recurrence_byday'])) {
Expand All @@ -93,8 +100,8 @@ function eme_get_recurrence_days( $recurrence ) {
while ( $cycle_date_obj <= $end_date_obj && $occurence_counter<10 ) {
$ymd = $cycle_date_obj->getDate();

// skip holidays
if ( ! empty( $holidays ) && isset( $holidays[ $ymd ] ) ) {
// skip excluded_days
if ( ! empty( $excluded_days ) && isset( $excluded_days[ $ymd ] ) ) {
$cycle_date_obj->addOneDay();
++$daycounter;
if ( $daycounter % 7 == 0 ) {
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ See the FAQ section at the [Official site](https://www.e-dynamics.be/wordpress/)
= 2.5.31 (2025//) =
* Both the shortcodes eme_mybookings and eme_bookings now accept multiple id's in the id-param, to indicate multiple events:
[eme_bookings id="1,3,5" template_id=3 template_id_header=7 template_id_footer=9]
* Per recurrence, you can now specify excluded days (next to the holidays list), on those days no events will be created

= 2.5.30 (2025/01/05) =
* Avoid a php error triggered when planning a mailing to be sent immediately and then going in the "Scheduled actions" submenu before the first cron-period had passed
Expand Down

0 comments on commit 48332b3

Please sign in to comment.