summaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2023-01-29 15:40:18 +0100
committerHarald Eilertsen <haraldei@anduin.net>2023-01-29 15:40:18 +0100
commit0d7a4542ef0c0114ae9788c83df80993449b18ce (patch)
treeaf30ff17f2b0c04181a6c27ec03775affafb9e2d /includes
parent2d2fe8402a57034f92a44b4be13d3124753e0293 (diff)
downloadgigologadmin-0d7a4542ef0c0114ae9788c83df80993449b18ce.tar.gz
gigologadmin-0d7a4542ef0c0114ae9788c83df80993449b18ce.tar.bz2
gigologadmin-0d7a4542ef0c0114ae9788c83df80993449b18ce.zip
Add filters to shortcode concert table.
Diffstat (limited to 'includes')
-rw-r--r--includes/giglogadmin-shortcodes.php13
-rw-r--r--includes/templates/giglogadmin-concerts-table.php26
2 files changed, 37 insertions, 2 deletions
diff --git a/includes/giglogadmin-shortcodes.php b/includes/giglogadmin-shortcodes.php
index 053e297..8e410b2 100644
--- a/includes/giglogadmin-shortcodes.php
+++ b/includes/giglogadmin-shortcodes.php
@@ -22,11 +22,20 @@ if ( ! function_exists( 'giglogadmin_shortcode_public' ) ) {
* This shortcode does not have any attributes.
*/
function giglogadmin_shortcode_public() : string {
- $opts = array(
+ $filters = array(
'offset' => 0,
'limit' => 15,
);
- $concerts = GiglogAdmin_Concert::find_concerts( $opts );
+
+ if ( isset( $_GET['city'] ) && ! empty( $_GET['city'] ) ) {
+ $filters['city'] = sanitize_text_field( wp_unslash( $_GET['city'] ) );
+ }
+
+ if ( isset( $_GET['venue'] ) && ! empty( $_GET['venue'] ) ) {
+ $filters['venue'] = sanitize_text_field( wp_unslash( $_GET['venue'] ) );
+ }
+
+ $concerts = GiglogAdmin_Concert::find_concerts( $filters );
ob_start();
include __DIR__ . '/templates/giglogadmin-concerts-table.php';
diff --git a/includes/templates/giglogadmin-concerts-table.php b/includes/templates/giglogadmin-concerts-table.php
index f5ca911..93f5366 100644
--- a/includes/templates/giglogadmin-concerts-table.php
+++ b/includes/templates/giglogadmin-concerts-table.php
@@ -26,6 +26,32 @@
}
</style>
<div class="giglogadmin-concerts-table">
+ <details class="giglogadmin-concerts-filter">
+ <summary class="giglogadmin-concerts-filter-label">
+ Filters
+ </summary>
+ <form name="giglogadmin-filter-city" action="" method="GET">
+ <?php
+ // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
+ echo EternalTerror\ViewHelpers\select_field(
+ 'city',
+ array_map( fn( $c ) => array( $c, $c ), GiglogAdmin_Venue::all_cities() ),
+ $filters['city'] ?? null,
+ 'City'
+ );
+
+ // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
+ echo EternalTerror\ViewHelpers\select_field(
+ 'venue',
+ array_map( fn( $v ) => array( $v->name(), "{$v->name()}, {$v->city()}" ), GiglogAdmin_Venue::all_venues() ),
+ $filters['venue'] ?? null,
+ 'Venue'
+ );
+ ?>
+ <input type="submit" value="Apply!">
+ <a href="<?php echo esc_url( site_url( get_page_uri() ) ); ?>">Clear filters</a>
+ </form>
+</details>
<?php foreach ( $concerts as $concert ) { ?>
<div class="giglogadmin-concert">
<div class="giglogadmin-concert-title-row">