Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recalculate new contributor #375

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/attendee/attendee-adder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private function import_stats( Event $event, Attendee $attendee ): void {
// phpcs:enable
}

private function check_is_new_contributor( Event $event, int $user_id ): bool {
public function check_is_new_contributor( Event $event, int $user_id ): bool {
global $wpdb, $gp_table_prefix;

// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
Expand Down
36 changes: 36 additions & 0 deletions includes/attendee/attendee-repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace Wporg\TranslationEvents\Attendee;

use Exception;
use Wporg\TranslationEvents\Attendee\Attendee_Adder;
use Wporg\TranslationEvents\Event\Event_Repository;
use DateTimeImmutable;
use DateTimeZone;

class Attendee_Repository {

Expand Down Expand Up @@ -47,8 +51,9 @@
$wpdb->update(
"{$gp_table_prefix}event_attendees",
array(
'is_host' => $attendee->is_host() ? 1 : 0,

Check warning on line 54 in includes/attendee/attendee-repository.php

View workflow job for this annotation

GitHub Actions / phpcs

Array double arrow not aligned correctly; expected 12 space(s) between "'is_host'" and double arrow, but found 3.
'is_remote' => $attendee->is_remote() ? 1 : 0,

Check warning on line 55 in includes/attendee/attendee-repository.php

View workflow job for this annotation

GitHub Actions / phpcs

Array double arrow not aligned correctly; expected 10 space(s) between "'is_remote'" and double arrow, but found 1.
'is_new_contributor' => $attendee->is_new_contributor() ? 1 : 0,
),
array(
'event_id' => $attendee->event_id(),
Expand Down Expand Up @@ -291,4 +296,35 @@
}
);
}

/**
* Check the attendees if they are no longer new contributors and update
*/
public function recheck_new_contributor_status( int $event_id ) {
// Get all attendees marked as new contributors.
$new_contributors = array_filter(
$this->get_attendees( $event_id ),
function ( Attendee $attendee ) {
return $attendee->is_new_contributor();
}
);

if ( empty( $new_contributors ) ) {
return;
}

$now = new DateTimeImmutable( 'now', new DateTimeZone( 'UTC' ) );

Check warning on line 316 in includes/attendee/attendee-repository.php

View workflow job for this annotation

GitHub Actions / phpcs

Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space
$attendee_adder = new Attendee_Adder( $this );
$event = ( new Event_Repository( $now, new Attendee_Repository() ) )->get_event( $event_id );

Check warning on line 318 in includes/attendee/attendee-repository.php

View workflow job for this annotation

GitHub Actions / phpcs

Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

if ( ! $event ) {
return;
}
foreach ( $new_contributors as $attendee ) {
if ( $attendee_adder->check_is_new_contributor( $event, $attendee->user_id() ) ) {
$attendee->mark_as_active_contributor();
$this->update_attendee( $attendee );
}
}
}
}
4 changes: 4 additions & 0 deletions includes/attendee/attendee.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function mark_as_new_contributor(): void {
$this->is_new_contributor = true;
}

public function mark_as_active_contributor(): void {
$this->is_new_contributor = false;
}

public function mark_as_remote_attendee(): void {
$this->is_remote = true;
}
Expand Down
Loading