summaryrefslogtreecommitdiffstats
path: root/includes/class-giglogadmin-concert.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/class-giglogadmin-concert.php')
-rw-r--r--includes/class-giglogadmin-concert.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/includes/class-giglogadmin-concert.php b/includes/class-giglogadmin-concert.php
index a470617..c6223cb 100644
--- a/includes/class-giglogadmin-concert.php
+++ b/includes/class-giglogadmin-concert.php
@@ -211,6 +211,8 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) {
$where = array();
$offset = 0;
$limit = 15;
+ $page = null;
+
foreach ( $filter as $key => $value ) {
switch ( $key ) {
case 'name':
@@ -230,6 +232,10 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) {
array_push( $where, $keymap[ $key ] . $wpdb->prepare( ' like %s', esc_like( $value ) ) );
break;
+ case 'page':
+ $page = intval( $value );
+ break;
+
case 'offset':
$offset = intval( $value );
break;
@@ -244,6 +250,10 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) {
$query .= ' AND ' . implode( ' and ', $where );
}
+ if ( $page !== null ) {
+ $offset = ( $page - 1 ) * $limit;
+ }
+
$query .= ' ORDER BY wpgconcert_date';
$query .= " LIMIT {$offset},{$limit}";
@@ -290,6 +300,22 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) {
}
/**
+ * Return number of pages with the limit of concerts/page
+ * specified in the filter.
+ *
+ * @param array<string, mixed> $filter The filter to use for the query.
+ * @return number of pages.
+ */
+ public static function count_pages( array $filter = array() ) : int {
+ if ( ! isset( $filter['limit'] ) ) {
+ $filter['limit'] = 15;
+ }
+
+ $num_concerts = self::count( $filter );
+ return ( intval( $num_concerts / $filter['limit'] ) ) + 1;
+ }
+
+ /**
* Save concert to database.
*/
public function save() : void {