summaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/admin/views/_concerts_table.php299
-rw-r--r--includes/admin/views/_edit_concert_form.php2
-rw-r--r--includes/admin/views/giglog_admin_page.php2
-rw-r--r--includes/admin/views/giglog_import_gigs.php112
-rw-r--r--includes/concert.php4
5 files changed, 198 insertions, 221 deletions
diff --git a/includes/admin/views/_concerts_table.php b/includes/admin/views/_concerts_table.php
index 066e14c..091bf83 100644
--- a/includes/admin/views/_concerts_table.php
+++ b/includes/admin/views/_concerts_table.php
@@ -25,6 +25,8 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
];
private string $username;
+ private array $filter;
+ private int $page_no;
public function __construct() {
$this->username = wp_get_current_user()->user_login;
@@ -34,14 +36,12 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
public function render(): string
{
return $this->render_filters()
- . $this->render_concerts_table();
+ . $this->render_concerts_table();
}
private function render_concert_table_header() : string
{
-
-
- $content = '<div style="overflow-x:auto;"><table class="assignit">';
+ $content = '<div style="overflow-x:auto;"><table class="assignit">';
$content.= '<span style="font-size:0.8em;font-style: italic;"> Note: the iCal link will download a file with extension .ical which can be used to add the event to your calendar. For convenience, we set all events with start time at 19:00 but please check the actual event for the correct time.</span>';
$content.= '<tr class="assignithrow">';
@@ -124,101 +124,91 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
private function render_pagination() : string
{
$content =
- '<div id="pagtextbox" style="display:flex">'
- . '<span class="alignleft" style="text-align:left;flex:auto;">';
+ '<div id="pagtextbox" style="display:flex">'
+ . '<span class="alignleft" style="text-align:left;flex:auto;">';
if($this->page_no > 1) {
$content .=
- '<span>'
- . '<a href="'. add_query_arg( 'page_no', 1 ) . '">'
- . 'First Page</a> -'
- . '</span>'
- . '<span>'
- . '<a href="' . add_query_arg( 'page_no', $this->previous_page ) . '">'
- . ' Previous</a></span>';
+ '<span>'
+ . '<a href="'. add_query_arg( 'page_no', 1 ) . '">'
+ . 'First Page</a> -'
+ . '</span>'
+ . '<span>'
+ . '<a href="' . add_query_arg( 'page_no', $this->previous_page ) . '">'
+ . ' Previous</a></span>';
}
$content .= '</span>'
- . '<span class="aligncenter" style="text-align:center;flex:auto">'
- . '<strong>Page ' . $this->page_no . ' of ' . $this->total_no_of_pages . '</strong>'
- . '</span>';
+ . '<span class="aligncenter" style="text-align:center;flex:auto">'
+ . '<strong>Page ' . $this->page_no . ' of ' . $this->total_no_of_pages . '</strong>'
+ . '</span>';
$content .= '<span class="alignright" style="text-align:right;flex:auto;float:none">';
if ($this->page_no < $this->total_no_of_pages) {
$content .=
- '<span>'
- . '<a href="' . add_query_arg( 'page_no', $this->next_page ) . '">'
- . 'Next</a> - '
- . '</span>'
- . '<span>'
- . '<a href="' . add_query_arg( 'page_no', $this->total_no_of_pages ) .'">'
- . 'Last Page</a>'
- . '</span>';
+ '<span>'
+ . '<a href="' . add_query_arg( 'page_no', $this->next_page ) . '">'
+ . 'Next</a> - '
+ . '</span>'
+ . '<span>'
+ . '<a href="' . add_query_arg( 'page_no', $this->total_no_of_pages ) .'">'
+ . 'Last Page</a>'
+ . '</span>';
}
$content .=
- '</span>'
- . '</div>';
+ '</span>'
+ . '</div>';
return $content;
}
private function render_concerts_table() : string
{
- //pagination. Change value as needed
-
$concerts = $this->get_concerts();
- $lastType = '';
+ $last_city = '';
$content = $this->render_concert_table_header();
- foreach ( $concerts AS $concert ) {
- $content .= '<tr class="assignitr">';
+ foreach ( $concerts as $concert ) {
+ $content .= '<tr class="assignitr"><td>';
- if ($lastType != '' && $lastType != $concert->venue()->city()) {
- $content .= '<td>' . $concert->venue()->city() . '</td>';
+ if ($last_city != $concert->venue()->city()) {
+ $content .= $concert->venue()->city();
}
- if ($lastType == '' ) {
- $content .= '<td>' . $concert->venue()->city() . '</td>';
- }
-
- if ($lastType != '' && $lastType == $concert->venue()->city()) {
- $content .= '<td></td>';
- }
+ $content .= '</td>';
- $fdate = strtotime($concert->cdate());
- $newformat = date('d.M.Y',$fdate);
- //$content .= DATE_FORMAT($fdate,'%d.%b.%Y');
- $content .= '<td>' . $newformat . '</td>';
- $content .= '<td>'. $concert->cname() . '</td>';
- $content .= '<td>' . $concert->venue()->name() . '</td>';
- if(!is_admin()){
- $content .= '<td><a target="_blank" href="'.$concert->eventlink() .'">Link</a></td>';
- $content .= '<td><a target="_blank" href="'.$concert->tickets() .'">Tickets</a></td>';
+ $content .=
+ "<td>" . date( 'd.M.Y', strtotime( $concert->cdate() ) ) . "</td>"
+ . "<td>{$concert->cname()}</td>"
+ . "<td>{$concert->venue()->name()}</td>";
- }
- else {
+ if( is_admin() ) {
$content .= '<td class="publishstatus">' . $this->mark_new_concert($concert) . '</td>';
- $content .= '<td class="assigneduser">' . $this->assign_role_for_user_form('photo1', $concert) . '</td>';
- $content .= '<td class="assigneduser">' . $this->assign_role_for_user_form('photo2', $concert) . '</td>';
- $content .= '<td class="assigneduser">' . $this->assign_role_for_user_form('rev1', $concert) . '</td>';
- $content .= '<td class="assigneduser">' . $this->assign_role_for_user_form('rev2', $concert) . '</td>';
+ foreach ( [ 'photo1', 'photo2', 'rev1', 'rev2' ] as $role ) {
+ $content .= '<td class="assigneduser">'
+ . $this->assign_role_for_user_form( $role, $concert )
+ . '</td>';
+ }
$content .= '<td>' . self::STATUS_LABELS[$concert->status()] . '</td>';
if (current_user_can('administrator')) {
- $content .= '<td class="adminbuttons">'
- . $this->adminactions($concert)
- . '</td>';
+ $content .= "<td class=\"adminbuttons\">{$this->adminactions( $concert )}</td>";
}
}
+ else {
+ $content .= "<td><a target=\"_blank\" href=\"{$concert->eventlink()}\">Link</a></td>";
+ $content .= "<td><a target=\"_blank\" href=\"{$concert->tickets()}\">Tickets</a></td>";
+ }
+
$content .= '<td> <a href="'.get_admin_url().'admin-ajax.php?action=giglog_export_ical&evid='.$concert->id().'">iCal</td>';
$content .= '</tr>';
- $lastType = $concert->venue()->city();
+ $last_city = $concert->venue()->city();
}
$content .= '</table>';
@@ -244,7 +234,7 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
}
$select .= '<input type="hidden" name="' . esc_attr( $name )
- . '" value="' . esc_attr( $val ) . '">';
+ . '" value="' . esc_attr( $val ) . '">';
}
$cty = $this->get_filter('city');
@@ -255,105 +245,104 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
$cty,
"Select city...");
+ if ( !empty($cty) ) {
+ //second drop down for venue
+ $select .= \EternalTerror\ViewHelpers\select_field(
+ "venue",
+ array_map(
+ fn($venue) => [$venue->id(), $venue->name()],
+ GiglogAdmin_Venue::venues_in_city($cty)
+ ),
+ $this->get_filter('venue_id'),
+ "Select venue...");
+ }
- if ( !empty($cty) ) {
- //second drop down for venue
- $select .= \EternalTerror\ViewHelpers\select_field(
- "venue",
- array_map(
- fn($venue) => [$venue->id(), $venue->name()],
- GiglogAdmin_Venue::venues_in_city($cty)
- ),
- $this->get_filter('venue_id'),
- "Select venue...");
- }
+ $select .= \EternalTerror\ViewHelpers\select_field(
+ "month",
+ array_map(
+ fn($m) => [ $m, $wp_locale->get_month( $m ) ],
+ range( 1, 12 )
+ ),
+ $this->get_filter('month'),
+ "Select month...");
+
+ $select.='</select>';
+
+ if(is_admin()) {
+ //option to select own concerts only
+ $select .= '<input name="only_mine" class="ownconc" type="checkbox" value="1"'
+ . checked( $this->get_filter( 'current_user' ) )
+ . '><label for="ownconcerts">Show own concerts only</label>';
- $select .= \EternalTerror\ViewHelpers\select_field(
- "month",
- array_map(
- fn($m) => [ $m, $wp_locale->get_month( $m ) ],
- range( 1, 12 )
- ),
- $this->get_filter('month'),
- "Select month...");
+ }
+ //NOTE that I remvoed </form></p> and mvoed them up to render_concerts_table function
+ $select .= '<input class="applybutton" type="submit" value="Apply Filters">';
- $select.='</select>';
+ return $select;
+ }
- if(is_admin()) {
- //option to select own concerts only
- $select .= '<input name="only_mine" class="ownconc" type="checkbox" value="1"'
- . checked( $this->get_filter( 'current_user' ) )
- . '><label for="ownconcerts">Show own concerts only</label>';
+ private function adminactions( GiglogAdmin_Concert $concert ) : string
+ {
+ return
+ '<form class="adminactions" method="POST" action="">'
+ . '<input type="hidden" name="cid" value="' . $concert->id() . '" />'
+ . \EternalTerror\ViewHelpers\select_field(
+ 'selectstatus',
+ array_map(fn($i) => [ $i, self::STATUS_LABELS[$i] ], range(1, count(self::STATUS_LABELS) - 1)),
+ $concert->status())
+ . '<input type="submit" value="SetStatus">'
+ . '<input type="submit" name ="edit" value="EDIT">'
+ . '</form>';
+ }
- }
- //NOTE that I remvoed </form></p> and mvoed them up to render_concerts_table function
- $select .= '<input class="applybutton" type="submit" value="Apply Filters">';
+ /**
+ * 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 '<span style="color:green">NEW</span>';
+ }
+ 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 = '<form class="unassign_concert" method="POST" action="">'
+ . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />'
+ . ' <input type="hidden" name="pid" value="' . $role . '" />'
+ . ' <input type="submit" name="unassignitem" value=""/>'
+ . '</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 ( array_search($this->username, $roles) ) {
+ // other slots for this concert are taken by user
+ $f = '<span class="taken_by_self">-</span>';
+ }
+ else { //not taken by anyone
+ $f = '<form class="assign_concert" method="POST" action="">'
+ . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />'
+ . ' <input type="hidden" name="pid" value="' . $role. '" />'
+ . ' <input type="submit" name="assignitem" value=""/>'
+ . '</form>';
+ }
- private function adminactions( GiglogAdmin_Concert $concert ) : string
- {
- return
- '<form class="adminactions" method="POST" action="">'
- . '<input type="hidden" name="cid" value="' . $concert->id() . '" />'
- . \EternalTerror\ViewHelpers\select_field(
- 'selectstatus',
- array_map(fn($i) => [ $i, self::STATUS_LABELS[$i] ], range(1, count(self::STATUS_LABELS) - 1)),
- $concert->status())
- . '<input type="submit" value="SetStatus">'
- . '<input type="submit" name ="edit" value="EDIT">'
- . '</form>';
- }
-
- /**
- * 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 '<span style="color:green">NEW</span>';
- }
- else {
- return '';
- }
- }
-
- 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 = '<form class="unassign_concert" method="POST" action="">'
- . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />'
- . ' <input type="hidden" name="pid" value="' . $role . '" />'
- . ' <input type="submit" name="unassignitem" value=""/>'
- . '</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 ( array_search($this->username, $roles) ) {
- // other slots for this concert are taken by user
- $f = '<span class="taken_by_self">-</span>';
- }
- else { //not taken by anyone
- $f = '<form class="assign_concert" method="POST" action="">'
- . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />'
- . ' <input type="hidden" name="pid" value="' . $role. '" />'
- . ' <input type="submit" name="assignitem" value=""/>'
- . '</form>';
- }
-
- return $f;
- }
- }
- }
+ return $f;
+ }
+ }
+}
diff --git a/includes/admin/views/_edit_concert_form.php b/includes/admin/views/_edit_concert_form.php
index 9bddfba..d17ef2d 100644
--- a/includes/admin/views/_edit_concert_form.php
+++ b/includes/admin/views/_edit_concert_form.php
@@ -20,7 +20,7 @@ if (!class_exists("GiglogAdmin_EditConcertForm"))
private function user_dropdown_for_role( GiglogAdmin_Concert $concert, string $role): string
{
$users = array_map(
- fn($usr) => $usr->user_login,
+ fn($usr): string => $usr->user_login,
get_users( array( 'fields' => array( 'user_login' ) ) ) );
$roles = $concert->roles();
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php
index 13c08b9..b0b018c 100644
--- a/includes/admin/views/giglog_admin_page.php
+++ b/includes/admin/views/giglog_admin_page.php
@@ -158,7 +158,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
];
$concert = GiglogAdmin_Concert::get(intval($_POST['pid']));
- if ($concert->update((object) $attributes)) {
+ if ($concert && $concert->update((object) $attributes)) {
// let user know the concert was updated.
// Look into admin_notices
}
diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php
index 7cf4009..ed6f978 100644
--- a/includes/admin/views/giglog_import_gigs.php
+++ b/includes/admin/views/giglog_import_gigs.php
@@ -38,26 +38,23 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
}
/**
- * Imports concert data from a file with tab separated values.
- *
- * The file must contain the following columns each separated by _one_
- * tab character:
- *
- * 1. Concertname
- * 2. Venuename or numeric venue id
- * 3. Concert date
- * 4. Ticket link
- * 5. Event info link
- *
- * Empty lines are ignored.
- *
- * @return void
- *
- * @param array<int, mixed>
- */
-
-
-
+ * Imports concert data from a file with tab separated values.
+ *
+ * The file must contain the following columns each separated by _one_
+ * tab character:
+ *
+ * 1. Concertname
+ * 2. Venuename or numeric venue id
+ * 3. Concert date
+ * 4. Ticket link
+ * 5. Event info link
+ *
+ * Empty lines are ignored.
+ *
+ * @return void
+ *
+ * @param array<mixed>
+ */
static function process_upload(array $file): void {
global $wpdb;
$newconcert= [];
@@ -86,66 +83,57 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
continue;
}
-
-
else {
- if (empty(trim($resultArray[0])))
- { $importerrors.= 'Row '.$rid.' is missing concert name!'."<br>";
+ if (empty(trim($resultArray[0]))) {
+ $importerrors.= 'Row '.$rid.' is missing concert name!'."<br>";
continue;
}
- else if (empty(trim($resultArray[1])))
- { $importerrors.= 'Row '.$rid.' is missing venue name!'."<br>";
+ elseif (empty(trim($resultArray[1]))) {
+ $importerrors.= 'Row '.$rid.' is missing venue name!'."<br>";
continue;
}
-
- else if (empty(trim($resultArray[2])))
- { $importerrors.= 'Row '.$rid.' is missing city name!' ."<br>";
+ elseif (empty(trim($resultArray[2]))) {
+ $importerrors.= 'Row '.$rid.' is missing city name!' ."<br>";
continue;
}
-
else {
$condate = date('Y-m-d', strtotime($resultArray[3]));
- if ($condate<date("Y-m-d"))
- {$importerrors.= 'Row '.$rid.' has date in the past!' .$resultArray[3]."<br>";
- continue; }
+ if ($condate<date("Y-m-d")) {
+ $importerrors.= 'Row '.$rid.' has date in the past!' .$resultArray[3]."<br>";
+ continue;
+ }
+ else {
+ $cname = trim($resultArray[0]);
+ $venue = trim($resultArray[1]);
+ if (is_numeric($venue)) {
+ $venue = GiglogAdmin_Venue::get($venue);
+ }
else {
+ $venue = GiglogAdmin_Venue::find_or_create($venue,trim($resultArray[2]));
+ }
+ $ticketlink = trim($resultArray[4]);
+ $eventlink = trim($resultArray[5]);
- $cname = trim($resultArray[0]);
- $venue = trim($resultArray[1]);
-
-
- if (is_numeric($venue)) {
- $venue = GiglogAdmin_Venue::get($venue);
- }
- else {
- $venue = GiglogAdmin_Venue::find_or_create($venue,trim($resultArray[2]));
- }
-
-
- $ticketlink = trim($resultArray[4]);
- $eventlink = trim($resultArray[5]);
-
- try {
- GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink);
-
- }
-
-
- catch(Exception $e) {
- $importerrors.= 'Row '.$rid.' is duplicate (or failed due unknown error)!'."<br>";
- }
+ try {
+ GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink);
+ }
+ catch(Exception $e) {
+ $importerrors.= 'Row '.$rid.' is duplicate (or failed due unknown error)!'."<br>";
}
}
-
}
-
-
}
}
- if (!empty($importerrors)) echo ($importerrors);
- else echo ('All rows imported ok');
+ }
+
+ if (!empty($importerrors)) {
+ echo ($importerrors);
+ }
+ else {
+ echo ('All rows imported ok');
}
}
}
+}
diff --git a/includes/concert.php b/includes/concert.php
index 91fbe57..a8c71db 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -78,8 +78,8 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
/**
* Return the concert with the given id.
*
- * @param int $id.
- * @return null|self.
+ * @param int $id
+ * @return null|self
*/
static function get( int $id ) : ?self
{