From f0c205f448b4e04c144e8fb7ef116a2a12c6dafd Mon Sep 17 00:00:00 2001 From: AndreaChirulescu Date: Sun, 5 Sep 2021 20:17:34 +0200 Subject: used is_admin() to check if user shoudl see xtra columns Re-idented the file --- includes/admin/views/_concerts_table.php | 368 +++++++++++++++---------------- 1 file changed, 184 insertions(+), 184 deletions(-) diff --git a/includes/admin/views/_concerts_table.php b/includes/admin/views/_concerts_table.php index e3c6aee..1b01d75 100644 --- a/includes/admin/views/_concerts_table.php +++ b/includes/admin/views/_concerts_table.php @@ -1,215 +1,215 @@ - -// SPDX-FileCopyrightText: 2021 Harald Eilertsen -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -if (!class_exists("GiglogAdmin_ConcertsTable")) -{ - class GiglogAdmin_ConcertsTable - { - const STATUS_LABELS = [ - '', - 'Accred Requested', - 'Photo Approved', - 'Text Approved', - 'Photo and Text Approved', - 'Rejected' - ]; - - private string $username; - - public function __construct() { - $this->username = wp_get_current_user()->user_login; - } - - public function render(): string - { - return $this->render_filters() - . $this->render_concerts_table(); - } + + // SPDX-FileCopyrightText: 2021 Harald Eilertsen + // + // SPDX-License-Identifier: AGPL-3.0-or-later - private function render_concerts_table() : string + if (!class_exists("GiglogAdmin_ConcertsTable")) + { + class GiglogAdmin_ConcertsTable { - $content = ''; - // $content .= ''; - - $content .= ''; - if(!is_user_logged_in()) - $content .= ''; + const STATUS_LABELS = [ + '', + 'Accred Requested', + 'Photo Approved', + 'Text Approved', + 'Photo and Text Approved', + 'Rejected' + ]; + + private string $username; + + public function __construct() { + $this->username = wp_get_current_user()->user_login; + } - else if(!is_page('Giglog')) - { - $content .= ''; - if (current_user_can('administrator')) - $content .= ''; - } - $content .= ''; + public function render(): string + { + return $this->render_filters() + . $this->render_concerts_table(); + } - $filter = []; + private function render_concerts_table() : string + { + $content = '
CITYIDBANDVENUEDATE
CITYNAMEVENUEDATEEVENTTICKETS PHOTO1PHOTO2TEXT1TEXT2STATUSAdminOptions
'; + // $content .= ''; - // Use the submitted "city" if any. Otherwise, use the default/static value. - $cty = filter_input( INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS ); - if ($cty) $filter['city'] = $cty; + $content .= ''; + if(!is_admin()) + $content .= ''; - $venue = filter_input( INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS ); - if ($venue) $filter['venue_id'] = $venue; + else + { + $content .= ''; + if (current_user_can('administrator')) + $content .= ''; + } + $content .= ''; - if(isset($_POST['ownconcerts']) && $_POST['ownconcerts'] == '1') - $filter['currentuser'] = wp_get_current_user()->user_login; + $filter = []; - $concerts = GiglogAdmin_Concert::find_concerts($filter); + // Use the submitted "city" if any. Otherwise, use the default/static value. + $cty = filter_input( INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS ); + if ($cty) $filter['city'] = $cty; - $lastType = ''; + $venue = filter_input( INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS ); + if ($venue) $filter['venue_id'] = $venue; - foreach ( $concerts AS $concert ) { - $content .= ''; + if(isset($_POST['ownconcerts']) && $_POST['ownconcerts'] == '1') + $filter['currentuser'] = wp_get_current_user()->user_login; - if ($lastType != '' && $lastType != $concert->venue()->city()) { - $content .= '">'; - } + $concerts = GiglogAdmin_Concert::find_concerts($filter); - if ($lastType == '' ) { - $content .= ''; - } - // Modify these to match the database structure - // $content .= ''; - // $content .= ''; - if ($lastType != '' && $lastType == $concert->venue()->city()) $content .= ''; - $content .= ''; - $content .= ''; - $fdate = strtotime($concert->cdate()); - $newformat = date('d.M.Y',$fdate); - - //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); - $content .= ''; - if(!is_user_logged_in()){ - $content .= ''; - $content .= ''; + $lastType = ''; - } - else if (!is_page('Giglog')){ - $content .= ''; + foreach ( $concerts AS $concert ) { + $content .= ''; - $content .= ''; - $content .= ''; - $content .= ''; - $content .= ''; + if ($lastType != '' && $lastType != $concert->venue()->city()) { + $content .= '">'; + } - $content .= ''; + if ($lastType == '' ) { + $content .= ''; + } + // Modify these to match the database structure + // $content .= ''; + // $content .= ''; + if ($lastType != '' && $lastType == $concert->venue()->city()) $content .= ''; + $content .= ''; + $content .= ''; + $fdate = strtotime($concert->cdate()); + $newformat = date('d.M.Y',$fdate); + + //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); + $content .= ''; + if(!is_admin()){ + $content .= ''; + $content .= ''; - if (current_user_can('administrator')) { - $content .= - ''; } + else { + $content .= ''; + + $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; + + $content .= ''; + + if (current_user_can('administrator')) { + $content .= + ''; + } + } + $content .= ''; + $lastType = $concert->venue()->city(); } - $content .= ''; - $lastType = $concert->venue()->city(); - } - $content .= '
CITYIDBANDVENUEDATE
CITYNAMEVENUEDATEEVENTTICKETS PHOTO1PHOTO2TEXT1TEXT2STATUSAdminOptions
' . $concert->venue()->city() . '' . $concert->venue()->city() . '' . $row->id. '' . $row->id. ''. $concert->cname() . '' . $concert->venue()->name() . '' . $newformat . 'LinkTickets' . $this->mark_new_concert($concert) . '
' . $this->assign_role_for_user_form('photo1', $concert) . '' . $this->assign_role_for_user_form('photo2', $concert) . '' . $this->assign_role_for_user_form('rev1', $concert) . '' . $this->assign_role_for_user_form('rev2', $concert) . '' . $concert->venue()->city() . '' . self::STATUS_LABELS[$concert->status()] . '' . $concert->venue()->city() . '' . $row->id. '' . $row->id. ''. $concert->cname() . '' . $concert->venue()->name() . '' . $newformat . 'LinkTickets' - . $this->adminactions($concert) - . '' . $this->mark_new_concert($concert) . '' . $this->assign_role_for_user_form('photo1', $concert) . '' . $this->assign_role_for_user_form('photo2', $concert) . '' . $this->assign_role_for_user_form('rev1', $concert) . '' . $this->assign_role_for_user_form('rev2', $concert) . '' . self::STATUS_LABELS[$concert->status()] . '' + . $this->adminactions($concert) + . '
'; - - // return the table - return $content; - } + $content .= ''; - private function render_filters() : string - { - $cty = filter_input(INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS); - - $select = '
FILTER DATA:'; - $select .= \EternalTerror\ViewHelpers\select_field( - "selectcity", - array_map(fn($city) => [$city, $city], GiglogAdmin_Venue::all_cities()), - $cty, - "Select city..."); - - - if ( !empty($cty) ) { - //second drop down for venue - $select .= \EternalTerror\ViewHelpers\select_field( - "selectvenue", - array_map( - fn($venue) => [$venue->id(), $venue->name()], - GiglogAdmin_Venue::venues_in_city($cty) - ), - filter_input(INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS), - "Select venue..."); + // return the table + return $content; } - if(is_user_logged_in() && !is_page('Giglog')) { - //option to select own concerts only - $select .= ''; - } - $select .= '
'; - return $select; - } + private function render_filters() : string + { + $cty = filter_input(INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS); - private function adminactions( GiglogAdmin_Concert $concert ) : string - { - return - '
' - . '' - . \EternalTerror\ViewHelpers\select_field( - 'selectstatus', - array_map(fn($i) => [ $i, self::STATUS_LABELS[$i] ], range(1, count(self::STATUS_LABELS) - 1)), - $concert->status()) - . '' - . '' - . '
'; - } + $select = '
FILTER DATA:'; + $select .= \EternalTerror\ViewHelpers\select_field( + "selectcity", + array_map(fn($city) => [$city, $city], GiglogAdmin_Venue::all_cities()), + $cty, + "Select city..."); + + + if ( !empty($cty) ) { + //second drop down for venue + $select .= \EternalTerror\ViewHelpers\select_field( + "selectvenue", + array_map( + fn($venue) => [$venue->id(), $venue->name()], + GiglogAdmin_Venue::venues_in_city($cty) + ), + filter_input(INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS), + "Select venue..."); + } + if(is_admin()) { + //option to select own concerts only + $select .= ''; + } + $select .= '
'; - /** - * Display a mark on the concert if it is new. - * I.e. imported/created within the last ten days. - * - * @return null|string - */ - private function mark_new_concert(GiglogAdmin_Concert $concert) : string - { - $now = new DateTime(); - $new_entry = $now->diff($concert->created())->days <= 10; - if ($new_entry) { - return 'NEW'; - } - else { - return ''; + return $select; } - } - private function assign_role_for_user_form(string $role, GiglogAdmin_Concert $concert) : ?string - { - $roles = $concert->roles(); - $assigned_user = array_key_exists($role, $roles) ? $roles[$role] : NULL; - - //first check if current slot is taken by current user - if ( $assigned_user == $this->username ) { - $f = '
' - . ' ' - . ' ' - . ' ' + private function adminactions( GiglogAdmin_Concert $concert ) : string + { + return + '' + . '' + . \EternalTerror\ViewHelpers\select_field( + 'selectstatus', + array_map(fn($i) => [ $i, self::STATUS_LABELS[$i] ], range(1, count(self::STATUS_LABELS) - 1)), + $concert->status()) + . '' + . '' . '
'; } - elseif ( $assigned_user ) { //check if slot is taken by another user - $f = 'Taken' - . '
Taken by ' . $assigned_user . '
'; - } - elseif ( array_search($this->username, $roles) ) { - // other slots for this concert are taken by user - $f = '-'; - } - else { //not taken by anyone - $f = '
' - . ' ' - . ' ' - . ' ' - . '
'; + + /** + * Display a mark on the concert if it is new. + * I.e. imported/created within the last ten days. + * + * @return null|string + */ + private function mark_new_concert(GiglogAdmin_Concert $concert) : string + { + $now = new DateTime(); + $new_entry = $now->diff($concert->created())->days <= 10; + if ($new_entry) { + return 'NEW'; + } + else { + return ''; + } } - return $f; + private function assign_role_for_user_form(string $role, GiglogAdmin_Concert $concert) : ?string + { + $roles = $concert->roles(); + $assigned_user = array_key_exists($role, $roles) ? $roles[$role] : NULL; + + //first check if current slot is taken by current user + if ( $assigned_user == $this->username ) { + $f = '
' + . ' ' + . ' ' + . ' ' + . '
'; + } + elseif ( $assigned_user ) { //check if slot is taken by another user + $f = 'Taken' + . '
Taken by ' . $assigned_user . '
'; + } + elseif ( array_search($this->username, $roles) ) { + // other slots for this concert are taken by user + $f = '-'; + } + else { //not taken by anyone + $f = '
' + . ' ' + . ' ' + . ' ' + . '
'; + } + + return $f; + } } } -} -- cgit v1.2.3