diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2021-09-03 19:32:28 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2021-09-03 19:32:28 +0200 |
commit | 74d39366640683914ab44db039ab48959c7dc91b (patch) | |
tree | 497a0304d40b4b7d03096b344ddffbffc94d4df8 /includes | |
parent | c9d80308ccb63a74f7dab723dd4e73a67b7fb597 (diff) | |
download | gigologadmin-74d39366640683914ab44db039ab48959c7dc91b.tar.gz gigologadmin-74d39366640683914ab44db039ab48959c7dc91b.tar.bz2 gigologadmin-74d39366640683914ab44db039ab48959c7dc91b.zip |
Editing concerts now work again.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/admin/views/giglog_admin_page.php | 32 | ||||
-rw-r--r-- | includes/concert.php | 55 |
2 files changed, 63 insertions, 24 deletions
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 4cb7dad..56376a8 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -331,15 +331,31 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { if(isset($_POST['editconcert'])) { - IF (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) - echo '<script language="javascript">alert("You are missing a value, concert was not updated"); </script>'; - else - { - GiglogAdmin_Concert::update_concert($_POST['pid'],$_POST['cname'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl']); - GiglogAdmin_Concertlogs::update($_POST['pid'],$_POST['photo1'], $_POST['photo2'], $_POST['rev1'], $_POST['rev2']); - echo '<script language="javascript">alert("Yay, concert updated"); </script>'; + $roles = array_reduce( + ['photo1', 'photo1', 'rev1', 'rev2'], + function($roles, $r) { + if (isset($_POST[$r])) { + $roles[$r] = sanitize_user($_POST[$r]); + } + return $roles; + }, + [] + ); + + $attributes = [ + 'wpgconcert_name' => sanitize_text_field($_POST['cname']), + 'venue' => intval($_POST['selectvenueadmin']), + 'wpgconcert_date' => sanitize_text_field($_POST['cdate']), + 'wpgconcert_ticket' => esc_url_raw($_POST['ticket']), + 'wpgconcert_event' => esc_url_raw($_POST['eventurl']), + 'wpgconcert_roles' => $roles, + ]; + + $concert = GiglogAdmin_Concert::get(intval($_POST['pid'])); + if ($concert->update((object) $attributes)) { + // let user know the concert was updated. + // Look into admin_notices } - } diff --git a/includes/concert.php b/includes/concert.php index d6fe7c4..f0c69c8 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -123,27 +123,50 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } - public static function update_concert($id, $cname, $venue, $cdate, $ticketlink, $eventlink) + public function update(object $attrs) : bool { - global $wpdb; + $need_update = false; - $res = $wpdb->update('wpg_concerts', array( - 'wpgconcert_name' => $cname, - 'venue' => $venue, - 'wpgconcert_date' => $cdate, - 'wpgconcert_tickets' => $ticketlink, - 'wpgconcert_event' => $eventlink - ), - array('id' => $id) - ); + if (isset($attrs->wpgconcert_name) && $attrs->wpgconcert_name != $this->cname) { + $this->cname = $attrs->wpgconcert_name; + $need_update = true; + } - if ( $res === false ) { - // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed - error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}"); - die; + if (isset($attrs->wpgconcert_date) && $attrs->wpgconcert_date != $this->cdate) { + $this->cdate = $attrs->wpgconcert_date; + $need_update = true; + } + + if (isset($attrs->wpgconcert_tickets) && $attrs->wpgconcert_tickets != $this->tickets) { + $this->tickets = $attrs->wpgconcert_tickets; + $need_update = true; + } + + if (isset($attrs->wpgconcert_event) && $attrs->wpgconcert_event != $this->eventlink) { + $this->eventling = $attrs->wpgconcert_eventlink; + $need_update = true; + } + + if (isset($attrs->wpgconcert_status) && $attrs->wpgconcert_status != $this->status) { + $this->status = $attrs->wpgconcert_status; + $need_update = true; + } + + if (isset($attrs->wpgconcert_roles) && $attrs->wpgconcert_roles != $this->roles) { + $this->roles = $attrs->wpgconcert_roles; + $need_update = true; + } + + if (isset($attrs->venue) && $attrs->venue != $this->venue()->id()) { + $this->venue = GiglogAdmin_Venue::get($attrs->venue); + $need_update = true; + } + + if ($need_update) { + $this->save(); } - return ($wpdb->last_error); + return $need_update; } public static function find($cname, $venue, $date) |