Skip to content

Commit

Permalink
Add new function to recheck new contributor status and mark as active…
Browse files Browse the repository at this point in the history
… if user is now an active translator
  • Loading branch information
trymebytes committed Oct 29, 2024
1 parent bfee8ed commit b61ca34
Showing 1 changed file with 36 additions and 0 deletions.
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 @@ -49,6 +53,7 @@ public function update_attendee( Attendee $attendee ): void {
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 @@ function ( Attendee $attendee ) {
}
);
}

/**
* 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 );
}
}
}
}

0 comments on commit b61ca34

Please sign in to comment.