Making WordPress.org


Ignore:
Timestamp:
05/09/2024 08:33:51 AM (19 months ago)
Author:
amieiro
Message:

Translate: Sync "Translation Events" from GitHub

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/event/details.php

    r13541 r13683  
    44
    55use Exception;
    6 use GP;
    76use Wporg\TranslationEvents\Attendee\Attendee;
    87use Wporg\TranslationEvents\Attendee\Attendee_Repository;
    98use Wporg\TranslationEvents\Event\Event_Repository_Interface;
     9use Wporg\TranslationEvents\Project\Project_Repository;
    1010use Wporg\TranslationEvents\Routes\Route;
    1111use Wporg\TranslationEvents\Stats\Stats_Calculator;
     12use Wporg\TranslationEvents\Translation\Translation_Repository;
    1213use Wporg\TranslationEvents\Translation_Events;
    1314
     
    1819    private Event_Repository_Interface $event_repository;
    1920    private Attendee_Repository $attendee_repository;
     21    private Translation_Repository $translation_repository;
     22    private Project_Repository $project_repository;
     23    private Stats_Calculator $stats_calculator;
    2024
    2125    public function __construct() {
    2226        parent::__construct();
    23         $this->event_repository    = Translation_Events::get_event_repository();
    24         $this->attendee_repository = Translation_Events::get_attendee_repository();
     27        $this->event_repository       = Translation_Events::get_event_repository();
     28        $this->attendee_repository    = Translation_Events::get_attendee_repository();
     29        $this->translation_repository = new Translation_Repository();
     30        $this->project_repository     = new Project_Repository();
     31        $this->stats_calculator       = new Stats_Calculator();
    2532    }
    2633
     
    3643        }
    3744
    38         /**
    39          * Filter the ability to create, edit, or delete an event.
    40          *
    41          * @param bool $can_crud_event Whether the user can create, edit, or delete an event.
    42          */
    43         $can_crud_event = apply_filters( 'gp_translation_events_can_crud_event', GP::$permission->current_user_can( 'admin' ) );
    44         if ( 'publish' !== $event->status() && ! $can_crud_event ) {
     45        if ( ! current_user_can( 'view_translation_event', $event->id() ) ) {
    4546            $this->die_with_error( esc_html__( 'You are not authorized to view this page.', 'gp-translation-events' ), 403 );
    4647        }
     
    5253        $event_end         = $event->end();
    5354
    54         $attendee          = $this->attendee_repository->get_attendee( $event->id(), $user->ID );
    55         $user_is_attending = $attendee instanceof Attendee;
     55        $projects              = $this->project_repository->get_for_event( $event->id() );
     56        $attendees             = $this->attendee_repository->get_attendees( $event->id() );
     57        $current_user_attendee = $attendees[ $user->ID ] ?? null;
     58        $user_is_attending     = $current_user_attendee instanceof Attendee;
     59        $user_is_contributor   = $user_is_attending && $current_user_attendee->is_contributor();
    5660
    57         $stats_calculator = new Stats_Calculator();
     61        $hosts = array_filter(
     62            $attendees,
     63            function ( Attendee $attendee ) {
     64                return $attendee->is_host();
     65            }
     66        );
     67
     68        $contributors = array_filter(
     69            $attendees,
     70            function ( Attendee $attendee ) {
     71                return $attendee->is_contributor();
     72            }
     73        );
     74
     75        $attendees_not_contributing = array_filter(
     76            $attendees,
     77            function ( Attendee $attendee ) {
     78                return ! $attendee->is_contributor();
     79            }
     80        );
     81
     82        $contributor_ids = array_map(
     83            function ( Attendee $contributor ) {
     84                return $contributor->user_id();
     85            },
     86            $contributors
     87        );
     88
     89        $new_contributor_ids = array();
     90        $translations_counts = $this->translation_repository->count_translations_before( $contributor_ids, $event->start() );
     91        foreach ( $translations_counts as $user_id => $count ) {
     92            if ( $count <= 10 ) {
     93                $new_contributor_ids[ $user_id ] = true;
     94            }
     95        }
     96
    5897        try {
    59             $event_stats   = $stats_calculator->for_event( $event->id() );
    60             $contributors  = $stats_calculator->get_contributors( $event->id() );
    61             $attendees     = $stats_calculator->get_attendees_not_contributing( $event->id() );
    62             $attendee_repo = $this->attendee_repository;
    63             $hosts         = $this->attendee_repository->get_hosts( $event->id() );
    64             $projects      = $stats_calculator->get_projects( $event->id() );
     98            $event_stats = $this->stats_calculator->for_event( $event->id() );
    6599        } catch ( Exception $e ) {
    66100            // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
     
    69103        }
    70104
    71         $is_editable_event = true;
    72         if ( $event_end->is_in_the_past() || $stats_calculator->event_has_stats( $event->id() ) ) {
    73             $is_editable_event = false;
    74         }
    75 
    76105        $this->tmpl( 'event', get_defined_vars() );
    77106    }
Note: See TracChangeset for help on using the changeset viewer.