diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/admin/register_db_tables.php | 18 | ||||
-rw-r--r-- | includes/concert.php | 68 |
2 files changed, 73 insertions, 13 deletions
diff --git a/includes/admin/register_db_tables.php b/includes/admin/register_db_tables.php index 11223b3..64123d9 100644 --- a/includes/admin/register_db_tables.php +++ b/includes/admin/register_db_tables.php @@ -260,7 +260,7 @@ if ( !function_exists( "giglog_register_db_tables") ) function giglog_register_db_tables() { $db_version = get_option('giglogadmin_db_version'); - if ($db_version == 5) { + if ($db_version == 6) { return; } @@ -445,7 +445,21 @@ if ( !function_exists( "giglog_register_db_tables") ) "ALTER TABLE `wpg_concerts` DROP FOREIGN KEY `wpgconcert_band`;"); } - update_option("giglogadmin_db_version", 5); + if ($db_version == NULL || $db_version < 6) + { + /* + * Move status and roles from concertlogs to main concerts table + * Don't really see the value in a separate table for these items + * Also make the roles fiels a JSON field instead of separate + * fields for each role. + */ + $wpdb->query( + "ALTER TABLE `wpg_concerts` ADD COLUMN IF NOT EXISTS ( + wpgconcert_status INT DEFAULT 1, + wpgconcert_roles JSON CHECK (JSON_VALID(wpgconcert_roles)))"); + } + + update_option("giglogadmin_db_version", 6); } giglog_register_db_tables(); diff --git a/includes/concert.php b/includes/concert.php index d370de9..88a20da 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -16,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. @@ -30,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)) { @@ -65,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; } @@ -188,20 +199,40 @@ if ( !class_exists('GiglogAdmin_Concert') ) { 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() @@ -229,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; + } } } ?> |