summaryrefslogtreecommitdiffstats
path: root/includes/admin/views/_edit_concert_form.php
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-09-04 20:56:59 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-09-04 20:56:59 +0200
commit15bf6674a36582d2ae736bfec651239884b9cab5 (patch)
treea5170c2c432f5e5bb8005d4ad6291e0b8ca18bf8 /includes/admin/views/_edit_concert_form.php
parent38bfa49958eca679166231f46e767f229d2561a6 (diff)
downloadgigologadmin-15bf6674a36582d2ae736bfec651239884b9cab5.tar.gz
gigologadmin-15bf6674a36582d2ae736bfec651239884b9cab5.tar.bz2
gigologadmin-15bf6674a36582d2ae736bfec651239884b9cab5.zip
Move the concerts table and edit form out of AdminPage.
Currently the AdminPage is still responsible for updating changes to any of the concerts, but I'd like to get that into their respective classes too. That way the AdminPage will just be a simple class to handle the layout of the page, while all the specific functionality is in their own classes. This is also the first step to be able to reuse the concerts table on the public end of the site.
Diffstat (limited to 'includes/admin/views/_edit_concert_form.php')
-rw-r--r--includes/admin/views/_edit_concert_form.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/includes/admin/views/_edit_concert_form.php b/includes/admin/views/_edit_concert_form.php
new file mode 100644
index 0000000..32ca762
--- /dev/null
+++ b/includes/admin/views/_edit_concert_form.php
@@ -0,0 +1,82 @@
+<?php
+// SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
+// SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+if (!class_exists("GiglogAdmin_EditConcertForm"))
+{
+ class GiglogAdmin_EditConcertForm
+ {
+ private function get_venue_selector( ?GiglogAdmin_Venue $invenue ): string
+ {
+ return \EternalTerror\ViewHelpers\select_field(
+ "selectvenueadmin",
+ array_map(fn($venue) => [$venue->id(), $venue->name()], GiglogAdmin_Venue::all_venues()),
+ $invenue ? $invenue->id() : null);
+ }
+
+
+ private function user_dropdown_for_role( GiglogAdmin_Concert $concert, string $role): string
+ {
+ $users = array_map(
+ fn($usr) => $usr->user_login,
+ get_users( array( 'fields' => array( 'user_login' ) ) ) );
+
+ $roles = $concert->roles();
+
+ $current_user = array_key_exists($role, $roles) ? $roles[$role] : NULL;
+
+ return \EternalTerror\ViewHelpers\select_field(
+ $role,
+ array_map( fn($user) => [ $user, $user ], $users ),
+ $current_user);
+ }
+
+
+
+ public function render() : string
+ {
+ $cid = filter_input(INPUT_POST, "cid");
+ $editing = filter_input(INPUT_POST, "edit") == "EDIT";
+
+ 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((object)[]);
+
+ $content='<div><h3>Form to create/edit concerts and venues</h3><br></div><div class="editform"><div class="concertform">';
+ $content.='<form method="POST" action="" class="concert" >'
+ .'<div class="concertitems"><strong>CONCERT DETAILS</strong><br><br><fieldset>'
+ .'<input type="hidden" name="pid" value="' .$c->id(). '" />'
+ .'<label for="cname">Concert Name:</label><textarea id="cname" name="cname" value="'.$c->cname().'">'.$c->cname().'</textarea><br>'
+ .'<label for="venue">Venue:</label>' . $this->get_venue_selector($c->venue()) . '<br>'
+ .'<label for="cdate">Date:</label><input type="date" id="cdate" name="cdate" value="'.$c->cdate().'"><br>'
+ .'<label for="ticket">Tickets:</label><input type="text" id="ticket" name="ticket" value="'.$c->tickets().'"><br>'
+ .'<label for="eventurl">Event link:</label><input type="text" id="eventurl" name="eventurl" value="'.$c->eventlink().'"><br>'
+ .'</fieldset>';
+ // actions differ if we update or create a concert, hence two buttons needed
+ if ($editing)
+ $content.='<p><input type="submit" name="editconcert" value="Edit Concert"></p>';
+ else
+ $content.='<p><input type="submit" name="newconcert" value="Create New Concert"></p>';
+
+ $content.='</div>';
+
+ $content.='<div class="useritems"><strong>ASSIGNMENT DETAILS</strong><br><br><fieldset>'
+ .'<label for="photo1">Photo1:</label>'.$this->user_dropdown_for_role($c,'photo1').'<br>'
+ .'<label for="photo2">Photo2:</label>'.$this->user_dropdown_for_role($c,'photo2').'<br>'
+ .'<label for="rev1">Text1:</label>'.$this->user_dropdown_for_role($c,'rev1').'<br>'
+ .'<label for="rev2">Text2:</label>'.$this->user_dropdown_for_role($c,'rev2').'<br>';
+
+ $content.='<fieldset></div></form></div>';
+ $content.='<div class="venueform"><form method="POST" action="" class="venue" ><strong>VENUE DETAILS</strong><br><br>'
+ .'<fieldset><label for="venue">Venue Name:</label><input type="text" id="venuename" name="venuename"><br>'
+ .'<label for="eventurl">Venue City:</label><input type="text" id="venuecity" name="venuecity"><br>'
+ .'<p><input type="submit" name="newvenue" value="Create New Venue"></p>'
+ .'<fieldset></form></div>';
+ $content.='</div>';
+ return $content;
+ }
+ }
+}