From 74b06505888d69602b32d792ba4a815cd604ae41 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 09:15:46 +0200 Subject: Redo concert list to use the Concert class. Instead of directly accessing the database with a custom query, we now just use the Concert::find_concerts method to fetch the concerts that are to be displayed. This became much easier now that we don't rely on the extra concertlogs table. There's still stuff missing to be functionally equivalent to the old code, but this should be a lot easier to get in place now. --- includes/admin/views/giglog_admin_page.php | 70 ++++++++++++++---------------- 1 file changed, 32 insertions(+), 38 deletions(-) (limited to 'includes/admin/views/giglog_admin_page.php') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 6c1f059..5a16b66 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -115,7 +115,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { if ($editing && !empty($cid)) //A bit overdoing with the checks if concert ID is empty both here and in find_cid. But based on that, things are NULL or not. Better ideas? $c = GiglogAdmin_Concert::get($cid); else - $c = new GiglogAdmin_Concert(); + $c = new GiglogAdmin_Concert((object)[]); $content='

Form to create/edit concerts and venues


'; $content.='
' @@ -204,63 +204,58 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $content .= 'AdminOptions'; $content .= ''; + $filter = []; + // Use the submitted "city" if any. Otherwise, use the default/static value. $cty = filter_input( INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS ); - $cty = $cty ? $cty: 'ALL'; + if ($cty) $filter['city'] = $cty; $venue = filter_input( INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS ); - $venue = $venue ? $venue : '0'; + if ($venue) $filter['venue_id'] = $venue; + $concerts = GiglogAdmin_Concert::find_concerts($filter); - $query = "SELECT wpgc.id, wpgconcert_name, wpgv.wpgvenue_name as venue, wpgc.wpgconcert_date, wpgc.wpgconcert_tickets, wpgc.wpgconcert_event, wpgv.wpgvenue_city, wpgv.wpgvenue_webpage, wpgps.wpgs_name - FROM wpg_concerts wpgc, wpg_venues wpgv, wpg_pressstatus wpgps, wpg_concertlogs wpgcl - where wpgc.venue = wpgv.id - and wpgconcert_date >= CURDATE() - and wpgps.id = wpgcl.wpgcl_status - and wpgcl.wpgcl_concertid=wpgc.id"; - - $query .= ($cty == "ALL") ? "" : " and wpgv.wpgvenue_city='" .$cty ."'"; - $query .= ($venue == "0") ? "" : " and wpgv.id='" .$venue ."'"; - $query.= (empty($_POST['my_checkbox'])) ? "": " and (wpgcl_photo1 ='".$this->username."' or wpgcl_photo2 ='".$this->username."' or wpgcl_rev1 ='".$this->username."' or wpgcl_rev2 ='".$this->username."')"; - $query .=" order by wpgv.wpgvenue_city, wpgconcert_date, wpgc.id" ; - $results = $wpdb->get_results($query); $lastType = ''; - foreach ( $results AS $row ) { + foreach ( $concerts AS $concert ) { $content .= ''; - if($lastType != '' && $lastType != $row->wpgvenue_city) { - $content .= ''.$row->wpgvenue_city.''; + if ($lastType != '' && $lastType != $concert->venue()->city()) { + $content .= '' . $concert->city() . ''; } if ($lastType == '' ) { - $content .= ''.$row->wpgvenue_city.''; + $content .= '' . $concert->venue()->city() . ''; } // Modify these to match the database structure // $content .= '' . $row->id. ''; $content .= ''; - $content .= '' . $row->wpgconcert_name. ''; - $content .= '' . $row->venue. ''; - $fdate = strtotime($row->wpgconcert_date); + $content .= '' . $concert->cname() . ''; + $content .= '' . $concert->venue()->name() . ''; + $fdate = strtotime($concert->cdate()); $newformat = date('d.M.Y',$fdate); //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); - $content .= '' .$newformat. ''; - $content .= ''.$this->getpublishstatus($row->id ).''; - $content .= ''.$this->returnuser('photo1', $row->id ).''; - $content .= ''.$this->returnuser('photo2', $row->id ).''; - $content .= ''.$this->returnuser('rev1', $row->id ).''; - $content .= ''.$this->returnuser('rev2', $row->id ).''; - $content .= ''.$row -> wpgs_name.''; - - if (current_user_can('administrator')) { - $content .= - '' - . $this->adminactions($row->id) - . ''; - } + $content .= '' . $newformat . ''; + $content .= '' . /* $concert->isnew() */ '' . ''; + + $roles = $concert->roles(); + + $content .= '' . (array_key_exists('photo1', $roles) ? $roles['photo1'] : '') . ''; + $content .= '' . (array_key_exists('photo1', $roles) ? $roles['photo2'] : '') . ''; + $content .= '' . (array_key_exists('rev1', $roles) ? $roles['rev1'] : '') . ''; + $content .= '' . (array_key_exists('rev2', $roles) ? $roles['rev2'] : '') . ''; + + $content .= '' . $concert->status() . ''; + + // if (current_user_can('administrator')) { + // $content .= + // '' + // . $this->adminactions($row->id) + // . ''; + // } $content .= ''; - $lastType = $row->wpgvenue_city; + $lastType = $concert->venue()->city(); } $content .= ''; @@ -395,7 +390,6 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { return null; } - $cl = GiglogAdmin_Concertlogs::get($c); $role = $cl->get_assigned_role( $this->username ); $assigned_user = $cl->assigned_user( $p1 ); -- cgit v1.2.3