Changeset 13683 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/attendee/attendee-repository.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/attendee/attendee-repository.php
r13541 r13683 4 4 5 5 use Exception; 6 use WP_User;7 6 8 7 class Attendee_Repository { … … 83 82 $wpdb->prepare( 84 83 " 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 87 94 where event_id = %d 88 95 and user_id = %d … … 100 107 } 101 108 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 { 127 124 global $wpdb, $gp_table_prefix; 128 125 … … 133 130 $wpdb->prepare( 134 131 " 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 138 143 ", 139 144 array( 140 145 $event_id, 141 146 ) 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 ); 153 197 } 154 198
Note: See TracChangeset
for help on using the changeset viewer.