summaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2022-06-18 11:38:26 +0200
committerHarald Eilertsen <haraldei@anduin.net>2022-06-18 11:38:26 +0200
commit0e42a12a33b9bb193fa7851628edf018bd922362 (patch)
treef01c0f82d0d8399f9c502d769c8e182e3b6df153 /includes
parentc0ff4d1d2ca7e4226d718bf11a636f431c470fe6 (diff)
downloadgigologadmin-0e42a12a33b9bb193fa7851628edf018bd922362.tar.gz
gigologadmin-0e42a12a33b9bb193fa7851628edf018bd922362.tar.bz2
gigologadmin-0e42a12a33b9bb193fa7851628edf018bd922362.zip
Add phpcs config and do automatic fixups.
Diffstat (limited to 'includes')
-rw-r--r--includes/admin/helpfiles/instr_photog.php6
-rw-r--r--includes/admin/helpfiles/instr_reviewers.php2
-rw-r--r--includes/admin/helpfiles/instrunctions.php2
-rw-r--r--includes/admin/register_db_tables.php17
-rw-r--r--includes/admin/views/_concerts_table.php295
-rw-r--r--includes/admin/views/_edit_concert_form.php159
-rw-r--r--includes/admin/views/_new_venue_form.php29
-rw-r--r--includes/admin/views/giglog_admin_page.php40
-rw-r--r--includes/admin/views/giglog_import_gigs.php96
-rw-r--r--includes/concert.php254
-rw-r--r--includes/giglog_visitor_display.php7
-rw-r--r--includes/ical_export.php65
-rw-r--r--includes/venue.php139
-rw-r--r--includes/view-helpers/select_field.php9
14 files changed, 531 insertions, 589 deletions
diff --git a/includes/admin/helpfiles/instr_photog.php b/includes/admin/helpfiles/instr_photog.php
index f661c5f..a530d48 100644
--- a/includes/admin/helpfiles/instr_photog.php
+++ b/includes/admin/helpfiles/instr_photog.php
@@ -5,7 +5,7 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-if ( !class_exists( 'Instructions_Photogs' ) ) {
+if ( ! class_exists( 'Instructions_Photogs' ) ) {
@@ -15,8 +15,6 @@ if ( !class_exists( 'Instructions_Photogs' ) ) {
static function render_instr_photo_html(): void {
-
-
?>
@@ -215,8 +213,6 @@ if ( !class_exists( 'Instructions_Photogs' ) ) {
<?php
-
-
}
diff --git a/includes/admin/helpfiles/instr_reviewers.php b/includes/admin/helpfiles/instr_reviewers.php
index 3632980..f94ec51 100644
--- a/includes/admin/helpfiles/instr_reviewers.php
+++ b/includes/admin/helpfiles/instr_reviewers.php
@@ -5,7 +5,7 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-if ( !class_exists( 'Instructions_Reviewers' ) ) {
+if ( ! class_exists( 'Instructions_Reviewers' ) ) {
class Instructions_Reviewers {
diff --git a/includes/admin/helpfiles/instrunctions.php b/includes/admin/helpfiles/instrunctions.php
index b9c4d89..d549aff 100644
--- a/includes/admin/helpfiles/instrunctions.php
+++ b/includes/admin/helpfiles/instrunctions.php
@@ -5,7 +5,7 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-if ( !class_exists( 'Instructions_Page' ) ) {
+if ( ! class_exists( 'Instructions_Page' ) ) {
class Instructions_Page {
diff --git a/includes/admin/register_db_tables.php b/includes/admin/register_db_tables.php
index ce0f25c..5f83e25 100644
--- a/includes/admin/register_db_tables.php
+++ b/includes/admin/register_db_tables.php
@@ -4,16 +4,14 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-if ( !function_exists( "giglog_register_db_tables") )
-{
+if ( ! function_exists( 'giglog_register_db_tables' ) ) {
/**
* Registers the tables used by the GiglogAdmin plugin
*/
- function giglog_register_db_tables() : void
- {
+ function giglog_register_db_tables() : void {
global $wpdb;
- $tables = [];
+ $tables = array();
$tables[] =
"CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}giglogadmin_venues` (
`id` int(11) NOT NULL AUTO_INCREMENT,
@@ -45,11 +43,10 @@ if ( !function_exists( "giglog_register_db_tables") )
REFERENCES `{$wpdb->prefix}giglogadmin_venues` (`id`) ON DELETE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
-
- foreach($tables as $tabledef) {
- $result = $wpdb->query($tabledef);
- if ($result === false) {
- error_log("Registering table failed.");
+ foreach ( $tables as $tabledef ) {
+ $result = $wpdb->query( $tabledef );
+ if ( $result === false ) {
+ error_log( 'Registering table failed.' );
}
}
}
diff --git a/includes/admin/views/_concerts_table.php b/includes/admin/views/_concerts_table.php
index 719dda5..ad7aebc 100644
--- a/includes/admin/views/_concerts_table.php
+++ b/includes/admin/views/_concerts_table.php
@@ -6,25 +6,24 @@
require_once __DIR__ . '/../../view-helpers/select_field.php';
-if (!class_exists("GiglogAdmin_ConcertsTable"))
-{
- class GiglogAdmin_ConcertsTable
- {
- const STATUS_LABELS = [
+if ( ! class_exists( 'GiglogAdmin_ConcertsTable' ) ) {
+ class GiglogAdmin_ConcertsTable {
+
+ const STATUS_LABELS = array(
'',
'Accred Requested',
'Photo Approved',
'Text Approved',
'Photo and Text Approved',
- 'Rejected'
- ];
+ 'Rejected',
+ );
- const FILTER_KEYS = [
+ const FILTER_KEYS = array(
'city',
'venue',
'month',
- 'only_mine'
- ];
+ 'only_mine',
+ );
private string $username;
private array $filter;
@@ -36,98 +35,94 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
private string $nonce;
- public static function update() : void
- {
+ public static function update() : void {
//
// Check that we get a nonce, and that it is valid to prevent CSRF attacks.
//
- if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'concerts-table')) {
- wp_die('You are not allowed to do that.', 403);
+ if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'concerts-table' ) ) {
+ wp_die( 'You are not allowed to do that.', 403 );
exit();
}
- if (isset($_POST['assignitem'])) {
- $concert = GiglogAdmin_Concert::get(intval($_POST['cid']));
+ if ( isset( $_POST['assignitem'] ) ) {
+ $concert = GiglogAdmin_Concert::get( intval( $_POST['cid'] ) );
- if ($concert) {
- $role = sanitize_text_field($_POST['pid']);
- self::assignconcert($role, $concert);
+ if ( $concert ) {
+ $role = sanitize_text_field( $_POST['pid'] );
+ self::assignconcert( $role, $concert );
}
return;
}
- if (isset($_POST['unassignitem'])) {
- $concert = GiglogAdmin_Concert::get(intval($_POST['cid']));
+ if ( isset( $_POST['unassignitem'] ) ) {
+ $concert = GiglogAdmin_Concert::get( intval( $_POST['cid'] ) );
- if ($concert) {
- $role = sanitize_text_field($_POST['pid']);
- self::unassignconcert($role, $concert);
+ if ( $concert ) {
+ $role = sanitize_text_field( $_POST['pid'] );
+ self::unassignconcert( $role, $concert );
}
return;
}
// handle the status drop down
- if (isset($_POST['selectstatus']) && !empty($_POST['selectstatus']) && !empty($_POST['cid'])) {
- if ($_POST['selectstatus'] > 0 && $_POST['selectstatus'] < count(self::STATUS_LABELS)) {
- $concert = GiglogAdmin_Concert::get(intval($_POST['cid']));
+ if ( isset( $_POST['selectstatus'] ) && ! empty( $_POST['selectstatus'] ) && ! empty( $_POST['cid'] ) ) {
+ if ( $_POST['selectstatus'] > 0 && $_POST['selectstatus'] < count( self::STATUS_LABELS ) ) {
+ $concert = GiglogAdmin_Concert::get( intval( $_POST['cid'] ) );
if ( $concert ) {
- $concert->set_status(intval($_POST['selectstatus']));
+ $concert->set_status( intval( $_POST['selectstatus'] ) );
$concert->save();
- self::emailuser($concert,intval($_POST['selectstatus']));
+ self::emailuser( $concert, intval( $_POST['selectstatus'] ) );
}
}
}
}
- static function assignconcert(string $p1, GiglogAdmin_Concert $concert): void
- {
+ static function assignconcert( string $p1, GiglogAdmin_Concert $concert ): void {
$username = wp_get_current_user()->user_login;
- $concert->assign_role($p1, $username);
+ $concert->assign_role( $p1, $username );
$concert->save();
- $cuser = get_user_by( 'login', 'etadmin');
+ $cuser = get_user_by( 'login', 'etadmin' );
if ( $cuser ) {
$dest = $cuser->user_email;
- $subject = 'WP-GIGLOG '.$username.' has taken '.$p1. 'for concert '.$concert->cname();
- $body = 'WP-GIGLOG '.$username.' has taken '.$p1. 'for concert '.$concert->cname().', concert with ID ' .$concert->id();
- $headers = array('Content-Type: text/html; charset=UTF-8');
+ $subject = 'WP-GIGLOG ' . $username . ' has taken ' . $p1 . 'for concert ' . $concert->cname();
+ $body = 'WP-GIGLOG ' . $username . ' has taken ' . $p1 . 'for concert ' . $concert->cname() . ', concert with ID ' . $concert->id();
+ $headers = array( 'Content-Type: text/html; charset=UTF-8' );
wp_mail( $dest, $subject, $body );
}
}
- static function unassignconcert(string $p1, GiglogAdmin_Concert $concert): void
- {
+ static function unassignconcert( string $p1, GiglogAdmin_Concert $concert ): void {
$username = wp_get_current_user()->user_login;
- $concert->remove_user_from_roles($username);
+ $concert->remove_user_from_roles( $username );
$concert->save();
- $cuser = get_user_by( 'login', 'etadmin');
+ $cuser = get_user_by( 'login', 'etadmin' );
if ( $cuser ) {
$dest = $cuser->user_email;
- $subject = 'WP-GIGLOG '.$username.' has UNASSIGNED '.$p1. 'for concert '.$concert->cname();
- $body = 'WP-GIGLOG '.$username.' has UNASSIGNED '.$p1. 'for concert '.$concert->cname().', concert with ID ' .$concert->id();
- $headers = array('Content-Type: text/html; charset=UTF-8');
+ $subject = 'WP-GIGLOG ' . $username . ' has UNASSIGNED ' . $p1 . 'for concert ' . $concert->cname();
+ $body = 'WP-GIGLOG ' . $username . ' has UNASSIGNED ' . $p1 . 'for concert ' . $concert->cname() . ', concert with ID ' . $concert->id();
+ $headers = array( 'Content-Type: text/html; charset=UTF-8' );
wp_mail( $dest, $subject, $body );
}
}
- static function emailuser(GiglogAdmin_Concert $concert, string $cstatus): void
- {
+ static function emailuser( GiglogAdmin_Concert $concert, string $cstatus ): void {
$username = wp_get_current_user()->user_login;
$useremail = 'live@eternal-terror.com';
$dest = '';
- $roles = $concert -> roles();
+ $roles = $concert->roles();
$x = '';
- foreach ($roles as $role) {
- if($role){
- $cuser = get_user_by( 'login', $role);
+ foreach ( $roles as $role ) {
+ if ( $role ) {
+ $cuser = get_user_by( 'login', $role );
if ( $cuser ) {
$dest .= $cuser->user_email . ',';
@@ -135,44 +130,40 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
}
}
- $subject = 'Message from GIGLOG: Concert '.$concert->cname().' has a new status '.$cstatus. '.';
- $body = 'You receive this message because you have assigned one of the roles for Concert '.$concert->cname().'.';
- $body .= '\r\n This is to inform you that there is a new status for the acreditation '.$cstatus. '.';
+ $subject = 'Message from GIGLOG: Concert ' . $concert->cname() . ' has a new status ' . $cstatus . '.';
+ $body = 'You receive this message because you have assigned one of the roles for Concert ' . $concert->cname() . '.';
+ $body .= '\r\n This is to inform you that there is a new status for the acreditation ' . $cstatus . '.';
$body .= '\r\n Should you no longer want to receive updates about this concert, please log in to Giglog and remove yourself from the concert. Thanks!';
- $headers = array('Content-Type: text/plain; charset=UTF-8'); //it is text by default so no need for headers actually
+ $headers = array( 'Content-Type: text/plain; charset=UTF-8' ); // it is text by default so no need for headers actually
wp_mail( $dest, $subject, $body );
}
- public function __construct()
- {
- $this->username = wp_get_current_user()->user_login;
+ public function __construct() {
+ $this->username = wp_get_current_user()->user_login;
// Set the nonce we use to check for CSRF attacks.
- $this->nonce = wp_create_nonce('concerts-table');
+ $this->nonce = wp_create_nonce( 'concerts-table' );
$this->get_args();
}
- public function render(): string
- {
+ public function render(): string {
return $this->render_filters()
. $this->render_concerts_table();
}
- private function render_concert_table_header() : string
- {
+ private function render_concert_table_header() : string {
$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 .= '<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">';
- $content.= '<th>CITY</th><th>DATE</th><th>NAME</th><th>VENUE</th>';
+ $content .= '<tr class="assignithrow">';
+ $content .= '<th>CITY</th><th>DATE</th><th>NAME</th><th>VENUE</th>';
- if (!is_admin()) {
+ if ( ! is_admin() ) {
$content .= '<th>EVENT</th><th>TICKETS</th><th>Calendar</th>';
- }
- else {
+ } else {
$content .= '<th></th><th>PHOTO1</th><th>PHOTO2</th><th>TEXT1</th><th>TEXT2</th><th>STATUS</th>';
- if (current_user_can('administrator')) {
+ if ( current_user_can( 'administrator' ) ) {
$content .= '<th>AdminOptions</th>';
}
}
@@ -182,75 +173,70 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
return $content;
}
- private function get_args() : void
- {
- $this->filter = [];
+ private function get_args() : void {
+ $this->filter = array();
// Use the submitted "city" if any. Otherwise, use the default/static value.
$cty = filter_input( INPUT_GET, 'city', FILTER_SANITIZE_SPECIAL_CHARS );
- if ($cty) {
+ if ( $cty ) {
$this->filter['city'] = $cty;
}
$venue = filter_input( INPUT_GET, 'venue', FILTER_SANITIZE_SPECIAL_CHARS );
- if ($venue) {
+ if ( $venue ) {
$this->filter['venue_id'] = $venue;
}
$smonth = filter_input( INPUT_GET, 'month', FILTER_SANITIZE_SPECIAL_CHARS );
- if ($smonth) {
+ if ( $smonth ) {
$this->filter['month'] = $smonth;
}
- if(isset($_GET['only_mine']) && $_GET['only_mone'] == '1') {
+ if ( isset( $_GET['only_mine'] ) && $_GET['only_mone'] == '1' ) {
$this->filter['currentuser'] = $this->username;
}
- if (isset($_GET['page_no']) && $_GET['page_no'] != "" && is_numeric($_GET['page_no']) && isset($_GET['page_no']) == $this->page_no ) {
- $this->page_no = intval($_GET['page_no']);
+ if ( isset( $_GET['page_no'] ) && $_GET['page_no'] != '' && is_numeric( $_GET['page_no'] ) && isset( $_GET['page_no'] ) == $this->page_no ) {
+ $this->page_no = intval( $_GET['page_no'] );
} else {
$this->page_no = 1;
}
}
- private function get_concerts() : ?array
- {
+ private function get_concerts() : ?array {
$total_records_per_page = 15;
$total_concerts = GiglogAdmin_Concert::count( $this->filter );
$this->total_no_of_pages = ceil( $total_concerts / $total_records_per_page );
- //calculate OFFSET Value and SET other Variables
- $offset = ($this->page_no - 1) * $total_records_per_page;
+ // calculate OFFSET Value and SET other Variables
+ $offset = ( $this->page_no - 1 ) * $total_records_per_page;
$this->previous_page = $this->page_no - 1;
$this->next_page = $this->page_no + 1;
-
- if ($this->page_no > $this->total_no_of_pages ) {
+ if ( $this->page_no > $this->total_no_of_pages ) {
$this->page_no = 1;
}
- $this->filter['offset'] = $offset;
- $this->filter['recperpage'] = $total_records_per_page;
+ $this->filter['offset'] = $offset;
+ $this->filter['recperpage'] = $total_records_per_page;
- return GiglogAdmin_Concert::find_concerts($this->filter);
+ return GiglogAdmin_Concert::find_concerts( $this->filter );
}
- private function get_filter(string $f) : ?string
- {
- return isset( $this->filter[$f] ) ? $this->filter[$f] : null;
+ private function get_filter( string $f ) : ?string {
+ return isset( $this->filter[ $f ] ) ? $this->filter[ $f ] : null;
}
- private function render_pagination() : string
- {
+ private function render_pagination() : string {
$content =
'<div id="pagtextbox" style="display:flex">'
. '<span class="alignleft" style="text-align:left;flex:auto;">';
- if($this->page_no > 1) {
+ if ( $this->page_no > 1 ) {
$content .=
'<span>'
- . '<a href="'. add_query_arg( 'page_no', 1 ) . '">'
+ . '<a href="' . add_query_arg( 'page_no', 1 ) . '">'
. 'First Page</a> -'
. '</span>'
. '<span>'
@@ -265,14 +251,14 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
$content .= '<span class="alignright" style="text-align:right;flex:auto;float:none">';
- if ($this->page_no < $this->total_no_of_pages) {
+ 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 ) .'">'
+ . '<a href="' . add_query_arg( 'page_no', $this->total_no_of_pages ) . '">'
. 'Last Page</a>'
. '</span>';
}
@@ -284,8 +270,7 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
return $content;
}
- private function render_concerts_table() : string
- {
+ private function render_concerts_table() : string {
$concerts = $this->get_concerts();
$last_city = '';
@@ -295,38 +280,37 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
foreach ( $concerts as $concert ) {
$content .= '<tr class="assignitr"><td>';
- if ($last_city != $concert->venue()->city()) {
+ if ( $last_city != $concert->venue()->city() ) {
$content .= $concert->venue()->city();
}
$content .= '</td>';
$content .=
- "<td>" . date( 'd.M.Y', strtotime( $concert->cdate() ) ) . "</td>"
- . "<td>" . strtoupper(esc_html($concert->cname())) . "</td>"
- . "<td>" . esc_html($concert->venue()->name()) . "</td>";
+ '<td>' . date( 'd.M.Y', strtotime( $concert->cdate() ) ) . '</td>'
+ . '<td>' . strtoupper( esc_html( $concert->cname() ) ) . '</td>'
+ . '<td>' . esc_html( $concert->venue()->name() ) . '</td>';
- if( is_admin() ) {
- $content .= '<td class="publishstatus">' . $this->mark_new_concert($concert) . '</td>';
+ if ( is_admin() ) {
+ $content .= '<td class="publishstatus">' . $this->mark_new_concert( $concert ) . '</td>';
- foreach ( [ 'photo1', 'photo2', 'rev1', 'rev2' ] as $role ) {
+ foreach ( array( '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>';
+ $content .= '<td>' . self::STATUS_LABELS[ $concert->status() ] . '</td>';
- if (current_user_can('administrator')) {
+ if ( current_user_can( 'administrator' ) ) {
$content .= "<td class=\"adminbuttons\">{$this->adminactions( $concert )}</td>";
}
- }
- else {
- $content .= "<td><a target=\"_blank\" href=\"" . esc_url($concert->eventlink()) . "\">Link</a></td>";
- $content .= "<td><a target=\"_blank\" href=\"" . esc_url($concert->tickets()) . "\">Tickets</a></td>";
+ } else {
+ $content .= '<td><a target="_blank" href="' . esc_url( $concert->eventlink() ) . '">Link</a></td>';
+ $content .= '<td><a target="_blank" href="' . esc_url( $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 .= '<td> <a href="' . get_admin_url() . 'admin-ajax.php?action=giglog_export_ical&evid=' . $concert->id() . '">iCal</td>';
$content .= '</tr>';
$last_city = $concert->venue()->city();
}
@@ -335,20 +319,19 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
$content .= $this->render_pagination();
- //from main form that includes filters
+ // from main form that includes filters
$content .= '</div></form></p>';
// return the table
return $content;
}
- private function render_filters() : string
- {
+ private function render_filters() : string {
global $wp_locale;
$select = '<p><form method="GET" action="" class="filterclass">FILTER DATA: ';
- foreach( $_GET as $name => $val ) {
+ foreach ( $_GET as $name => $val ) {
if ( in_array( $name, self::FILTER_KEYS ) ) {
continue;
}
@@ -357,60 +340,62 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
. '" value="' . esc_attr( $val ) . '">';
}
- $cty = $this->get_filter('city');
+ $cty = $this->get_filter( 'city' );
$select .= \EternalTerror\ViewHelpers\select_field(
- "city",
- array_map(fn($city) => [$city, $city], GiglogAdmin_Venue::all_cities()),
+ 'city',
+ array_map( fn( $city) => array( $city, $city ), GiglogAdmin_Venue::all_cities() ),
$cty,
- "Select city...");
+ 'Select city...'
+ );
- if ( !empty($cty) ) {
- //second drop down for venue
+ if ( ! empty( $cty ) ) {
+ // second drop down for venue
$select .= \EternalTerror\ViewHelpers\select_field(
- "venue",
+ 'venue',
array_map(
- fn($venue) => [$venue->id(), $venue->name()],
- GiglogAdmin_Venue::venues_in_city($cty)
+ fn( $venue) => array( $venue->id(), $venue->name() ),
+ GiglogAdmin_Venue::venues_in_city( $cty )
),
- $this->get_filter('venue_id'),
- "Select venue...");
+ $this->get_filter( 'venue_id' ),
+ 'Select venue...'
+ );
}
$select .= \EternalTerror\ViewHelpers\select_field(
- "month",
+ 'month',
array_map(
- fn($m) => [ $m, $wp_locale->get_month( $m ) ],
+ fn( $m) => array( $m, $wp_locale->get_month( $m ) ),
range( 1, 12 )
),
- $this->get_filter('month'),
- "Select month...");
+ $this->get_filter( 'month' ),
+ 'Select month...'
+ );
- $select.='</select>';
+ $select .= '</select>';
- if(is_admin()) {
- //option to select own concerts only
+ 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>';
}
- //NOTE that I remvoed </form></p> and mvoed them up to render_concerts_table function
+ // NOTE that I remvoed </form></p> and mvoed them up to render_concerts_table function
$select .= '<input class="applybutton" type="submit" value="Apply Filters">';
return $select;
}
- private function adminactions( GiglogAdmin_Concert $concert ) : string
- {
- return
- '<form class="adminactions" method="POST" action="">'
+ private function adminactions( GiglogAdmin_Concert $concert ) : string {
+ return '<form class="adminactions" method="POST" action="">'
. '<input type="hidden" name="nonce" value="' . $this->nonce . '">'
- . '<input type="hidden" name="cid" value="' . $concert->id() . '" />'
+ . '<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())
+ array_map( fn( $i) => array( $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>';
@@ -422,24 +407,21 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
*
* @return null|string
*/
- private function mark_new_concert(GiglogAdmin_Concert $concert) : string
- {
+ private function mark_new_concert( GiglogAdmin_Concert $concert ) : string {
$now = new DateTime();
- $new_entry = $now->diff($concert->created())->days <= 10;
- if ($new_entry) {
+ $new_entry = $now->diff( $concert->created() )->days <= 10;
+ if ( $new_entry ) {
return '<span style="color:green">NEW</span>';
- }
- else {
+ } else {
return '';
}
}
- private function assign_role_for_user_form(string $role, GiglogAdmin_Concert $concert) : ?string
- {
+ 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;
+ $assigned_user = array_key_exists( $role, $roles ) ? $roles[ $role ] : null;
- //first check if current slot is taken by current user
+ // 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="nonce" value="' . $this->nonce . '">'
@@ -447,20 +429,17 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
. ' <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
+ } 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) ) {
+ } 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
+ } else { // not taken by anyone
$f = '<form class="assign_concert" method="POST" action="">'
. ' <input type="hidden" name="nonce" value="' . $this->nonce . '">'
. ' <input type="hidden" name="cid" value="' . $concert->id() . '" />'
- . ' <input type="hidden" name="pid" value="' . $role. '" />'
+ . ' <input type="hidden" name="pid" value="' . $role . '" />'
. ' <input type="submit" name="assignitem" value=""/>'
. '</form>';
}
diff --git a/includes/admin/views/_edit_concert_form.php b/includes/admin/views/_edit_concert_form.php
index b839edd..18ff4d3 100644
--- a/includes/admin/views/_edit_concert_form.php
+++ b/includes/admin/views/_edit_concert_form.php
@@ -6,134 +6,129 @@
require_once __DIR__ . '/../../view-helpers/select_field.php';
-if (!class_exists("GiglogAdmin_EditConcertForm"))
-{
- class GiglogAdmin_EditConcertForm
- {
- private function get_venue_selector( ?GiglogAdmin_Venue $invenue ): string
- {
+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);
+ 'selectvenueadmin',
+ array_map( fn( $venue) => array( $venue->id(), $venue->name() ), GiglogAdmin_Venue::all_venues() ),
+ $invenue ? $invenue->id() : null
+ );
}
- private function user_dropdown_for_role( GiglogAdmin_Concert $concert, string $role): string
- {
+ private function user_dropdown_for_role( GiglogAdmin_Concert $concert, string $role ): string {
$users = array_map(
- fn($usr): string => $usr->user_login,
- get_users( array( 'fields' => array( 'user_login' ) ) ) );
+ fn( $usr): string => $usr->user_login,
+ get_users( array( 'fields' => array( 'user_login' ) ) )
+ );
$roles = $concert->roles();
- $current_user = array_key_exists($role, $roles) ? $roles[$role] : NULL;
+ $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);
+ array_map( fn( $user) => array( $user, $user ), $users ),
+ $current_user
+ );
}
- public function render() : string
- {
- $cid = filter_input(INPUT_POST, "cid");
- $editing = filter_input(INPUT_POST, "edit") == "EDIT";
+ public function render() : string {
+ $cid = filter_input( INPUT_POST, 'cid' );
+ $editing = filter_input( INPUT_POST, 'edit' ) == 'EDIT';
- if ($editing && !empty($cid)) {
- $c = GiglogAdmin_Concert::get($cid);
- if ( !$c ) {
- wp_die("Invalid request!", 400);
+ if ( $editing && ! empty( $cid ) ) {
+ $c = GiglogAdmin_Concert::get( $cid );
+ if ( ! $c ) {
+ wp_die( 'Invalid request!', 400 );
}
- }
- else {
- $c = new GiglogAdmin_Concert((object)[]);
+ } else {
+ $c = new GiglogAdmin_Concert( (object) array() );
}
- $content='<div class="concertform">';
- $content.='<form method="POST" action="" class="concert" >'
- .'<div class="concertitems"><strong>CONCERT DETAILS</strong><br><br><fieldset>'
+ $content = '<div class="concertform">';
+ $content .= '<form method="POST" action="" class="concert" >'
+ . '<div class="concertitems"><strong>CONCERT DETAILS</strong><br><br><fieldset>'
. wp_nonce_field( 'edit-concert', 'nonce' )
- .'<input type="hidden" name="pid" value="' . esc_attr($c->id()) . '" />'
- .'<label for="cname">Concert Name:</label>'
- .'<textarea id="cname" name="cname" value="'. esc_attr($c->cname()) . '">'
- . esc_textarea($c->cname())
- .'</textarea><br>'
- .'<label for="venue">Venue:</label>' . $this->get_venue_selector($c->venue()) . '<br>'
- //date has to be formatted else it is not red in the date field of html form
- .'<label for="cdate">Date:</label>'
- .'<input type="date" id="cdate" name="cdate" value="'. esc_attr(date('Y-m-d',strtotime($c->cdate()))) .'"><br>'
- .'<label for="ticket">Tickets:</label>'
- .'<input type="text" id="ticket" name="ticket" value="'. esc_url($c->tickets()) .'"><br>'
- .'<label for="eventurl">Event link:</label>'
- .'<input type="text" id="eventurl" name="eventurl" value="'. esc_url($c->eventlink()) .'"><br>'
- .'</fieldset>';
+ . '<input type="hidden" name="pid" value="' . esc_attr( $c->id() ) . '" />'
+ . '<label for="cname">Concert Name:</label>'
+ . '<textarea id="cname" name="cname" value="' . esc_attr( $c->cname() ) . '">'
+ . esc_textarea( $c->cname() )
+ . '</textarea><br>'
+ . '<label for="venue">Venue:</label>' . $this->get_venue_selector( $c->venue() ) . '<br>'
+ // date has to be formatted else it is not red in the date field of html form
+ . '<label for="cdate">Date:</label>'
+ . '<input type="date" id="cdate" name="cdate" value="' . esc_attr( date( 'Y-m-d', strtotime( $c->cdate() ) ) ) . '"><br>'
+ . '<label for="ticket">Tickets:</label>'
+ . '<input type="text" id="ticket" name="ticket" value="' . esc_url( $c->tickets() ) . '"><br>'
+ . '<label for="eventurl">Event link:</label>'
+ . '<input type="text" id="eventurl" name="eventurl" value="' . esc_url( $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>';
+ 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>';
- $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 .= '<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 .= '<fieldset></div></form></div>';
return $content;
}
- static function update() : void
- {
- if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'edit-concert')) {
- wp_die('CSRF validation failed.', 403);
+ static function update() : void {
+ if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'edit-concert' ) ) {
+ wp_die( 'CSRF validation failed.', 403 );
}
- if (isset($_POST['newconcert'])) {
- if (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) {
+ if ( isset( $_POST['newconcert'] ) ) {
+ if ( empty( $_POST['cname'] ) || empty( $_POST['selectvenueadmin'] ) || empty( $_POST['cdate'] ) || empty( $_POST['ticket'] ) || empty( $_POST['eventurl'] ) ) {
echo '<script language="javascript">alert("You are missing a value, concert was not created"); </script>';
- }
- else {
- if (GiglogAdmin_Concert::create($_POST['cname'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl'])) {
+ } else {
+ if ( GiglogAdmin_Concert::create( $_POST['cname'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl'] ) ) {
echo '<script language="javascript">alert("Yey, concert created"); </script>';
- }
- else {
+ } else {
echo '<script language="javascript">alert("Nay, concert was duplicated"); </script>';
}
}
}
- if (isset($_POST['editconcert']))
- {
+ if ( isset( $_POST['editconcert'] ) ) {
$roles = array_reduce(
- ['photo1', 'photo1', 'rev1', 'rev2'],
- function($roles, $r) {
- if (isset($_POST[$r])) {
- $roles[$r] = sanitize_user($_POST[$r]);
+ array( 'photo1', 'photo1', 'rev1', 'rev2' ),
+ function( $roles, $r ) {
+ if ( isset( $_POST[ $r ] ) ) {
+ $roles[ $r ] = sanitize_user( $_POST[ $r ] );
}
return $roles;
},
- []
+ array()
);
- $attributes = [
- 'wpgconcert_name' => sanitize_text_field($_POST['cname']),
- 'venue' => intval($_POST['selectvenueadmin']),
- 'wpgconcert_date' => sanitize_text_field($_POST['cdate']),
- 'wpgconcert_ticket' => esc_url_raw($_POST['ticket']),
- 'wpgconcert_event' => esc_url_raw($_POST['eventurl']),
+ $attributes = array(
+ 'wpgconcert_name' => sanitize_text_field( $_POST['cname'] ),
+ 'venue' => intval( $_POST['selectvenueadmin'] ),
+ 'wpgconcert_date' => sanitize_text_field( $_POST['cdate'] ),
+ 'wpgconcert_ticket' => esc_url_raw( $_POST['ticket'] ),
+ 'wpgconcert_event' => esc_url_raw( $_POST['eventurl'] ),
'wpgconcert_roles' => $roles,
- ];
+ );
- $concert = GiglogAdmin_Concert::get(intval($_POST['pid']));
- if ($concert && $concert->update((object) $attributes)) {
+ $concert = GiglogAdmin_Concert::get( intval( $_POST['pid'] ) );
+ if ( $concert && $concert->update( (object) $attributes ) ) {
// let user know the concert was updated.
// Look into admin_notices
}
diff --git a/includes/admin/views/_new_venue_form.php b/includes/admin/views/_new_venue_form.php
index ab02bbe..39eb1b2 100644
--- a/includes/admin/views/_new_venue_form.php
+++ b/includes/admin/views/_new_venue_form.php
@@ -4,14 +4,11 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-if ( !class_exists( "GiglogAdmin_NewVenueForm" ) )
-{
- class GiglogAdmin_NewVenueForm
- {
- public function render() : string
- {
- return
- '<div class="venueform">'
+if ( ! class_exists( 'GiglogAdmin_NewVenueForm' ) ) {
+ class GiglogAdmin_NewVenueForm {
+
+ public function render() : string {
+ return '<div class="venueform">'
. '<p><strong>VENUE DETAILS</strong></p>'
. '<form method="POST" action="" class="venue">'
. ' <fieldset>'
@@ -32,18 +29,16 @@ if ( !class_exists( "GiglogAdmin_NewVenueForm" ) )
. '</div>';
}
- static function update() : void
- {
- if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'edit-venue')) {
- header("{$_SERVER['SERVER_PROTOCOL']} 403 Forbidden");
- wp_die('CSRF validation failed.', 403);
+ static function update() : void {
+ if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'edit-venue' ) ) {
+ header( "{$_SERVER['SERVER_PROTOCOL']} 403 Forbidden" );
+ wp_die( 'CSRF validation failed.', 403 );
}
- if (empty($_POST['venuename']) || empty($_POST['venuecity'])) {
+ if ( empty( $_POST['venuename'] ) || empty( $_POST['venuecity'] ) ) {
echo '<script language="javascript">alert("You are missing a value, venue was not created"); </script>';
- }
- else {
- GiglogAdmin_Venue::create($_POST['venuename'],$_POST['venuecity']);
+ } else {
+ GiglogAdmin_Venue::create( $_POST['venuename'], $_POST['venuecity'] );
echo '<script language="javascript">alert("Yey, venue created"); </script>';
}
}
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php
index 7da93de..f3eaa87 100644
--- a/includes/admin/views/giglog_admin_page.php
+++ b/includes/admin/views/giglog_admin_page.php
@@ -5,31 +5,29 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
+if ( ! class_exists( 'GiglogAdmin_AdminPage' ) ) {
require_once __DIR__ . '/../../venue.php';
require_once __DIR__ . '/_concerts_table.php';
require_once __DIR__ . '/_edit_concert_form.php';
require_once __DIR__ . '/_new_venue_form.php';
- class GiglogAdmin_AdminPage
- {
- const STATUS_LABELS = [
+ class GiglogAdmin_AdminPage {
+
+ const STATUS_LABELS = array(
'',
'Accred Requested',
'Photo Approved',
'Text Approved',
'Photo and Text Approved',
- 'Rejected'
- ];
+ 'Rejected',
+ );
- public static function render_html() : void
- {
+ public static function render_html() : void {
$page = new self();
$page->render_page();
}
- private function render_page() : void
- {
+ private function render_page() : void {
$concerts = new GiglogAdmin_ConcertsTable();
?>
<div class="wrap">
@@ -49,40 +47,42 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
what the accreditation status is. You will get personal message if this
is really close to the concert date.</p>
- <p><?php echo $concerts->render() ?></p>
+ <p><?php echo $concerts->render(); ?></p>
</div>
<?php
- if (current_user_can('administrator')) {
+ if ( current_user_can( 'administrator' ) ) {
$edit_form = new GiglogAdmin_EditConcertForm();
- $venue_form = new GiglogAdmin_NewVenueForm(); ?>
+ $venue_form = new GiglogAdmin_NewVenueForm();
+ ?>
<div>
<h3>Form to create/edit concerts and venues</h3>
</div>
<div class="editform">
<?php echo $edit_form->render() . $venue_form->render(); ?>
- </div><?php
+ </div>
+ <?php
}
}
/**
* @return void
*/
- static function update() : void
- {
- if ('POST' !== $_SERVER['REQUEST_METHOD'])
+ static function update() : void {
+ if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
return;
+ }
- if (isset($_POST['assignitem']) || isset($_POST['unassignitem']) || isset($_POST['selectstatus'])) {
+ if ( isset( $_POST['assignitem'] ) || isset( $_POST['unassignitem'] ) || isset( $_POST['selectstatus'] ) ) {
GiglogAdmin_ConcertsTable::update();
return;
}
- if (isset($_POST['newconcert']) || isset($_POST['editconcert'])) {
+ if ( isset( $_POST['newconcert'] ) || isset( $_POST['editconcert'] ) ) {
GiglogAdmin_EditConcertForm::update();
return;
}
- if (isset($_POST['newvenue'])) {
+ if ( isset( $_POST['newvenue'] ) ) {
GiglogAdmin_NewVenueForm::update();
return;
}
diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php
index c6b6a56..505e4bd 100644
--- a/includes/admin/views/giglog_import_gigs.php
+++ b/includes/admin/views/giglog_import_gigs.php
@@ -5,7 +5,7 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
+if ( ! class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
require_once __DIR__ . '/../../concert.php';
require_once __DIR__ . '/../../venue.php';
@@ -15,7 +15,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
<div class="wrap">
<h1>Import gigs</h1>
<p>Import gig data from a tab separated data file.</p>
- <form action="<?php menu_page_url( 'giglog_import' ) ?>" enctype="multipart/form-data" method="post">
+ <form action="<?php menu_page_url( 'giglog_import' ); ?>" enctype="multipart/form-data" method="post">
<?php wp_nonce_field( plugin_basename( __FILE__ ), 'giglog_import_nonce' ); ?>
<label for="giglog_import_file">File: </label>
<input type="file" name="giglog_import_file" id="giglog_import_file">
@@ -26,13 +26,12 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
}
static function submit_form(): void {
- if ('POST' === $_SERVER['REQUEST_METHOD'] && current_user_can('upload_files') && !empty($_FILES['giglog_import_file']['tmp_name'])) {
- if (isset($_POST['giglog_import_nonce']) && wp_verify_nonce($_POST['giglog_import_nonce'], plugin_basename( __FILE__ )) ) {
- GiglogAdmin_ImportGigsPage::process_upload($_FILES['giglog_import_file']);
- }
- else {
- header("{$_SERVER['SERVER_PROTOCOL']} 403 Forbidden");
- wp_die('CSRF validation failed.', 403);
+ if ( 'POST' === $_SERVER['REQUEST_METHOD'] && current_user_can( 'upload_files' ) && ! empty( $_FILES['giglog_import_file']['tmp_name'] ) ) {
+ if ( isset( $_POST['giglog_import_nonce'] ) && wp_verify_nonce( $_POST['giglog_import_nonce'], plugin_basename( __FILE__ ) ) ) {
+ self::process_upload( $_FILES['giglog_import_file'] );
+ } else {
+ header( "{$_SERVER['SERVER_PROTOCOL']} 403 Forbidden" );
+ wp_die( 'CSRF validation failed.', 403 );
}
}
}
@@ -55,85 +54,80 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
*
* @param array<int, mixed> $file
*/
- static function process_upload(array $file): void
- {
- $fo = new SplFileObject($file['tmp_name']);
- $importerrors = [];
- $rid=0;
+ static function process_upload( array $file ): void {
+ $fo = new SplFileObject( $file['tmp_name'] );
+ $importerrors = array();
+ $rid = 0;
- foreach ($fo as $line) {
+ foreach ( $fo as $line ) {
$rid++;
$line = trim( $line );
- if ( !empty($line) ) {
+ if ( ! empty( $line ) ) {
try {
self::process_line( $line );
- }
- catch (Exception $e) {
+ } catch ( Exception $e ) {
$importerrors[] = "Error importing line {$rid}: {$e->getMessage()}";
}
}
}
- if (!empty($importerrors)) {
- echo implode("<br>", $importerrors);
- }
- else {
- echo ('All rows imported ok');
+ if ( ! empty( $importerrors ) ) {
+ echo implode( '<br>', $importerrors );
+ } else {
+ echo ( 'All rows imported ok' );
}
}
- static function process_line( string $line ) : void
- {
- $resultArray = explode("\t", $line);
+ static function process_line( string $line ) : void {
+ $resultArray = explode( "\t", $line );
// unsure if this is needed, considering we are also checking if
// each individual important field is missing. But if they are not
// replaced by tabs, then everything gets shifted so probably best
// to check if a value is empty and NOT replaced by tab
- if (count($resultArray) < 6) {
- throw new Exception("missing a field");
+ if ( count( $resultArray ) < 6 ) {
+ throw new Exception( 'missing a field' );
}
- if (! preg_match("/\d{4}\-\d{2}-\d{2}/",$resultArray[3])) {
- throw new Exception("invalid date: " . esc_html($resultArray[3]));
+ if ( ! preg_match( '/\d{4}\-\d{2}-\d{2}/', $resultArray[3] ) ) {
+ throw new Exception( 'invalid date: ' . esc_html( $resultArray[3] ) );
}
- if (empty(trim($resultArray[0]))) {
- throw new Exception("missing concert name");
+ if ( empty( trim( $resultArray[0] ) ) ) {
+ throw new Exception( 'missing concert name' );
}
- if (empty(trim($resultArray[1]))) {
- throw new Exception("missing venue");
+ if ( empty( trim( $resultArray[1] ) ) ) {
+ throw new Exception( 'missing venue' );
}
- if (empty(trim($resultArray[2]))) {
- throw new Exception("missing city");
+ if ( empty( trim( $resultArray[2] ) ) ) {
+ throw new Exception( 'missing city' );
}
- $condate = date('Y-m-d', strtotime($resultArray[3]));
+ $condate = date( 'Y-m-d', strtotime( $resultArray[3] ) );
- if ($condate<date("Y-m-d")) {
- throw new Exception("has date in the past: " . esc_html($resultArray[3]));
+ if ( $condate < date( 'Y-m-d' ) ) {
+ throw new Exception( 'has date in the past: ' . esc_html( $resultArray[3] ) );
}
- $cname = trim($resultArray[0]);
- $venue = trim($resultArray[1]);
+ $cname = trim( $resultArray[0] );
+ $venue = trim( $resultArray[1] );
- if (is_numeric($venue)) {
- $venue = GiglogAdmin_Venue::get(intval($venue));
- if (!$venue) {
- throw new Exception("invalid venue id: {$venue}");
+ if ( is_numeric( $venue ) ) {
+ $venue = GiglogAdmin_Venue::get( intval( $venue ) );
+ if ( ! $venue ) {
+ throw new Exception( "invalid venue id: {$venue}" );
}
- }
- else {
- $venue = GiglogAdmin_Venue::find_or_create($venue,trim($resultArray[2]));
+ } else {
+ $venue = GiglogAdmin_Venue::find_or_create( $venue, trim( $resultArray[2] ) );
}
- $ticketlink = trim($resultArray[4]);
- $eventlink = trim($resultArray[5]);
+ $ticketlink = trim( $resultArray[4] );
+ $eventlink = trim( $resultArray[5] );
- GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink);
+ GiglogAdmin_Concert::create( $cname, $venue->id(), $condate, $ticketlink, $eventlink );
}
}
}
diff --git a/includes/concert.php b/includes/concert.php
index 162291d..a225a6e 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -7,18 +7,17 @@
require_once __DIR__ . '/venue.php';
-if ( !class_exists('GiglogAdmin_DuplicateConcertException') )
-{
- class GiglogAdmin_DuplicateConcertException extends Exception
- {
+if ( ! class_exists( 'GiglogAdmin_DuplicateConcertException' ) ) {
+ class GiglogAdmin_DuplicateConcertException extends Exception {
+
}
}
-if ( !class_exists('GiglogAdmin_Concert') ) {
+if ( ! class_exists( 'GiglogAdmin_Concert' ) ) {
require_once __DIR__ . '/venue.php';
- class GiglogAdmin_Concert
- {
+ class GiglogAdmin_Concert {
+
private ?int $id;
private ?string $cname;
private ?GiglogAdmin_Venue $venue;
@@ -44,34 +43,31 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
* so this constructor can be used to construct the object
* directly from the database row.
*/
- public function __construct(object $attrs)
- {
- $this->id = isset($attrs->id) ? $attrs->id : NULL;
- $this->cname = isset($attrs->wpgconcert_name) ? $attrs->wpgconcert_name : NULL;
- $this->cdate = isset($attrs->wpgconcert_date) ? $attrs->wpgconcert_date : NULL;
- $this->tickets = isset($attrs->wpgconcert_tickets) ? $attrs->wpgconcert_tickets : NULL;
- $this->eventlink = isset($attrs->wpgconcert_event) ? $attrs->wpgconcert_event : NULL;
- $this->status = isset($attrs->wpgconcert_status) ? $attrs->wpgconcert_status : 0;
- $this->roles = isset($attrs->wpgconcert_roles) ? json_decode($attrs->wpgconcert_roles, true) : [];
- $this->created = isset($attrs->created) ? new DateTimeImmutable($attrs->created) : NULL;
- $this->updated = isset($attrs->updated) ? new DateTimeImmutable($attrs->updated) : NULL;
+ public function __construct( object $attrs ) {
+ $this->id = isset( $attrs->id ) ? $attrs->id : null;
+ $this->cname = isset( $attrs->wpgconcert_name ) ? $attrs->wpgconcert_name : null;
+ $this->cdate = isset( $attrs->wpgconcert_date ) ? $attrs->wpgconcert_date : null;
+ $this->tickets = isset( $attrs->wpgconcert_tickets ) ? $attrs->wpgconcert_tickets : null;
+ $this->eventlink = isset( $attrs->wpgconcert_event ) ? $attrs->wpgconcert_event : null;
+ $this->status = isset( $attrs->wpgconcert_status ) ? $attrs->wpgconcert_status : 0;
+ $this->roles = isset( $attrs->wpgconcert_roles ) ? json_decode( $attrs->wpgconcert_roles, true ) : array();
+ $this->created = isset( $attrs->created ) ? new DateTimeImmutable( $attrs->created ) : null;
+ $this->updated = isset( $attrs->updated ) ? new DateTimeImmutable( $attrs->updated ) : null;
if ( isset( $attrs->venue ) ) {
- if (isset($attrs->wpgvenue_name) && isset($attrs->wpgvenue_city)) {
- $venue_attrs = (object) [
- "id" => $attrs->venue,
- "wpgvenue_name" => $attrs->wpgvenue_name,
- "wpgvenue_city" => $attrs->wpgvenue_city,
- ];
-
- $this->venue = new GiglogAdmin_Venue($venue_attrs);
- }
- else {
- $this->venue = GiglogAdmin_Venue::get($attrs->venue);
+ if ( isset( $attrs->wpgvenue_name ) && isset( $attrs->wpgvenue_city ) ) {
+ $venue_attrs = (object) array(
+ 'id' => $attrs->venue,
+ 'wpgvenue_name' => $attrs->wpgvenue_name,
+ 'wpgvenue_city' => $attrs->wpgvenue_city,
+ );
+
+ $this->venue = new GiglogAdmin_Venue( $venue_attrs );
+ } else {
+ $this->venue = GiglogAdmin_Venue::get( $attrs->venue );
}
- }
- else {
- $this->venue = NULL;
+ } else {
+ $this->venue = null;
}
}
@@ -81,31 +77,33 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
* @param int $id
* @return null|self
*/
- static function get( int $id ) : ?self
- {
- return self::find_concerts(['id' => $id])[0];
+ static function get( int $id ) : ?self {
+ return self::find_concerts( array( 'id' => $id ) )[0];
}
- public static function create(string $name, int $venue_id, string $date, string $ticketlink, string $eventlink): ?self
- {
- $gigs = GiglogAdmin_Concert::find_concerts([
- 'name' => $name,
- 'venue_id' => $venue_id,
- 'date' => $date
- ]);
+ public static function create( string $name, int $venue_id, string $date, string $ticketlink, string $eventlink ): ?self {
+ $gigs = self::find_concerts(
+ array(
+ 'name' => $name,
+ 'venue_id' => $venue_id,
+ 'date' => $date,
+ )
+ );
- if (!empty($gigs)) {
+ if ( ! empty( $gigs ) ) {
throw new GiglogAdmin_DuplicateConcertException(
- "Duplicate concert: name: {$name}, venue_id: {$venue_id}, date: {$date}");
- }
- else {
- $concert = new GiglogAdmin_Concert( (object) [
- "wpgconcert_name" => $name,
- "venue" => $venue_id,
- "wpgconcert_date" => $date,
- "wpgconcert_tickets" => $ticketlink,
- "wpgconcert_event" => $eventlink,
- ]);
+ "Duplicate concert: name: {$name}, venue_id: {$venue_id}, date: {$date}"
+ );
+ } else {
+ $concert = new GiglogAdmin_Concert(
+ (object) array(
+ 'wpgconcert_name' => $name,
+ 'venue' => $venue_id,
+ 'wpgconcert_date' => $date,
+ 'wpgconcert_tickets' => $ticketlink,
+ 'wpgconcert_event' => $eventlink,
+ )
+ );
$concert->save();
@@ -114,54 +112,52 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
}
- public function update(object $attrs) : bool
- {
+ public function update( object $attrs ) : bool {
$need_update = false;
- if (isset($attrs->wpgconcert_name) && $attrs->wpgconcert_name != $this->cname) {
+ if ( isset( $attrs->wpgconcert_name ) && $attrs->wpgconcert_name != $this->cname ) {
$this->cname = $attrs->wpgconcert_name;
$need_update = true;
}
- if (isset($attrs->wpgconcert_date) && $attrs->wpgconcert_date != $this->cdate) {
+ if ( isset( $attrs->wpgconcert_date ) && $attrs->wpgconcert_date != $this->cdate ) {
$this->cdate = $attrs->wpgconcert_date;
$need_update = true;
}
- if (isset($attrs->wpgconcert_tickets) && $attrs->wpgconcert_tickets != $this->tickets) {
+ if ( isset( $attrs->wpgconcert_tickets ) && $attrs->wpgconcert_tickets != $this->tickets ) {
$this->tickets = $attrs->wpgconcert_tickets;
$need_update = true;
}
- if (isset($attrs->wpgconcert_event) && $attrs->wpgconcert_event != $this->eventlink) {
+ if ( isset( $attrs->wpgconcert_event ) && $attrs->wpgconcert_event != $this->eventlink ) {
$this->eventlink = $attrs->wpgconcert_eventlink;
$need_update = true;
}
- if (isset($attrs->wpgconcert_status) && $attrs->wpgconcert_status != $this->status) {
+ if ( isset( $attrs->wpgconcert_status ) && $attrs->wpgconcert_status != $this->status ) {
$this->status = $attrs->wpgconcert_status;
$need_update = true;
}
- if (isset($attrs->wpgconcert_roles) && $attrs->wpgconcert_roles != $this->roles) {
+ if ( isset( $attrs->wpgconcert_roles ) && $attrs->wpgconcert_roles != $this->roles ) {
$this->roles = $attrs->wpgconcert_roles;
$need_update = true;
}
- if (isset($attrs->venue) && $attrs->venue != $this->venue()->id()) {
- $this->venue = GiglogAdmin_Venue::get($attrs->venue);
+ if ( isset( $attrs->venue ) && $attrs->venue != $this->venue()->id() ) {
+ $this->venue = GiglogAdmin_Venue::get( $attrs->venue );
$need_update = true;
}
- if ($need_update) {
+ if ( $need_update ) {
$this->save();
}
return $need_update;
}
- private static function _build_query(array $filter = [], bool $count = false) : string
- {
+ private static function _build_query( array $filter = array(), bool $count = false ) : string {
global $wpdb;
$ct = "{$wpdb->prefix}giglogadmin_concerts";
@@ -169,63 +165,62 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
if ( $count ) {
$query = "SELECT count({$ct}.id) ";
- }
- else {
+ } else {
$query = "SELECT {$ct}.*, {$vt}.wpgvenue_name, {$vt}.wpgvenue_city ";
}
$query .= "FROM {$ct} LEFT JOIN {$vt} ON {$ct}.venue = {$vt}.id WHERE wpgconcert_date >= CURRENT_TIMESTAMP";
- $keymap = [
+ $keymap = array(
'id' => $wpdb->prefix . 'giglogadmin_concerts.id',
'name' => 'wpgconcert_name',
'date' => 'wpgconcert_date',
- 'month'=> 'MONTH(wpgconcert_date)',
+ 'month' => 'MONTH(wpgconcert_date)',
'venue_id' => $wpdb->prefix . 'giglogadmin_venues.id',
'venue' => $wpdb->prefix . 'giglogadmin_venues.wpgvenue_name',
'city' => $wpdb->prefix . 'giglogadmin_venues.wpgvenue_city',
'currentuser' => 'wpgconcert_roles',
- ];
+ );
- $where = [];
- $lmt=[];
- foreach( $filter as $key => $value ) {
- switch ($key) {
+ $where = array();
+ $lmt = array();
+ foreach ( $filter as $key => $value ) {
+ switch ( $key ) {
case 'name':
case 'date':
case 'month':
case 'venue':
case 'city':
- array_push($where, $wpdb->prepare($keymap[$key] . '=%s', $value));
+ array_push( $where, $wpdb->prepare( $keymap[ $key ] . '=%s', $value ) );
break;
case 'id':
case 'venue_id':
- array_push($where, $wpdb->prepare($keymap[$key] . '=%d', $value));
+ array_push( $where, $wpdb->prepare( $keymap[ $key ] . '=%d', $value ) );
break;
case 'currentuser':
- array_push($where, $wpdb->prepare($keymap[$key] . ' like "%%%s%%"', $value));
+ array_push( $where, $wpdb->prepare( $keymap[ $key ] . ' like "%%%s%%"', $value ) );
break;
case 'offset':
- array_push($lmt, $value);
+ array_push( $lmt, $value );
break;
case 'recperpage':
- array_push($lmt, $value);
+ array_push( $lmt, $value );
break;
}
}
if ( ! empty( $where ) ) {
- $query .= ' AND ' . implode(' and ', $where);
+ $query .= ' AND ' . implode( ' and ', $where );
}
$query .= ' ORDER BY wpgconcert_date';
if ( ! empty( $lmt ) ) {
- $query .= ' LIMIT ' . implode(', ', $lmt);
+ $query .= ' LIMIT ' . implode( ', ', $lmt );
}
return $query;
@@ -242,14 +237,18 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
* @param array<string, mixed> $filter
* @return array<GiglogAdmin_Concert>
*/
- public static function find_concerts(array $filter = []) : array
- {
+ public static function find_concerts( array $filter = array() ) : array {
global $wpdb;
- $query = Self::_build_query($filter, false);
- $results = $wpdb->get_results($query);
+ $query = self::_build_query( $filter, false );
+ $results = $wpdb->get_results( $query );
- return array_map(function($c) { return new GiglogAdmin_Concert($c); }, $results);
+ return array_map(
+ function( $c ) {
+ return new GiglogAdmin_Concert( $c );
+ },
+ $results
+ );
}
/**
@@ -258,21 +257,19 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
* @param array<string, mixed> $filter
* @return int
*/
- public static function count(array $filter = []) : int
- {
+ public static function count( array $filter = array() ) : int {
global $wpdb;
- $query = Self::_build_query($filter, true);
- $count = $wpdb->get_var($query);
+ $query = self::_build_query( $filter, true );
+ $count = $wpdb->get_var( $query );
return $count ? $count : 0;
}
- public function save() : void
- {
+ public function save() : void {
global $wpdb;
- $columns = [
+ $columns = array(
'wpgconcert_name' => $this->cname,
'venue' => $this->venue->id(),
'wpgconcert_date' => $this->cdate,
@@ -280,57 +277,47 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
'wpgconcert_event' => $this->eventlink,
'wpgconcert_status' => $this->status,
'wpgconcert_roles' => wp_json_encode( $this->roles ),
- ];
+ );
- if ( $this->id !== NULL ) {
- $res = $wpdb->update( $wpdb->prefix . 'giglogadmin_concerts', $columns, [ 'id' => $this->id ] );
- }
- else {
- $res = $wpdb->insert( $wpdb->prefix . 'giglogadmin_concerts', $columns);
+ if ( $this->id !== null ) {
+ $res = $wpdb->update( $wpdb->prefix . 'giglogadmin_concerts', $columns, array( 'id' => $this->id ) );
+ } else {
+ $res = $wpdb->insert( $wpdb->prefix . 'giglogadmin_concerts', $columns );
}
if ( $res === false ) {
$wpdb->print_error( __METHOD__ );
- }
- elseif ( $this->id === NULL ) {
+ } elseif ( $this->id === null ) {
$this->id = $wpdb->insert_id;
}
}
- public function id()
- {
- return $this->id;
+ public function id() {
+ return $this->id;
}
- public function cname()
- {
- return $this->cname;
+ public function cname() {
+ return $this->cname;
}
- public function venue()
- {
- return $this->venue;
+ public function venue() {
+ return $this->venue;
}
- public function cdate()
- {
- return $this->cdate;
+ public function cdate() {
+ return $this->cdate;
}
- public function tickets()
- {
- return $this->tickets;
+ public function tickets() {
+ return $this->tickets;
}
- public function eventlink()
- {
- return $this->eventlink;
+ public function eventlink() {
+ return $this->eventlink;
}
- public function status()
- {
- return $this->status;
+ public function status() {
+ return $this->status;
}
- public function set_status( int $new_status )
- {
- $this->status = $new_status;
+ public function set_status( int $new_status ) {
+ $this->status = $new_status;
}
/**
@@ -338,19 +325,16 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
*
* @return array<string, string>
*/
- public function roles() : array
- {
+ public function roles() : array {
return $this->roles;
}
- public function assign_role( string $role, string $username ) : void
- {
- $this->roles[$role] = $username;
+ public function assign_role( string $role, string $username ) : void {
+ $this->roles[ $role ] = $username;
}
- public function remove_user_from_roles( string $username ) : void
- {
- $this->roles = array_filter($this->roles, fn($u) => $u != $username);
+ public function remove_user_from_roles( string $username ) : void {
+ $this->roles = array_filter( $this->roles, fn( $u) => $u != $username );
}
public function created() : DateTimeImmutable {
@@ -362,4 +346,4 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
}
}
}
-?>
+
diff --git a/includes/giglog_visitor_display.php b/includes/giglog_visitor_display.php
index b4742f5..b803bec 100644
--- a/includes/giglog_visitor_display.php
+++ b/includes/giglog_visitor_display.php
@@ -4,11 +4,10 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-function display_giglog() : string
-{
+function display_giglog() : string {
$c = new GiglogAdmin_ConcertsTable();
return $c->render();
}
-add_shortcode('getconcerts', 'display_giglog');
-?>
+add_shortcode( 'getconcerts', 'display_giglog' );
+
diff --git a/includes/ical_export.php b/includes/ical_export.php
index 9a3b0c0..627c83b 100644
--- a/includes/ical_export.php
+++ b/includes/ical_export.php
@@ -7,46 +7,43 @@
use Kigkonsult\Icalcreator\Vcalendar;
-if ( ! class_exists( "GiglogAdmin_IcalExport" ) )
-{
- class Giglogadmin_IcalExport
- {
- static function textclean(string $txt) : string
- {
- $cleantext = preg_replace("/[^A-Za-z0-9 ]/", "",$txt);
- $cleantext = str_replace(' ','_',$cleantext);
- return($cleantext);
+if ( ! class_exists( 'GiglogAdmin_IcalExport' ) ) {
+ class Giglogadmin_IcalExport {
+
+ static function textclean( string $txt ) : string {
+ $cleantext = preg_replace( '/[^A-Za-z0-9 ]/', '', $txt );
+ $cleantext = str_replace( ' ', '_', $cleantext );
+ return( $cleantext );
}
- public static function export_ical()
- {
- $evid = $_GET['evid'];
+ public static function export_ical() {
+ $evid = $_GET['evid'];
- $concert = GiglogAdmin_Concert::get($evid);
- $cfullname = $concert->cname().' live at '. $concert->venue()->name() .', '.$concert->venue()->city();
- $cshortname=substr($cfullname,0,20);
- $fdate = strtotime($concert->cdate());
- $newformat = date('Ymd',$fdate);
- $filename='Concert '.$concert->venue()->name().' '.$newformat.' '.substr($concert->cname(),0,30);
- $filename=Giglogadmin_IcalExport::textclean($filename);
+ $concert = GiglogAdmin_Concert::get( $evid );
+ $cfullname = $concert->cname() . ' live at ' . $concert->venue()->name() . ', ' . $concert->venue()->city();
+ $cshortname = substr( $cfullname, 0, 20 );
+ $fdate = strtotime( $concert->cdate() );
+ $newformat = date( 'Ymd', $fdate );
+ $filename = 'Concert ' . $concert->venue()->name() . ' ' . $newformat . ' ' . substr( $concert->cname(), 0, 30 );
+ $filename = self::textclean( $filename );
// create a new calendar
- $vcalendar = Vcalendar::factory( [ Vcalendar::UNIQUE_ID => "kigkonsult.se", ] )
+ $vcalendar = Vcalendar::factory( array( Vcalendar::UNIQUE_ID => 'kigkonsult.se' ) )
// with calendaring info
->setMethod( Vcalendar::PUBLISH )
->setXprop(
Vcalendar::X_WR_CALNAME,
- "Calendar Sample"
+ 'Calendar Sample'
)
->setXprop(
Vcalendar::X_WR_CALDESC,
- "Concert ".$cfullname . ""
+ 'Concert ' . $cfullname . ''
)
->setXprop(
Vcalendar::X_WR_RELCALID,
- "3E26604A-50F4-4449-8B3E-E4F4932D05B5"
+ '3E26604A-50F4-4449-8B3E-E4F4932D05B5'
)
->setXprop(
Vcalendar::X_WR_TIMEZONE,
- "Europe/Oslo"
+ 'Europe/Oslo'
);
// create a new event
@@ -55,21 +52,19 @@ if ( ! class_exists( "GiglogAdmin_IcalExport" ) )
->setClass( Vcalendar::P_BLIC )
->setSequence( 1 )
// describe the event
- ->setSummary("".$cfullname."" )
- ->setDescription("".$cfullname."" )
- ->setComment ("".$cfullname."" )
+ ->setSummary( '' . $cfullname . '' )
+ ->setDescription( '' . $cfullname . '' )
+ ->setComment( '' . $cfullname . '' )
// place the event
- ->setLocation( "".$concert->venue()->name() .', '.$concert->venue()->city() ."" )
+ ->setLocation( '' . $concert->venue()->name() . ', ' . $concert->venue()->city() . '' )
// set the time
->setDtstart(
new DateTime(
- $newformat.'T190000',
+ $newformat . 'T190000',
new DateTimezone( 'Europe/Oslo' )
)
)
- ->setDuration ("PT4H")
-
- ;
+ ->setDuration( 'PT4H' );
$vcalendarString =
// apply appropriate Vtimezone with Standard/DayLight components
$vcalendar->vtimezonePopulate()
@@ -77,15 +72,15 @@ if ( ! class_exists( "GiglogAdmin_IcalExport" ) )
->createCalendar();
header( 'Content-Type: text/calendar' );
- header( 'content-disposition: attachment;filename='.$filename.'.ics');
+ header( 'content-disposition: attachment;filename=' . $filename . '.ics' );
echo $vcalendarString;
die();
}
}
/** @psalm-suppress HookNotFound */
- add_action( 'wp_ajax_nopriv_giglog_export_ical', [ 'GiglogAdmin_IcalExport', 'export_ical' ] );
+ add_action( 'wp_ajax_nopriv_giglog_export_ical', array( 'GiglogAdmin_IcalExport', 'export_ical' ) );
/** @psalm-suppress HookNotFound */
- add_action( 'wp_ajax_giglog_export_ical', [ 'GiglogAdmin_IcalExport', 'export_ical' ] );
+ add_action( 'wp_ajax_giglog_export_ical', array( 'GiglogAdmin_IcalExport', 'export_ical' ) );
}
diff --git a/includes/venue.php b/includes/venue.php
index 3cbf884..b6f9956 100644
--- a/includes/venue.php
+++ b/includes/venue.php
@@ -4,9 +4,9 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
-if ( !class_exists('GiglogAdmin_Venue') ) {
- class GiglogAdmin_Venue
- {
+if ( ! class_exists( 'GiglogAdmin_Venue' ) ) {
+ class GiglogAdmin_Venue {
+
private ?int $id;
/**
@@ -27,21 +27,19 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
* so this constructor can be used to construct the object
* directly from the database row.
*/
- public function __construct(object $attrs)
- {
- $this->id = isset($attrs->id) ? $attrs->id : NULL;
+ public function __construct( object $attrs ) {
+ $this->id = isset( $attrs->id ) ? $attrs->id : null;
- if (isset($attrs->wpgvenue_name, $attrs->wpgvenue_city)) {
+ if ( isset( $attrs->wpgvenue_name, $attrs->wpgvenue_city ) ) {
$this->name = $attrs->wpgvenue_name;
$this->city = $attrs->wpgvenue_city;
- }
- else {
- error_log('Trying to construct a Venue without a name or a city');
+ } else {
+ error_log( 'Trying to construct a Venue without a name or a city' );
wp_die();
}
- $this->address = isset($attrs->wpgvenue_address) ? $attrs->wpgvenue_address : NULL;
- $this->webpage = isset($attrs->wpgvenue_webpage) ? $attrs->wpgvenue_webpage : NULL;
+ $this->address = isset( $attrs->wpgvenue_address ) ? $attrs->wpgvenue_address : null;
+ $this->webpage = isset( $attrs->wpgvenue_webpage ) ? $attrs->wpgvenue_webpage : null;
}
/**
@@ -50,50 +48,53 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
* @param int $id
* @return null|self
*/
- static function get(int $id) : ?self
- {
+ static function get( int $id ) : ?self {
global $wpdb;
- $query = $wpdb->prepare("SELECT * from {$wpdb->prefix}giglogadmin_venues WHERE id = %d", $id);
- $results = $wpdb->get_results($query);
+ $query = $wpdb->prepare( "SELECT * from {$wpdb->prefix}giglogadmin_venues WHERE id = %d", $id );
+ $results = $wpdb->get_results( $query );
- return $results ? new GiglogAdmin_Venue($results[0]) : NULL;
+ return $results ? new GiglogAdmin_Venue( $results[0] ) : null;
}
- static function create(string $name, string $city = 'Oslo'): self
- {
- $venue = new GiglogAdmin_Venue((object) [
- 'wpgvenue_name' => $name,
- 'wpgvenue_city' => $city,
- ]);
+ static function create( string $name, string $city = 'Oslo' ): self {
+ $venue = new GiglogAdmin_Venue(
+ (object) array(
+ 'wpgvenue_name' => $name,
+ 'wpgvenue_city' => $city,
+ )
+ );
$venue->save();
return $venue;
}
- static function find_or_create(string $name, string $city = 'Oslo'): self
- {
+ static function find_or_create( string $name, string $city = 'Oslo' ): self {
global $wpdb;
$venuesql = "SELECT * FROM {$wpdb->prefix}giglogadmin_venues "
- . $wpdb->prepare("WHERE upper(wpgvenue_name)=upper(%s) and upper(wpgvenue_city)=upper(%s)", $name, $city);
+ . $wpdb->prepare( 'WHERE upper(wpgvenue_name)=upper(%s) and upper(wpgvenue_city)=upper(%s)', $name, $city );
- $results = $wpdb->get_results($venuesql);
+ $results = $wpdb->get_results( $venuesql );
- if ($results) {
- return new GiglogAdmin_Venue($results[0]);
- }
- else {
- return GiglogAdmin_Venue::create($name, $city);
+ if ( $results ) {
+ return new GiglogAdmin_Venue( $results[0] );
+ } else {
+ return self::create( $name, $city );
}
}
- static function all_cities(): array
- {
+ static function all_cities(): array {
global $wpdb;
$results = $wpdb->get_results(
- "select distinct wpgvenue_city from {$wpdb->prefix}giglogadmin_venues");
-
- return array_map(function ($r) { return $r->wpgvenue_city; }, $results);
+ "select distinct wpgvenue_city from {$wpdb->prefix}giglogadmin_venues"
+ );
+
+ return array_map(
+ function ( $r ) {
+ return $r->wpgvenue_city;
+ },
+ $results
+ );
}
/**
@@ -101,14 +102,19 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
*
* @psalm-return array<array-key, self>
*/
- static function all_venues(): array
- {
+ static function all_venues(): array {
global $wpdb;
$results = $wpdb->get_results(
- "select * from {$wpdb->prefix}giglogadmin_venues ORDER BY wpgvenue_name");
-
- return array_map(function ($r) { return new GiglogAdmin_Venue($r); }, $results);
+ "select * from {$wpdb->prefix}giglogadmin_venues ORDER BY wpgvenue_name"
+ );
+
+ return array_map(
+ function ( $r ) {
+ return new GiglogAdmin_Venue( $r );
+ },
+ $results
+ );
}
@@ -117,42 +123,45 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
*
* @psalm-return array<array-key, self>
*/
- static function venues_in_city(string $city): array
- {
+ static function venues_in_city( string $city ): array {
global $wpdb;
- $q = $wpdb->prepare("select * from {$wpdb->prefix}giglogadmin_venues where wpgvenue_city=%s", $city)
- . " ORDER BY wpgvenue_name";
- $results = $wpdb->get_results($q);
-
- return array_map(function ($r) { return new GiglogAdmin_Venue($r); }, $results);
+ $q = $wpdb->prepare( "select * from {$wpdb->prefix}giglogadmin_venues where wpgvenue_city=%s", $city )
+ . ' ORDER BY wpgvenue_name';
+ $results = $wpdb->get_results( $q );
+
+ return array_map(
+ function ( $r ) {
+ return new GiglogAdmin_Venue( $r );
+ },
+ $results
+ );
}
- public function save(): void
- {
+ public function save(): void {
global $wpdb;
- $wpdb->insert($wpdb->prefix . 'giglogadmin_venues', array(
- 'id' => '',
- 'wpgvenue_name' => $this->name,
- 'wpgvenue_city' => $this->city,
- ));
+ $wpdb->insert(
+ $wpdb->prefix . 'giglogadmin_venues',
+ array(
+ 'id' => '',
+ 'wpgvenue_name' => $this->name,
+ 'wpgvenue_city' => $this->city,
+ )
+ );
$this->id = $wpdb->insert_id;
}
- public function id()
- {
- return $this->id;
+ public function id() {
+ return $this->id;
}
- public function name()
- {
- return $this->name;
+ public function name() {
+ return $this->name;
}
- public function city()
- {
- return $this->city;
+ public function city() {
+ return $this->city;
}
}
}
diff --git a/includes/view-helpers/select_field.php b/includes/view-helpers/select_field.php
index e72fc40..aa156d0 100644
--- a/includes/view-helpers/select_field.php
+++ b/includes/view-helpers/select_field.php
@@ -19,13 +19,12 @@ namespace EternalTerror\ViewHelpers;
*/
function select_field(
string $name,
- array $opts = [],
+ array $opts = array(),
$selected = null,
- string $blank = "Please select...") : string
-{
+ string $blank = 'Please select...' ) : string {
$body = "<option value=\"\">{$blank}</option>";
- foreach ($opts as $opt) {
- $sel = selected($selected, $opt[0], false);
+ foreach ( $opts as $opt ) {
+ $sel = selected( $selected, $opt[0], false );
$body .= "<option value=\"{$opt[0]}\"{$sel}>{$opt[1]}</option>";
}
return "<select name=\"{$name}\">{$body}</select>";