diff options
author | AndreaChirulescu <andrea.chirulescu@gmail.com> | 2021-06-15 18:34:29 +0200 |
---|---|---|
committer | AndreaChirulescu <andrea.chirulescu@gmail.com> | 2021-06-15 18:34:29 +0200 |
commit | 1a8155ea64352b0eaf088675d51547361f6f17a7 (patch) | |
tree | 7da669474e0896cefbec89a16b65413a7ed25cb1 /includes/concert.php | |
parent | bfe4eb5efd705b64943a0e1c0b7e18bfe0eee4d8 (diff) | |
parent | 82c4a8f2c4e5acd80b813829cecc40f621da3b21 (diff) | |
download | gigologadmin-1a8155ea64352b0eaf088675d51547361f6f17a7.tar.gz gigologadmin-1a8155ea64352b0eaf088675d51547361f6f17a7.tar.bz2 gigologadmin-1a8155ea64352b0eaf088675d51547361f6f17a7.zip |
Merge branch 'dev' of https://code.volse.net/wordpress/plugins/gigologadmin.git into andreaschanges
Diffstat (limited to 'includes/concert.php')
-rw-r--r-- | includes/concert.php | 131 |
1 files changed, 83 insertions, 48 deletions
diff --git a/includes/concert.php b/includes/concert.php index 050c924..88a20da 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -6,6 +6,8 @@ // SPDX-License-Identifier: AGPL-3.0-or-later if ( !class_exists('GiglogAdmin_Concert') ) { + require_once __DIR__ . '/venue.php'; + class GiglogAdmin_Concert { private $id; @@ -14,6 +16,15 @@ if ( !class_exists('GiglogAdmin_Concert') ) { private $cdate; private $tickets; private $eventlink; + private int $status; + private array $roles; + + public const STATUS_NONE = 1; + public const STATUS_ACCRED_REQ = 2; + public const STATUS_PHOTO_APPROVED = 3; + public const STATUS_TEXT_APPROVED = 4; + public const STATUS_ALL_APPROVED = 5; + public const STATUS_REJECTED = 6; /* * Constructs a new concert object from an array of attributes. @@ -28,7 +39,8 @@ if ( !class_exists('GiglogAdmin_Concert') ) { $this->cdate = isset($attrs->wpgconcert_date) ? $attrs->wpgconcert_date : NULL; $this->tickets = isset($attrs->wpgconcert_tickets) ? $attrs->wpgconcert_tickets : NULL; $this->eventlink = isset($attrs->wpgconcert_event) ? $attrs->wpgconcert_event : NULL; - + $this->status = isset($attrs->wpgconcert_status) ? $attrs->wpgconcert_status : 1; + $this->roles = isset($attrs->wpgconcert_roles) ? json_decode($attrs->wpgconcert_roles, true) : []; if ( isset( $attrs->venue ) ) { if (isset($attrs->wpgvenue_name) && isset($attrs->wpgvenue_city)) { @@ -63,6 +75,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { . 'WHERE ' . $wpdb->prepare('wpg_concerts.id = %d', $id); $results = $wpdb->get_results($query); + var_dump($results); return $results ? new GiglogAdmin_Concert($results[0]) : NULL; } @@ -126,36 +139,13 @@ if ( !class_exists('GiglogAdmin_Concert') ) { array('id' => $id) ); - if ( !$res ) { - // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed - error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}"); - die; - } - - return ($wpdb->last_error); - } - - static function update_concertlog($cid, $ph1, $ph2, $rev1, $rev2) - { - global $wpdb; - - $res = $wpdb->update('wpg_concertlogs', array( - 'wpgcl_photo1' => $ph1, - 'wpgcl_photo2' => $ph2, - 'wpgcl_rev1' => $rev1, - 'wpgcl_rev2' => $rev2 - ), - array('wpgcl_concertid' => $cid) - ); - - if ( !$res ) { + if ( $res === false ) { // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}"); die; } return ($wpdb->last_error); - } public static function find($cname, $venue, $date) @@ -171,48 +161,78 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } - public static function find_concerts_in(string $city) : array + /** + * Return an array of concert objects optionally limited by a specified + * filter. + * + * Valid filters are: + * - 'venue_id' => int : only include concerts at the given venue + * - 'city' => string : only include concerts in the given city + * + * @param array<string, mixed> $filter + * @return array<GiglogAdmin_Concert> + */ + public static function find_concerts(array $filter = []) : array { global $wpdb; $query = 'SELECT wpg_concerts.*, wpg_venues.wpgvenue_name, wpg_venues.wpgvenue_city ' . 'FROM wpg_concerts ' - . 'INNER JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id ' - . 'WHERE wpg_venues.wpgvenue_city = ' . $wpdb->prepare('%s', $city); + . 'INNER JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id '; - $results = $wpdb->get_results($query); + $where = []; - return array_map(function($c) { return new GiglogAdmin_Concert($c); }, $results); - } + if ( isset( $filter["city"] ) ) { + array_push($where, 'wpg_venues.wpgvenue_city = ' . $wpdb->prepare('%s', $filter["city"])); + } - public static function find_concerts_at(GiglogAdmin_Venue $venue) : array - { - global $wpdb; + if ( isset( $filter["venue_id"] ) ) { + array_push($where, 'wpg_venues.id = ' . $wpdb->prepare('%s', $filter["venue_id"])); + } - $query = 'SELECT wpg_concerts.*, wpg_venues.wpgvenue_name, wpg_venues.wpgvenue_city ' - . 'FROM wpg_concerts ' - . 'INNER JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id ' - . 'WHERE wpg_concerts.venue = ' . $wpdb->prepare('%d', $venue->id()); + if ( ! empty( $where ) ) { + $query .= 'WHERE ' . implode(' and ', $where); + } $results = $wpdb->get_results($query); return array_map(function($c) { return new GiglogAdmin_Concert($c); }, $results); } - public function save(): void + public function save() : void { global $wpdb; - $wpdb->insert('wpg_concerts', array( - 'id' => '', - 'wpgconcert_name' => $this->cname, - 'venue' => $this->venue->id(), - 'wpgconcert_date' => $this->cdate, - 'wpgconcert_tickets' => $this->tickets, - 'wpgconcert_event' => $this->eventlink - )); + if ( $this->id !== NULL ) { + $res = $wpdb->update('wpg_concerts', array( + 'id' => $this->id, + 'wpgconcert_name' => $this->cname, + 'venue' => $this->venue->id(), + 'wpgconcert_date' => $this->cdate, + 'wpgconcert_tickets' => $this->tickets, + 'wpgconcert_event' => $this->eventlink, + 'wpgconcert_status' => $this->status, + ), + array( 'id' => $this->id ) ); + + } + else { + $res = $wpdb->insert('wpg_concerts', array( + 'wpgconcert_name' => $this->cname, + 'venue' => $this->venue->id(), + 'wpgconcert_date' => $this->cdate, + 'wpgconcert_tickets' => $this->tickets, + 'wpgconcert_event' => $this->eventlink, + 'wpgconcert_status' => $this->status, + )); + } - $this->id = $wpdb->insert_id; + if ( $res === false ) { + $wpdb->print_error( __METHOD__ ); + } + else { + $this->id = $wpdb->insert_id; + } } public function id() @@ -240,6 +260,21 @@ if ( !class_exists('GiglogAdmin_Concert') ) { { return $this->eventlink; } + + public function status() + { + return $this->status; + } + + public function set_status( int $new_status ) + { + $this->status = $new_status; + } + + public function roles() + { + return $this->roles; + } } } ?> |