Skip to content

Commit

Permalink
Check waiting list after an event is saved. If max attendance goes up…
Browse files Browse the repository at this point in the history
…, move people from waiting list to attending.
  • Loading branch information
mauteri committed Jun 19, 2024
1 parent 1dd6e98 commit a87a67f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build/panels.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('moment', 'react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'b84b943903a5956e91f5');
<?php return array('dependencies' => array('moment', 'react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '24014ba7345244e47c2e');
2 changes: 1 addition & 1 deletion build/panels.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions includes/core/classes/class-event-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected function setup_hooks(): void {
add_action( 'init', array( $this, 'register_post_type' ) );
add_action( 'init', array( $this, 'register_post_meta' ) );
add_action( 'delete_post', array( $this, 'delete_event' ) );
add_action( sprintf( 'save_post_%s', Event::POST_TYPE ), array( $this, 'check_waiting_list' ) );
add_action(
sprintf( 'manage_%s_posts_custom_column', Event::POST_TYPE ),
array( $this, 'custom_columns' ),
Expand Down Expand Up @@ -212,6 +213,23 @@ public function register_post_meta(): void {
}
}

/**
* Checks and updates the waiting list for the given event.
*
* This function initializes an RSVP object for the given post ID
* and checks the waiting list associated with that post.
*
* @since 1.0.0
*
* @param int $post_id The ID of the post for which the waiting list should be checked.
* @return void
*/
public function check_waiting_list( int $post_id ): void {
$rsvp = new Rsvp( $post_id );

$rsvp->check_waiting_list();
}

/**
* Delete event record from custom table when an event is deleted.
*
Expand Down
6 changes: 5 additions & 1 deletion includes/core/classes/class-rsvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Rsvp {
*/
public function __construct( int $post_id ) {
$this->event = get_post( $post_id );
$this->max_attendance_limit = Settings::get_instance()->get_value( 'general', 'general', 'max_attendance_limit' );
$this->max_attendance_limit = intval( get_post_meta( $post_id, 'gatherpress_max_attendance_limit', true ) );
}

/**
Expand Down Expand Up @@ -295,6 +295,10 @@ public function attending_limit_reached( array $current_response, int $guests =
$responses = $this->responses();
$user_count = 1;

if ( empty( $this->max_attendance_limit ) ) {
return false;
}

// If the user record was previously attending adjust numbers to figure out new limit.
if ( 'attending' === $current_response['status'] ) {
$guests = $guests - intval( $current_response['guests'] );
Expand Down
2 changes: 1 addition & 1 deletion includes/core/classes/settings/class-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function get_sections(): array {
'labels' => array(
'name' => __( 'Maximum Attendance Limit', 'gatherpress' ),
),
'description' => __( 'Set this as your default, but you can still override it for each event as you like.', 'gatherpress' ),
'description' => __( 'Set this as your default, but you can still override it for each event as you like. If you set it to 0, there will not be any limit.', 'gatherpress' ),
'field' => array(
'label' => __( 'The default maximum limit of attendees to an event.', 'gatherpress' ),
'type' => 'number',
Expand Down
21 changes: 13 additions & 8 deletions src/components/MaxAttendanceLimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ const MaxAttendanceLimit = () => {
}, [isNewEvent, defaultMaxAttendanceLimit, updateMaxAttendanceLimit]);

return (
<NumberControl
label={__('Maximum Attendance Limit', 'gatherpress')}
value={maxAttendanceLimit}
min={0}
onChange={(value) => {
updateMaxAttendanceLimit(value);
}}
/>
<>
<NumberControl
label={__('Maximum Attendance Limit', 'gatherpress')}
value={maxAttendanceLimit}
min={0}
onChange={(value) => {
updateMaxAttendanceLimit(value);
}}
/>
<p className="description">
{__('A value of 0 indicates no limit.', 'gatherpress')}
</p>
</>
);
};

Expand Down

0 comments on commit a87a67f

Please sign in to comment.