Making WordPress.org


Ignore:
Timestamp:
05/09/2024 08:33:51 AM (2 years 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/attendee/attendee-repository.php

    r13541 r13683  
    44
    55use Exception;
    6 use WP_User;
    76
    87class Attendee_Repository {
     
    8382                        $wpdb->prepare(
    8483                                "
    85                                 select *
    86                                 from {$gp_table_prefix}event_attendees
     84                                select
     85                                        user_id,
     86                                        is_host,
     87                                        (
     88                                                select group_concat( distinct locale )
     89                                                from {$gp_table_prefix}event_actions
     90                                                where event_id = attendees.event_id
     91                                                  and user_id = attendees.user_id
     92                                        ) as locales
     93                                from {$gp_table_prefix}event_attendees attendees
    8794                                where event_id = %d
    8895                                  and user_id = %d
     
    100107                }
    101108
    102                 $attendee = new Attendee( $row->event_id, $row->user_id );
    103                 if ( '1' === $row->is_host ) {
    104                         $attendee->mark_as_host();
    105                 }
    106 
    107                 return $attendee;
    108         }
    109 
    110         /**
    111          * @return Attendee[] Attendees of the event.
    112          */
    113         public function get_attendees( int $event_id ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
    114                 // TODO.
    115                 return array();
    116         }
    117 
    118         /**
    119          * Get the hosts' users for an event.
    120          *
    121          * @param int $event_id The id of the event.
    122          *
    123          * @return Attendee[] The hosts of the event.
    124          * @throws Exception
    125          */
    126         public function get_hosts( int $event_id ): array {
     109                return new Attendee(
     110                        $event_id,
     111                        $row->user_id,
     112                        '1' === $row->is_host,
     113                        null === $row->locales ? array() : explode( ',', $row->locales ),
     114                );
     115        }
     116
     117        /**
     118         * Retrieve all the attendees of an event.
     119         *
     120         * @return Attendee[] Attendees of the event. Associative array with user_id as key.
     121         * @throws Exception
     122         */
     123        public function get_attendees( int $event_id ): array {
    127124                global $wpdb, $gp_table_prefix;
    128125
     
    133130                        $wpdb->prepare(
    134131                                "
    135                                 select event_id, user_id
    136                                 from {$gp_table_prefix}event_attendees
    137                                 where event_id = %d and is_host = 1
     132                                select
     133                                        user_id,
     134                                        is_host,
     135                                        (
     136                                                select group_concat( distinct locale )
     137                                                from {$gp_table_prefix}event_actions
     138                                                where event_id = attendees.event_id
     139                                                  and user_id = attendees.user_id
     140                                        ) as locales
     141                                from {$gp_table_prefix}event_attendees attendees
     142                                where event_id = %d
    138143                        ",
    139144                                array(
    140145                                        $event_id,
    141146                                )
    142                         )
    143                 );
    144                 // phpcs:enable
    145 
    146                 $hosts = array();
    147                 foreach ( $rows as $row ) {
    148                         $host = new Attendee( $row->event_id, $row->user_id );
    149                         $host->mark_as_host();
    150                         $hosts[] = $host;
    151                 }
    152                 return $hosts;
     147                        ),
     148                        OBJECT_K,
     149                );
     150                // phpcs:enable
     151
     152                return array_map(
     153                        function ( $row ) use ( $event_id ) {
     154                                return new Attendee(
     155                                        $event_id,
     156                                        $row->user_id,
     157                                        '1' === $row->is_host,
     158                                        null === $row->locales ? array() : explode( ',', $row->locales ),
     159                                );
     160                        },
     161                        $rows,
     162                );
     163        }
     164
     165        /**
     166         * Get attendees without contributions for an event.
     167         *
     168         * @param int $event_id The id of the event.
     169         *
     170         * @return Attendee[] Associative array with user_id as key.
     171         * @throws Exception
     172         */
     173        public function get_attendees_not_contributing( int $event_id ): array {
     174                return array_filter(
     175                        $this->get_attendees( $event_id ),
     176                        function ( Attendee $attendee ) {
     177                                return ! $attendee->is_contributor();
     178                        }
     179                );
     180        }
     181
     182        /**
     183         * Get the hosts' users for an event.
     184         *
     185         * @param int $event_id The id of the event.
     186         *
     187         * @return Attendee[] The hosts of the event. Associative array with user_id as key.
     188         * @throws Exception
     189         */
     190        public function get_hosts( int $event_id ): array {
     191                return array_filter(
     192                        $this->get_attendees( $event_id ),
     193                        function ( Attendee $attendee ) {
     194                                return $attendee->is_host();
     195                        }
     196                );
    153197        }
    154198
Note: See TracChangeset for help on using the changeset viewer.