Changeset 13683 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/event/details.php
- Timestamp:
- 05/09/2024 08:33:51 AM (19 months ago)
- 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 4 4 5 5 use Exception; 6 use GP;7 6 use Wporg\TranslationEvents\Attendee\Attendee; 8 7 use Wporg\TranslationEvents\Attendee\Attendee_Repository; 9 8 use Wporg\TranslationEvents\Event\Event_Repository_Interface; 9 use Wporg\TranslationEvents\Project\Project_Repository; 10 10 use Wporg\TranslationEvents\Routes\Route; 11 11 use Wporg\TranslationEvents\Stats\Stats_Calculator; 12 use Wporg\TranslationEvents\Translation\Translation_Repository; 12 13 use Wporg\TranslationEvents\Translation_Events; 13 14 … … 18 19 private Event_Repository_Interface $event_repository; 19 20 private Attendee_Repository $attendee_repository; 21 private Translation_Repository $translation_repository; 22 private Project_Repository $project_repository; 23 private Stats_Calculator $stats_calculator; 20 24 21 25 public function __construct() { 22 26 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(); 25 32 } 26 33 … … 36 43 } 37 44 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() ) ) { 45 46 $this->die_with_error( esc_html__( 'You are not authorized to view this page.', 'gp-translation-events' ), 403 ); 46 47 } … … 52 53 $event_end = $event->end(); 53 54 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(); 56 60 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 58 97 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() ); 65 99 } catch ( Exception $e ) { 66 100 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log … … 69 103 } 70 104 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 76 105 $this->tmpl( 'event', get_defined_vars() ); 77 106 }
Note: See TracChangeset
for help on using the changeset viewer.