Skip to content

Commit

Permalink
Merge pull request #15 from jawordpressorg/fix-redirec
Browse files Browse the repository at this point in the history
検索とチケットのリダイレクトを改善
  • Loading branch information
fumikito authored Feb 23, 2024
2 parents 25bc215 + 87626b0 commit b2a62fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/WCTokyo/WpCheckin/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function render_qr() {
}
$tickets = Tickets::search( $query );
if ( 1 === $tickets['total'] ) {
$url = home_url( 'checkin/' . $tickets['tickets'][0][0] );
$url = home_url( 'checkin/ticket/' . $tickets['tickets'][0][0] );
} elseif ( ! empty( $query[4] ) ) {
// Not found. Try to search with email.
$url = home_url( 'checkin/?s=' . rawurlencode( $query[4] ) );
Expand Down
22 changes: 16 additions & 6 deletions lib/WCTokyo/WpCheckin/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,22 @@ public static function search( $query = '', $page = 1 ) {
return ! $not_found;
} ) );
} elseif ( $query ) {
// This is string search.
$tickets = array_values( array_filter( self::tickets( false ), function( $ticket ) use ( $query ) {
// Flatten array.
$str = implode( '', $ticket );
return str_contains( $str, $query );
} ) );
$query = array_values( array_filter( preg_split( '/[  +]/u', $query ) ) );
$tickets = self::tickets( false );
if ( ! empty( $query ) ) {
// This is string search.
$tickets = array_values( array_filter( $tickets, function( $ticket ) use ( $query ) {
// Flatten array.
$str = implode( '', $ticket );
$matched = 0;
foreach ( $query as $q ) {
if ( str_contains( $str, $q ) ) {
$matched++;
}
}
return count( $query ) === $matched;
} ) );
}
} else {
$tickets = self::tickets( false );
}
Expand Down

0 comments on commit b2a62fe

Please sign in to comment.