From 0e42a12a33b9bb193fa7851628edf018bd922362 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 18 Jun 2022 11:38:26 +0200 Subject: Add phpcs config and do automatic fixups. --- includes/admin/views/_concerts_table.php | 295 ++++++++++++++----------------- 1 file changed, 137 insertions(+), 158 deletions(-) (limited to 'includes/admin/views/_concerts_table.php') 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 = '
'; - $content.= '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.'; + $content .= '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.'; - $content.= ''; - $content.= ''; + $content .= ''; + $content .= ''; - if (!is_admin()) { + if ( ! is_admin() ) { $content .= ''; - } - else { + } else { $content .= ''; - if (current_user_can('administrator')) { + if ( current_user_can( 'administrator' ) ) { $content .= ''; } } @@ -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 = '
' . ''; - if($this->page_no > 1) { + if ( $this->page_no > 1 ) { $content .= '' - . '' + . '' . 'First Page -' . '' . '' @@ -265,14 +251,14 @@ if (!class_exists("GiglogAdmin_ConcertsTable")) $content .= ''; - if ($this->page_no < $this->total_no_of_pages) { + if ( $this->page_no < $this->total_no_of_pages ) { $content .= '' . '' . 'Next - ' . '' . '' - . '' + . '' . 'Last Page' . ''; } @@ -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 .= '
'; $content .= - "" - . "" - . ""; + '' + . '' + . ''; - if( is_admin() ) { - $content .= ''; + if ( is_admin() ) { + $content .= ''; - foreach ( [ 'photo1', 'photo2', 'rev1', 'rev2' ] as $role ) { + foreach ( array( 'photo1', 'photo2', 'rev1', 'rev2' ) as $role ) { $content .= ''; } - $content .= ''; + $content .= ''; - if (current_user_can('administrator')) { + if ( current_user_can( 'administrator' ) ) { $content .= ""; } - } - else { - $content .= ""; - $content .= ""; + } else { + $content .= ''; + $content .= ''; } - $content .= ''; + $content .= ''; $content .= ''; $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 .= '

'; // return the table return $content; } - private function render_filters() : string - { + private function render_filters() : string { global $wp_locale; $select = '

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 .= ''; - if(is_admin()) { - //option to select own concerts only + if ( is_admin() ) { + // option to select own concerts only $select .= 'get_filter( 'current_user' ) ) . '>'; } - //NOTE that I remvoed

and mvoed them up to render_concerts_table function + // NOTE that I remvoed

and mvoed them up to render_concerts_table function $select .= ''; return $select; } - private function adminactions( GiglogAdmin_Concert $concert ) : string - { - return - '' + private function adminactions( GiglogAdmin_Concert $concert ) : string { + return '' . '' - . '' + . '' . \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() + ) . '' . '' . ''; @@ -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 'NEW'; - } - 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 = '' . ' ' @@ -447,20 +429,17 @@ if (!class_exists("GiglogAdmin_ConcertsTable")) . ' ' . ' ' . ''; - } - elseif ( $assigned_user ) { //check if slot is taken by another user + } elseif ( $assigned_user ) { // check if slot is taken by another user $f = 'Taken' . '
Taken by ' . $assigned_user . '
'; - } - elseif ( array_search($this->username, $roles) ) { + } elseif ( array_search( $this->username, $roles ) ) { // other slots for this concert are taken by user $f = '-'; - } - else { //not taken by anyone + } else { // not taken by anyone $f = '' . ' ' . ' ' - . ' ' + . ' ' . ' ' . ''; } -- cgit v1.2.3
CITYDATENAMEVENUE
CITYDATENAMEVENUEEVENTTICKETSCalendarPHOTO1PHOTO2TEXT1TEXT2STATUSAdminOptions
'; - if ($last_city != $concert->venue()->city()) { + if ( $last_city != $concert->venue()->city() ) { $content .= $concert->venue()->city(); } $content .= '" . date( 'd.M.Y', strtotime( $concert->cdate() ) ) . "" . strtoupper(esc_html($concert->cname())) . "" . esc_html($concert->venue()->name()) . "' . date( 'd.M.Y', strtotime( $concert->cdate() ) ) . '' . strtoupper( esc_html( $concert->cname() ) ) . '' . esc_html( $concert->venue()->name() ) . '' . $this->mark_new_concert($concert) . '' . $this->mark_new_concert( $concert ) . '' . $this->assign_role_for_user_form( $role, $concert ) . '' . self::STATUS_LABELS[$concert->status()] . '' . self::STATUS_LABELS[ $concert->status() ] . '{$this->adminactions( $concert )}eventlink()) . "\">Linktickets()) . "\">TicketsLinkTickets iCal iCal