summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-05-26 21:35:28 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-05-26 21:35:28 +0200
commitb3c2e40c2ebfbfc6098495293c322140fd48250c (patch)
tree2cff26dfb3ac29aaa6111de3dec2bdab45432663
parent8e1da1f405a5f307c84e12b9a40b4a657c16c05d (diff)
downloadgigologadmin-b3c2e40c2ebfbfc6098495293c322140fd48250c.tar.gz
gigologadmin-b3c2e40c2ebfbfc6098495293c322140fd48250c.tar.bz2
gigologadmin-b3c2e40c2ebfbfc6098495293c322140fd48250c.zip
Refactor and reformat AdminPage::returnuser.
Now use a Concertlog object to render the correct subform instead of messing with the db directly.
-rw-r--r--includes/admin/views/giglog_admin_page.php49
1 files changed, 31 insertions, 18 deletions
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 ('<form class="unassignit" method="POST" action=""> <input type="hidden" name="cid" value="' . $c. '" /><input type="hidden" name="pid" value="' . $p1. '" /><input type="submit" name="unassignitem" value="Your"/></form>');
- else //check if slot is taken by another user
- if (!empty($array[$p1])) return ('<span class="takenby">Taken</span><div class="takenby">Taken by '.$array[$p1].'</div>');
- else //check if other slots for this concert are taken by user
- if (in_array($hf_username,$array)) return ('<span class="taken_by_self">-</span>');
- else //not taken by anyone
- return ('<form method="POST" action=""> <input type="hidden" name="cid" value="' . $c. '" /><input type="hidden" name="pid" value="' . $p1. '" /><input type="submit" name="assignitem" value=""/>
- </form>');
+ $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 = '<form class="unassignit" method="POST" action="">'
+ . ' <input type="hidden" name="cid" value="' . $c. '" />'
+ . ' <input type="hidden" name="pid" value="' . $p1. '" />'
+ . ' <input type="submit" name="unassignitem" value="Your"/>'
+ . '</form>';
+ }
+ elseif ( $assigned_user ) { //check if slot is taken by another user
+ $f = '<span class="takenby">Taken</span>'
+ . '<div class="takenby">Taken by ' . $assigned_user . '</div>';
+ }
+ elseif ( $role ) {
+ // other slots for this concert are taken by user
+ $f = '<span class="taken_by_self">-</span>';
+ }
+ else { //not taken by anyone
+ $f = '<form method="POST" action="">'
+ . ' <input type="hidden" name="cid" value="' . $c. '" />'
+ . ' <input type="hidden" name="pid" value="' . $p1. '" />'
+ . ' <input type="submit" name="assignitem" value=""/>'
+ . '</form>';
}
- else return ('no concert selected');
+ return $f;
}
}
}