Changeset 13541
- Timestamp:
- 04/16/2024 12:41:37 PM (21 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events
- Files:
-
- 4 added
- 2 deleted
- 14 edited
-
assets/css/translation-events.css (modified) (1 diff)
-
autoload.php (modified) (1 diff)
-
includes/attendee/attendee-repository.php (modified) (3 diffs)
-
includes/event/event-form-handler.php (modified) (1 diff)
-
includes/event/event.php (modified) (2 diffs)
-
includes/routes/event/details.php (modified) (1 diff)
-
includes/routes/event/edit.php (modified) (1 diff)
-
includes/routes/user/attend-event.php (modified) (5 diffs)
-
includes/routes/user/host-event.php (modified) (1 diff)
-
includes/stats (added)
-
includes/stats-calculator.php (deleted)
-
includes/stats-listener.php (deleted)
-
includes/stats/stats-calculator.php (added)
-
includes/stats/stats-importer.php (added)
-
includes/stats/stats-listener.php (added)
-
includes/upgrade.php (modified) (1 diff)
-
templates/event.php (modified) (7 diffs)
-
templates/events-header.php (modified) (1 diff)
-
templates/events-my-events.php (modified) (1 diff)
-
wporg-gp-translation-events.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/assets/css/translation-events.css
r13529 r13541 101 101 } 102 102 103 span.event- creator, span.event-you{103 span.event-not-attending { 104 104 display: block; 105 105 margin-left: 55px; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/autoload.php
r13529 r13541 19 19 require_once __DIR__ . '/includes/event/event-repository-cached.php'; 20 20 require_once __DIR__ . '/includes/event/event-form-handler.php'; 21 require_once __DIR__ . '/includes/stats-calculator.php'; 22 require_once __DIR__ . '/includes/stats-listener.php'; 21 require_once __DIR__ . '/includes/stats/stats-calculator.php'; 22 require_once __DIR__ . '/includes/stats/stats-importer.php'; 23 require_once __DIR__ . '/includes/stats/stats-listener.php'; 23 24 require_once __DIR__ . '/includes/event-text-snippet.php'; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/attendee/attendee-repository.php
r13529 r13541 120 120 * 121 121 * @param int $event_id The id of the event. 122 * @return array[Attendee] The hosts of the event. 122 * 123 * @return Attendee[] The hosts of the event. 124 * @throws Exception 123 125 */ 124 126 public function get_hosts( int $event_id ): array { … … 128 130 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery 129 131 // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching 130 $ host_ids = $wpdb->get_col(132 $rows = $wpdb->get_results( 131 133 $wpdb->prepare( 132 134 " 133 select user_id135 select event_id, user_id 134 136 from {$gp_table_prefix}event_attendees 135 137 where event_id = %d and is_host = 1 … … 143 145 144 146 $hosts = array(); 145 foreach ( $host_ids as $host_id ) { 146 $hosts[] = $this->get_attendee( $event_id, $host_id ); 147 foreach ( $rows as $row ) { 148 $host = new Attendee( $row->event_id, $row->user_id ); 149 $host->mark_as_host(); 150 $hosts[] = $host; 147 151 } 148 152 return $hosts; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/event/event-form-handler.php
r13529 r13541 10 10 use Wporg\TranslationEvents\Attendee\Attendee; 11 11 use Wporg\TranslationEvents\Attendee\Attendee_Repository; 12 use Wporg\TranslationEvents\Stats _Calculator;12 use Wporg\TranslationEvents\Stats\Stats_Calculator; 13 13 14 14 class Event_Form_Handler { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/event/event.php
r13529 r13541 3 3 namespace Wporg\TranslationEvents\Event; 4 4 5 use DateTimeImmutable; 5 6 use DateTimeZone; 6 7 use Exception; … … 87 88 } 88 89 90 public function is_active(): bool { 91 $now = new DateTimeImmutable( 'now', new DateTimeZone( 'UTC' ) ); 92 return $now >= $this->start->utc() && $now < $this->end->utc(); 93 } 94 95 public function is_past(): bool { 96 return $this->end->is_in_the_past(); 97 } 98 89 99 public function timezone(): DateTimeZone { 90 100 return $this->timezone; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/event/details.php
r13529 r13541 9 9 use Wporg\TranslationEvents\Event\Event_Repository_Interface; 10 10 use Wporg\TranslationEvents\Routes\Route; 11 use Wporg\TranslationEvents\Stats _Calculator;11 use Wporg\TranslationEvents\Stats\Stats_Calculator; 12 12 use Wporg\TranslationEvents\Translation_Events; 13 13 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/event/edit.php
r13529 r13541 7 7 use Wporg\TranslationEvents\Event\Event_Repository_Interface; 8 8 use Wporg\TranslationEvents\Routes\Route; 9 use Wporg\TranslationEvents\Stats _Calculator;9 use Wporg\TranslationEvents\Stats\Stats_Calculator; 10 10 use Wporg\TranslationEvents\Translation_Events; 11 11 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/user/attend-event.php
r13529 r13541 7 7 use Wporg\TranslationEvents\Event\Event_Repository_Interface; 8 8 use Wporg\TranslationEvents\Routes\Route; 9 use Wporg\TranslationEvents\Stats\Stats_Importer; 9 10 use Wporg\TranslationEvents\Translation_Events; 10 11 … … 13 14 * If the user is not currently marked as attending, they will be marked as attending. 14 15 * If the user is currently marked as attending, they will be marked as not attending. 16 * 17 * If the user is marked as attending, and the event is active at that moment, stats for the translations the user 18 * created since the event started are imported. 15 19 */ 16 20 class Attend_Event_Route extends Route { 17 21 private Event_Repository_Interface $event_repository; 18 22 private Attendee_Repository $attendee_repository; 23 private Stats_Importer $stats_importer; 19 24 20 25 public function __construct() { … … 22 27 $this->event_repository = Translation_Events::get_event_repository(); 23 28 $this->attendee_repository = Translation_Events::get_attendee_repository(); 29 $this->stats_importer = new Stats_Importer(); 24 30 } 25 31 … … 29 35 $this->die_with_error( esc_html__( 'Only logged-in users can attend events', 'gp-translation-events' ), 403 ); 30 36 } 37 $user_id = $user->ID; 31 38 32 39 $event = $this->event_repository->get_event( $event_id ); … … 35 42 } 36 43 37 $attendee = $this->attendee_repository->get_attendee( $event->id(), $user->ID ); 38 if ( $attendee instanceof Attendee && $attendee->is_host() && ( 1 === count( $this->attendee_repository->get_hosts( $event_id ) ) ) ) { 39 $this->die_with_error( esc_html__( 'The event needs a host. Add a new host before stopping to attend the event.', 'gp-translation-events' ), 403 ); 44 if ( $event->is_past() ) { 45 $this->die_with_error( esc_html__( 'Cannot attend or un-attend a past event', 'gp-translation-events' ), 403 ); 40 46 } 47 48 $attendee = $this->attendee_repository->get_attendee( $event->id(), $user_id ); 41 49 if ( $attendee instanceof Attendee ) { 42 $this->attendee_repository->remove_attendee( $event->id(), $user ->ID);50 $this->attendee_repository->remove_attendee( $event->id(), $user_id ); 43 51 } else { 44 $attendee = new Attendee( $event->id(), $user ->ID);52 $attendee = new Attendee( $event->id(), $user_id ); 45 53 $this->attendee_repository->insert_attendee( $attendee ); 54 55 // If the event is active right now, 56 // import stats for translations the user created since the event started. 57 if ( $event->is_active() ) { 58 $this->stats_importer->import_for_user_and_event( $user_id, $event ); 59 } 46 60 } 47 61 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/user/host-event.php
r13529 r13541 51 51 52 52 $affected_attendee = $this->attendee_repository->get_attendee( $event_id, $user_id ); 53 if ( $affected_attendee instanceof Attendee && $affected_attendee->is_host() && ( 1 === count( $this->attendee_repository->get_hosts( $event_id ) ) ) ) {54 $this->die_with_error( esc_html__( 'The event needs a host. Add a new host before stopping to attend the event.', 'gp-translation-events' ), 403 );55 }56 53 // The user is attending to the event, so if I don't find the attendee, I won't create it. 57 54 if ( $affected_attendee instanceof Attendee ) { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/upgrade.php
r13529 r13541 6 6 use WP_Query; 7 7 use Wporg\TranslationEvents\Attendee\Attendee; 8 use Wporg\TranslationEvents\Stats\Stats_Calculator; 8 9 9 10 class Upgrade { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/templates/event.php
r13529 r13541 12 12 use Wporg\TranslationEvents\Event\Event_End_Date; 13 13 use Wporg\TranslationEvents\Event\Event_Start_Date; 14 use Wporg\TranslationEvents\Stats\Event_Stats; 15 use Wporg\TranslationEvents\Stats\Stats_Row; 14 16 15 17 /** @var Attendee_Repository $attendee_repo */ … … 46 48 <?php foreach ( $contributors as $contributor ) : ?> 47 49 <li class="event-contributor" title="<?php echo esc_html( implode( ', ', $contributor->locales ) ); ?>"> 48 <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>" ><?php echo get_avatar( $contributor->ID, 48 ); ?></a>49 <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>" ><?php echo esc_html( get_the_author_meta( 'display_name', $contributor->ID ) ); ?></a>50 <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>" class="avatar"><?php echo get_avatar( $contributor->ID, 48 ); ?></a> 51 <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>" class="name"><?php echo esc_html( get_the_author_meta( 'display_name', $contributor->ID ) ); ?></a> 50 52 <?php if ( $stats_calculator->is_first_time_contributor( $event_start, $contributor->ID ) ) : ?> 51 <span class="first-time-contributor-tada" ></span>53 <span class="first-time-contributor-tada" title="<?php esc_html_e( 'New Translation Contributor', 'gp-translation-events' ); ?>"></span> 52 54 <?php endif; ?> 53 55 <?php 54 56 if ( ! $event->end()->is_in_the_past() ) : 55 if ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'manage_options' ) ) : 56 if ( $user->ID !== $contributor->ID ) : 57 $_attendee = $attendee_repo->get_attendee( $event_id, $contributor->ID ); 58 if ( $_attendee instanceof Attendee ) : 59 echo '<form class="add-remove-user-as-host" method="post" action="' . esc_url( gp_url( "/events/host/$event_id/$contributor->ID" ) ) . '">'; 60 if ( $_attendee->is_host() ) : 61 if ( 1 === count( $attendee_repo->get_hosts( $event_id ) ) ) : 62 echo '<input type="submit" class="button is-primary remove-as-host" disabled value="Remove as host"/>'; 63 else : 64 echo '<input type="submit" class="button is-primary remove-as-host" value="Remove as host"/>'; 65 endif; 66 else : 67 echo '<input type="submit" class="button is-secondary convert-to-host" value="Make co-host"/>'; 68 endif; 69 echo '</form>'; 57 if ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'manage_options' ) || $user->ID === $event->author_id() ) : 58 $_attendee = $attendee_repo->get_attendee( $event_id, $contributor->ID ); 59 if ( $_attendee instanceof Attendee ) : 60 echo '<form class="add-remove-user-as-host" method="post" action="' . esc_url( gp_url( "/events/host/$event_id/$contributor->ID" ) ) . '">'; 61 if ( $_attendee->is_host() ) : 62 echo '<input type="submit" class="button is-primary remove-as-host" value="Remove as host"/>'; 63 else : 64 echo '<input type="submit" class="button is-secondary convert-to-host" value="Make co-host"/>'; 70 65 endif; 71 elseif ( ( $attendee instanceof Attendee && $attendee->is_host() ) ) : 72 echo '<span class="event-you">' . esc_html__( 'You (host)', 'gp-translation-events' ) . '</span>'; 73 else : 74 echo '<span class="event-you">' . esc_html__( 'You (event creator)', 'gp-translation-events' ) . '</span>'; 66 echo '</form>'; 67 else : 68 echo '<span class="event-not-attending">' . esc_html__( 'Not attending', 'gp-translation-events' ) . '</span>'; 75 69 endif; 76 70 endif; … … 82 76 </div> 83 77 <?php endif; ?> 84 <?php if ( ! empty( $attendees ) && ( ! $event->end()->is_in_the_past() || ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'manage_options' ) ) ) ) : ?>78 <?php if ( ! empty( $attendees ) && ( ! $event->end()->is_in_the_past() || ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'manage_options' ) || $user->ID === $event->author_id() ) ) ) : ?> 85 79 <div class="event-attendees"> 86 80 <h2><?php esc_html_e( 'Attendees', 'gp-translation-events' ); ?></h2> … … 88 82 <?php foreach ( $attendees as $_user ) : ?> 89 83 <li class="event-attendee"> 90 <a href="<?php echo esc_url( get_author_posts_url( $_user->ID ) ); ?>" ><?php echo get_avatar( $_user->ID, 48 ); ?></a>91 <a href="<?php echo esc_url( get_author_posts_url( $_user->ID ) ); ?>" ><?php echo esc_html( get_the_author_meta( 'display_name', $_user->ID ) ); ?></a>84 <a href="<?php echo esc_url( get_author_posts_url( $_user->ID ) ); ?>" class="avatar"><?php echo get_avatar( $_user->ID, 48 ); ?></a> 85 <a href="<?php echo esc_url( get_author_posts_url( $_user->ID ) ); ?>" class="name"><?php echo esc_html( get_the_author_meta( 'display_name', $_user->ID ) ); ?></a> 92 86 <?php if ( $stats_calculator->is_first_time_contributor( $event_start, $_user->ID ) ) : ?> 93 <span class="first-time-contributor-tada" ></span>87 <span class="first-time-contributor-tada" title="<?php esc_html_e( 'New Translation Contributor', 'gp-translation-events' ); ?>"></span> 94 88 <?php endif; ?> 95 89 <?php 96 90 if ( ! $event->end()->is_in_the_past() ) : 97 if ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'manage_options' ) ) : 98 if ( $user->ID !== $_user->ID ) : 99 $_attendee = $attendee_repo->get_attendee( $event_id, $_user->ID ); 100 if ( $_attendee instanceof Attendee ) : 101 echo '<form class="add-remove-user-as-host" method="post" action="' . esc_url( gp_url( "/events/host/$event_id/$_user->ID" ) ) . '">'; 102 if ( $_attendee->is_host() ) : 103 if ( 1 === count( $attendee_repo->get_hosts( $event_id ) ) ) : 104 echo '<input type="submit" class="button is-primary remove-as-host" disabled value="Remove as host"/>'; 105 else : 106 echo '<input type="submit" class="button is-primary remove-as-host" value="Remove as host"/>'; 107 endif; 108 else : 109 echo '<input type="submit" class="button is-secondary convert-to-host" value="Make co-host"/>'; 110 endif; 111 echo '</form>'; 91 if ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'manage_options' ) || $user->ID === $event->author_id() ) : 92 $_attendee = $attendee_repo->get_attendee( $event_id, $_user->ID ); 93 if ( $_attendee instanceof Attendee ) : 94 echo '<form class="add-remove-user-as-host" method="post" action="' . esc_url( gp_url( "/events/host/$event_id/$_user->ID" ) ) . '">'; 95 if ( $_attendee->is_host() ) : 96 echo '<input type="submit" class="button is-primary remove-as-host" value="Remove as host"/>'; 97 else : 98 echo '<input type="submit" class="button is-secondary convert-to-host" value="Make co-host"/>'; 112 99 endif; 113 elseif ( ( $attendee instanceof Attendee && $attendee->is_host() ) ) : 114 echo '<span class="event-you">' . esc_html__( 'You (host)', 'gp-translation-events' ) . '</span>'; 115 else : 116 echo '<span class="event-you">' . esc_html__( 'You (event creator)', 'gp-translation-events' ) . '</span>'; 100 echo '</form>'; 117 101 endif; 118 102 endif; … … 215 199 array_map( 216 200 function ( $contributor ) use ( $stats_calculator, $event_start ) { 217 $append_tada = $stats_calculator->is_first_time_contributor( $event_start, $contributor->ID ) ? '<span class="first-time-contributor-tada"></span>' : ''; 201 $append_tada = ''; 202 if ( $stats_calculator->is_first_time_contributor( $event_start, $contributor->ID ) ) { 203 $append_tada = '<span class="first-time-contributor-tada" title="' . esc_html__( 'New Translation Contributor', 'gp-translation-events' ) . '"></span>'; 204 } 218 205 return '@' . $contributor->user_login . $append_tada; 219 206 }, … … 225 212 'span' => array( 226 213 'class' => array(), 214 'title' => array(), 227 215 ), 228 216 ) … … 258 246 <form class="event-details-attend" method="post" action="<?php echo esc_url( gp_url( "/events/attend/$event_id" ) ); ?>"> 259 247 <?php if ( $attendee instanceof Attendee ) : ?> 260 <?php if ( $attendee->is_host() && ( 1 === count( $attendee_repo->get_hosts( $event_id ) ) ) ) : ?> 261 <input type="submit" class="button is-secondary attending-btn" disabled value="You're attending" /> 262 <?php else : ?> 263 <input type="submit" class="button is-secondary attending-btn" value="You're attending" /> 264 <?php endif; ?> 248 <input type="submit" class="button is-secondary attending-btn" value="You're attending" /> 265 249 <?php else : ?> 266 250 <input type="submit" class="button is-primary attend-btn" value="Attend Event"/> -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/templates/events-header.php
r13529 r13541 40 40 <span class="event-host"> 41 41 <?php 42 if ( 1 === count( $hosts ) ) : 43 esc_html_e( 'Host:', 'gp-translation-events' ); 42 if ( count( $hosts ) > 0 ) : 43 if ( 1 === count( $hosts ) ) : 44 esc_html_e( 'Host:', 'gp-translation-events' ); 45 else : 46 esc_html_e( 'Hosts:', 'gp-translation-events' ); 47 endif; 44 48 else : 45 esc_html_e( 'Hosts:', 'gp-translation-events' ); 49 esc_html_e( 'Created by:', 'gp-translation-events' ); 50 ?> 51 <a href="<?php echo esc_attr( get_author_posts_url( $user->ID ) ); ?>"><?php echo esc_html( get_the_author_meta( 'display_name', $user->ID ) ); ?></a> 52 <?php 46 53 endif; 47 54 ?> 48 55 <?php foreach ( $hosts as $host ) : ?> 49 <?php $user = get_userdata( $host->user_id() ); ?> 50 <a href="<?php echo esc_attr( get_author_posts_url( $user->ID ) ); ?>"><?php echo esc_html( get_the_author_meta( 'display_name', $user->ID ) ); ?></a> 56 <a href="<?php echo esc_attr( get_author_posts_url( $host->user_id() ) ); ?>"><?php echo esc_html( get_the_author_meta( 'display_name', $host->user_id() ) ); ?></a> 51 57 <?php if ( end( $hosts ) !== $host ) : ?> 52 58 , 59 <?php else : ?> 60 . 53 61 <?php endif; ?> 54 62 <?php endforeach; ?> 55 .</span>63 </span> 56 64 <?php $show_edit_button = ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'edit_post', $event->id() ) ) && $is_editable_event; ?> 57 65 <?php if ( $show_edit_button ) : ?> -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/templates/events-my-events.php
r13529 r13541 7 7 8 8 use Wporg\TranslationEvents\Event\Events_Query_Result; 9 use Wporg\TranslationEvents\Stats\Stats_Calculator; 9 10 10 11 /** @var Events_Query_Result $events_i_created_query */ -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/wporg-gp-translation-events.php
r13529 r13541 30 30 use Wporg\TranslationEvents\Event\Event_Repository_Cached; 31 31 use Wporg\TranslationEvents\Event\Event_Repository_Interface; 32 use Wporg\TranslationEvents\Stats\Stats_Listener; 32 33 33 34 class Translation_Events {
Note: See TracChangeset
for help on using the changeset viewer.