From b3c2e40c2ebfbfc6098495293c322140fd48250c Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 26 May 2021 21:35:28 +0200 Subject: Refactor and reformat AdminPage::returnuser. Now use a Concertlog object to render the correct subform instead of messing with the db directly. --- includes/admin/views/giglog_admin_page.php | 49 +++++++++++++++++++----------- 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'includes/admin') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index bb42aa7..c1887dc 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -384,31 +384,44 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { wp_mail( $to, $subject, $body, $headers ); } - static function returnuser(string $p1, ?int $c): string + static function returnuser(string $p1, ?int $c) : ?string { - global $wpdb; $hf_user = wp_get_current_user(); $hf_username = $hf_user->user_login; + if (!$c) { + return null; + } - if (!empty($c)) - { - $sql = "select * from wpg_concertlogs where wpgcl_concertid=".$c; - $crow = $wpdb->get_results($sql); - $array = array('photo1' => $crow[0]->wpgcl_photo1, 'photo2'=> $crow[0]->wpgcl_photo2, 'rev1' => $crow[0]->wpgcl_rev1, 'rev2'=> $crow[0]->wpgcl_rev2); - - //first check if current slot is taken by current user - if ($array[$p1] == $hf_username) return ('
'); - else //check if slot is taken by another user - if (!empty($array[$p1])) return ('Taken
Taken by '.$array[$p1].'
'); - else //check if other slots for this concert are taken by user - if (in_array($hf_username,$array)) return ('-'); - else //not taken by anyone - return ('
-
'); + $cl = GiglogAdmin_Concertlogs::get($c); + $role = $cl->get_assigned_role( $hf_username ); + $assigned_user = $cl->assigned_user( $p1 ); + + //first check if current slot is taken by current user + if ( $role == $p1 ) { + $f = '
' + . ' ' + . ' ' + . ' ' + . '
'; + } + elseif ( $assigned_user ) { //check if slot is taken by another user + $f = 'Taken' + . '
Taken by ' . $assigned_user . '
'; + } + elseif ( $role ) { + // other slots for this concert are taken by user + $f = '-'; + } + else { //not taken by anyone + $f = '
' + . ' ' + . ' ' + . ' ' + . '
'; } - else return ('no concert selected'); + return $f; } } } -- cgit v1.2.3