Making WordPress.org

Changeset 13541


Ignore:
Timestamp:
04/16/2024 12:41:37 PM (21 months ago)
Author:
amieiro
Message:

Translate: Sync "Translation Events" from GitHub

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events
Files:
4 added
2 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/assets/css/translation-events.css

    r13529 r13541  
    101101}
    102102
    103 span.event-creator, span.event-you {
     103span.event-not-attending {
    104104    display: block;
    105105    margin-left: 55px;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/autoload.php

    r13529 r13541  
    1919require_once __DIR__ . '/includes/event/event-repository-cached.php';
    2020require_once __DIR__ . '/includes/event/event-form-handler.php';
    21 require_once __DIR__ . '/includes/stats-calculator.php';
    22 require_once __DIR__ . '/includes/stats-listener.php';
     21require_once __DIR__ . '/includes/stats/stats-calculator.php';
     22require_once __DIR__ . '/includes/stats/stats-importer.php';
     23require_once __DIR__ . '/includes/stats/stats-listener.php';
    2324require_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  
    120120     *
    121121     * @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
    123125     */
    124126    public function get_hosts( int $event_id ): array {
     
    128130        // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
    129131        // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
    130         $host_ids = $wpdb->get_col(
     132        $rows = $wpdb->get_results(
    131133            $wpdb->prepare(
    132134                "
    133                 select user_id
     135                select event_id, user_id
    134136                from {$gp_table_prefix}event_attendees
    135137                where event_id = %d and is_host = 1
     
    143145
    144146        $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;
    147151        }
    148152        return $hosts;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/event/event-form-handler.php

    r13529 r13541  
    1010use Wporg\TranslationEvents\Attendee\Attendee;
    1111use Wporg\TranslationEvents\Attendee\Attendee_Repository;
    12 use Wporg\TranslationEvents\Stats_Calculator;
     12use Wporg\TranslationEvents\Stats\Stats_Calculator;
    1313
    1414class Event_Form_Handler {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/event/event.php

    r13529 r13541  
    33namespace Wporg\TranslationEvents\Event;
    44
     5use DateTimeImmutable;
    56use DateTimeZone;
    67use Exception;
     
    8788    }
    8889
     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
    8999    public function timezone(): DateTimeZone {
    90100        return $this->timezone;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/event/details.php

    r13529 r13541  
    99use Wporg\TranslationEvents\Event\Event_Repository_Interface;
    1010use Wporg\TranslationEvents\Routes\Route;
    11 use Wporg\TranslationEvents\Stats_Calculator;
     11use Wporg\TranslationEvents\Stats\Stats_Calculator;
    1212use Wporg\TranslationEvents\Translation_Events;
    1313
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/event/edit.php

    r13529 r13541  
    77use Wporg\TranslationEvents\Event\Event_Repository_Interface;
    88use Wporg\TranslationEvents\Routes\Route;
    9 use Wporg\TranslationEvents\Stats_Calculator;
     9use Wporg\TranslationEvents\Stats\Stats_Calculator;
    1010use Wporg\TranslationEvents\Translation_Events;
    1111
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/user/attend-event.php

    r13529 r13541  
    77use Wporg\TranslationEvents\Event\Event_Repository_Interface;
    88use Wporg\TranslationEvents\Routes\Route;
     9use Wporg\TranslationEvents\Stats\Stats_Importer;
    910use Wporg\TranslationEvents\Translation_Events;
    1011
     
    1314 * If the user is not currently marked as attending, they will be marked as attending.
    1415 * 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.
    1519 */
    1620class Attend_Event_Route extends Route {
    1721    private Event_Repository_Interface $event_repository;
    1822    private Attendee_Repository $attendee_repository;
     23    private Stats_Importer $stats_importer;
    1924
    2025    public function __construct() {
     
    2227        $this->event_repository    = Translation_Events::get_event_repository();
    2328        $this->attendee_repository = Translation_Events::get_attendee_repository();
     29        $this->stats_importer      = new Stats_Importer();
    2430    }
    2531
     
    2935            $this->die_with_error( esc_html__( 'Only logged-in users can attend events', 'gp-translation-events' ), 403 );
    3036        }
     37        $user_id = $user->ID;
    3138
    3239        $event = $this->event_repository->get_event( $event_id );
     
    3542        }
    3643
    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 );
    4046        }
     47
     48        $attendee = $this->attendee_repository->get_attendee( $event->id(), $user_id );
    4149        if ( $attendee instanceof Attendee ) {
    42             $this->attendee_repository->remove_attendee( $event->id(), $user->ID );
     50            $this->attendee_repository->remove_attendee( $event->id(), $user_id );
    4351        } else {
    44             $attendee = new Attendee( $event->id(), $user->ID );
     52            $attendee = new Attendee( $event->id(), $user_id );
    4553            $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            }
    4660        }
    4761
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/user/host-event.php

    r13529 r13541  
    5151
    5252        $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         }
    5653        // The user is attending to the event, so if I don't find the attendee, I won't create it.
    5754        if ( $affected_attendee instanceof Attendee ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/upgrade.php

    r13529 r13541  
    66use WP_Query;
    77use Wporg\TranslationEvents\Attendee\Attendee;
     8use Wporg\TranslationEvents\Stats\Stats_Calculator;
    89
    910class Upgrade {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/templates/event.php

    r13529 r13541  
    1212use Wporg\TranslationEvents\Event\Event_End_Date;
    1313use Wporg\TranslationEvents\Event\Event_Start_Date;
     14use Wporg\TranslationEvents\Stats\Event_Stats;
     15use Wporg\TranslationEvents\Stats\Stats_Row;
    1416
    1517/** @var Attendee_Repository $attendee_repo */
     
    4648                    <?php foreach ( $contributors as $contributor ) : ?>
    4749                        <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>
    5052                            <?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>
    5254                            <?php endif; ?>
    5355                            <?php
    5456                            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"/>';
    7065                                        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>';
    7569                                    endif;
    7670                                endif;
     
    8276            </div>
    8377        <?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() ) ) ) : ?>
    8579            <div class="event-attendees">
    8680                <h2><?php esc_html_e( 'Attendees', 'gp-translation-events' ); ?></h2>
     
    8882                    <?php foreach ( $attendees as $_user ) : ?>
    8983                        <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>
    9286                            <?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>
    9488                            <?php endif; ?>
    9589                            <?php
    9690                            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"/>';
    11299                                        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>';
    117101                                    endif;
    118102                                endif;
     
    215199                                array_map(
    216200                                    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                                        }
    218205                                        return '@' . $contributor->user_login . $append_tada;
    219206                                    },
     
    225212                            'span' => array(
    226213                                'class' => array(),
     214                                'title' => array(),
    227215                            ),
    228216                        )
     
    258246                <form class="event-details-attend" method="post" action="<?php echo esc_url( gp_url( "/events/attend/$event_id" ) ); ?>">
    259247                    <?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" />
    265249                    <?php else : ?>
    266250                        <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  
    4040            <span class="event-host">
    4141                <?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;
    4448                else :
    45                     esc_html_e( 'Hosts:', 'gp-translation-events' );
     49                    esc_html_e( 'Created by:', 'gp-translation-events' );
     50                    ?>
     51                    &nbsp;<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
    4653                endif;
    4754                ?>
    4855                <?php foreach ( $hosts as $host ) : ?>
    49                     <?php $user = get_userdata( $host->user_id() ); ?>
    50                     &nbsp;<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                    &nbsp;<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>
    5157                    <?php if ( end( $hosts ) !== $host ) : ?>
    5258                        ,
     59                    <?php else : ?>
     60                        .
    5361                    <?php endif; ?>
    5462                <?php endforeach; ?>
    55             .</span>
     63            </span>
    5664            <?php $show_edit_button = ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'edit_post', $event->id() ) ) && $is_editable_event; ?>
    5765            <?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  
    77
    88use Wporg\TranslationEvents\Event\Events_Query_Result;
     9use Wporg\TranslationEvents\Stats\Stats_Calculator;
    910
    1011/** @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  
    3030use Wporg\TranslationEvents\Event\Event_Repository_Cached;
    3131use Wporg\TranslationEvents\Event\Event_Repository_Interface;
     32use Wporg\TranslationEvents\Stats\Stats_Listener;
    3233
    3334class Translation_Events {
Note: See TracChangeset for help on using the changeset viewer.