summaryrefslogtreecommitdiffstats
path: root/includes/concert.php
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-09-01 22:01:42 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-09-01 22:01:42 +0200
commitfb8d2649e17c94458db247925b796f5ae2141b0d (patch)
tree28d7d9e9bc9cc68e715192cc6a4d1fb07900c863 /includes/concert.php
parent224f0149ea513146b164736f461e6cbba4b86add (diff)
downloadgigologadmin-fb8d2649e17c94458db247925b796f5ae2141b0d.tar.gz
gigologadmin-fb8d2649e17c94458db247925b796f5ae2141b0d.tar.bz2
gigologadmin-fb8d2649e17c94458db247925b796f5ae2141b0d.zip
Fix saving and fetching roles from Concerts table.
Diffstat (limited to 'includes/concert.php')
-rw-r--r--includes/concert.php42
1 files changed, 20 insertions, 22 deletions
diff --git a/includes/concert.php b/includes/concert.php
index db8d68a..53cd00e 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -76,7 +76,12 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
$results = $wpdb->get_results($query);
- return $results ? new GiglogAdmin_Concert($results[0]) : NULL;
+ if ( !$results ) {
+ $wpdb->print_error( __METHOD__ );
+ return null;
+ }
+
+ return new GiglogAdmin_Concert($results[0]);
}
public static function create(string $name, $venue, string $date, string $ticketlink, string $eventlink): ?self
@@ -202,34 +207,27 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
{
global $wpdb;
- 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 ) );
+ $columns = [
+ 'wpgconcert_name' => $this->cname,
+ 'venue' => $this->venue->id(),
+ 'wpgconcert_date' => $this->cdate,
+ 'wpgconcert_tickets' => $this->tickets,
+ 'wpgconcert_event' => $this->eventlink,
+ 'wpgconcert_status' => $this->status,
+ 'wpgconcert_roles' => wp_json_encode( $this->roles ),
+ ];
+ if ( $this->id !== NULL ) {
+ $res = $wpdb->update( 'wpg_concerts', $columns, [ '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,
- ));
+ $res = $wpdb->insert('wpg_concerts', $columns);
}
if ( $res === false ) {
$wpdb->print_error( __METHOD__ );
}
- else {
+ elseif ( $this->id === NULL ) {
$this->id = $wpdb->insert_id;
}
}
@@ -275,7 +273,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
return $this->roles;
}
- public function assign_role( int $role, string $username ) : void
+ public function assign_role( string $role, string $username ) : void
{
$this->roles[$role] = $username;
}