Skip to content

Commit

Permalink
Merge branch 'trunk' into delete-button
Browse files Browse the repository at this point in the history
  • Loading branch information
amieiro authored Feb 15, 2024
2 parents 9fd3d62 + d21f915 commit e8d2fcd
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
composer-options: "--no-progress --no-ansi --no-interaction"

- name: Run PHPCS
run: vendor/bin/phpcs -q --report=checkstyle | cs2pr --notices-as-warnings
run: vendor/bin/phpcs --standard=phpcs.xml -q --report=checkstyle | cs2pr --notices-as-warnings
61 changes: 48 additions & 13 deletions includes/class-wporg-gp-translation-events-route.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class WPORG_GP_Translation_Events_Route extends GP_Route {
* @since 0.0.1
*/
public function __construct() {
$this->template_path = dirname( __FILE__ ) . '/../templates/';
parent::__construct();
$this->template_path = __DIR__ . '/../templates/';
}

/**
Expand All @@ -23,16 +24,40 @@ public function __construct() {
* @return void
*/
public function events_list() {
$current_datetime_utc = ( new DateTime( 'now', new DateTimeZone( 'UTC' ) ) )->format( 'Y-m-d H:i:s' );
$_current_events_paged = isset( $_GET['current_events_paged'] ) && is_numeric( $_GET['current_events_paged'] ) ? $_GET['current_events_paged'] : 1;
$_upcoming_events_paged = isset( $_GET['upcoming_events_paged'] ) && is_numeric( $_GET['upcoming_events_paged'] ) ? $_GET['upcoming_events_paged'] : 1;
$current_datetime_utc = null;
try {
$current_datetime_utc = ( new DateTime( 'now', new DateTimeZone( 'UTC' ) ) )->format( 'Y-m-d H:i:s' );
} catch ( Exception $e ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( $e );
$this->die_with_error( 'Something is wrong.' );
}

$_current_events_paged = 1;
$_upcoming_events_paged = 1;

// phpcs:disable WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['current_events_paged'] ) ) {
$value = sanitize_text_field( wp_unslash( $_GET['current_events_paged'] ) );
if ( is_numeric( $value ) ) {
$_current_events_paged = (int) $value;
}
}
if ( isset( $_GET['upcoming_events_paged'] ) ) {
$value = sanitize_text_field( wp_unslash( $_GET['upcoming_events_paged'] ) );
if ( is_numeric( $value ) ) {
$_upcoming_events_paged = (int) $value;
}
}
// phpcs:enable

$current_events_args = array(
'post_type' => 'event',
'posts_per_page' => 10,
'current_events_paged' => $_current_events_paged,
'paged' => $_current_events_paged,
'post_status' => 'publish',
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'meta_query' => array(
array(
'key' => '_event_start',
Expand All @@ -58,6 +83,7 @@ public function events_list() {
'upcoming_events_paged' => $_upcoming_events_paged,
'paged' => $_upcoming_events_paged,
'post_status' => 'publish',
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'meta_query' => array(
array(
'key' => '_event_start',
Expand Down Expand Up @@ -91,6 +117,7 @@ public function events_create() {
$event_timezone = '';

Check warning on line 117 in includes/class-wporg-gp-translation-events-route.php

View workflow job for this annotation

GitHub Actions / PHP

Equals sign not aligned with surrounding assignments; expected 11 spaces but found 13 spaces
$event_start = '';

Check warning on line 118 in includes/class-wporg-gp-translation-events-route.php

View workflow job for this annotation

GitHub Actions / PHP

Equals sign not aligned with surrounding assignments; expected 14 spaces but found 16 spaces
$event_end = '';

Check warning on line 119 in includes/class-wporg-gp-translation-events-route.php

View workflow job for this annotation

GitHub Actions / PHP

Equals sign not aligned with surrounding assignments; expected 16 spaces but found 18 spaces
$event_url = '';

Check failure on line 120 in includes/class-wporg-gp-translation-events-route.php

View workflow job for this annotation

GitHub Actions / PHP

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 120 in includes/class-wporg-gp-translation-events-route.php

View workflow job for this annotation

GitHub Actions / PHP

Line indented incorrectly; expected at least 2 tabs, found 1

Check warning on line 120 in includes/class-wporg-gp-translation-events-route.php

View workflow job for this annotation

GitHub Actions / PHP

Equals sign not aligned with surrounding assignments; expected 20 spaces but found 18 spaces
$create_delete_button = true;
$visibility_delete_button = 'none';

Expand All @@ -104,7 +131,7 @@ public function events_create() {
*
* @return void
*/
public function events_edit( $event_id ) {
public function events_edit( int $event_id ) {
if ( ! is_user_logged_in() ) {
$this->die_with_error( 'You must be logged in to edit an event', 403 );
}
Expand All @@ -122,21 +149,29 @@ public function events_edit( $event_id ) {
$css_show_url = '';
$event_title = $event->post_title;
$event_description = $event->post_content;
$event_timezone = get_post_meta( $event_id, '_event_timezone', true ) ?: '';
$event_start = self::convertToTimezone( get_post_meta( $event_id, '_event_start', true ), $event_timezone ) ?? '';
$event_end = self::convertToTimezone( get_post_meta( $event_id, '_event_end', true ), $event_timezone ) ?? '';
$event_status = $event->post_status;
list( $permalink, $post_name ) = get_sample_permalink( $event_id );
$permalink = str_replace( '%pagename%', $post_name, $permalink );
$event_url = get_site_url() . gp_url( wp_make_link_relative( $permalink ) );
$event_timezone = get_post_meta( $event_id, '_event_timezone', true ) ?: '';
$create_delete_button = false;
$visibility_delete_button = 'inline-flex';

Check failure on line 159 in includes/class-wporg-gp-translation-events-route.php

View workflow job for this annotation

GitHub Actions / PHP

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 159 in includes/class-wporg-gp-translation-events-route.php

View workflow job for this annotation

GitHub Actions / PHP

Whitespace found at end of line
$stats_calculator = new WPORG_GP_Translation_Events_Stats_Calculator();
if ( ! $stats_calculator->event_has_stats( $event ) ) {
$current_user = wp_get_current_user();
if ( $current_user->ID === $event->post_author || current_user_can( 'manage_options' ) ) {
$create_delete_button = true;
}
}

Check failure on line 166 in includes/class-wporg-gp-translation-events-route.php

View workflow job for this annotation

GitHub Actions / PHP

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 166 in includes/class-wporg-gp-translation-events-route.php

View workflow job for this annotation

GitHub Actions / PHP

Line indented incorrectly; expected 2 tabs, found 1

try {
$event_start = self::convertToTimezone( get_post_meta( $event_id, '_event_start', true ), $event_timezone );
$event_end = self::convertToTimezone( get_post_meta( $event_id, '_event_end', true ), $event_timezone );
} catch ( Exception $e ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( $e );
$this->die_with_error( 'Something is wrong.' );
}

$this->tmpl( 'events-form', get_defined_vars() );
Expand All @@ -149,7 +184,7 @@ public function events_edit( $event_id ) {
*
* @return void
*/
public function events_details( $event_slug ) {
public function events_details( string $event_slug ) {
$user = wp_get_current_user();
$event = get_page_by_path( $event_slug, OBJECT, 'event' );
if ( ! $event ) {
Expand All @@ -168,6 +203,7 @@ public function events_details( $event_slug ) {
try {
$event_stats = $stats_calculator->for_event( $event );
} catch ( Exception $e ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( $e );
$this->die_with_error( 'Failed to calculate event stats' );
}
Expand All @@ -179,8 +215,6 @@ public function events_details( $event_slug ) {
* Toggle whether the current user is attending an event.
* If the user is not currently marked as attending, they will be marked as attending.
* If the user is currently marked as attending, they will be marked as not attending.
*
* @param int $event_id
*/
public function events_attend( int $event_id ) {
$user = wp_get_current_user();
Expand Down Expand Up @@ -246,8 +280,9 @@ public function events_user_created() {
* @param string $time_zone The time zone.
*
* @return string The date time in the time zone.
* @throws Exception When date is invalid.
*/
public static function convertToTimezone( $date_time, $time_zone ) {
public static function convertToTimezone( string $date_time, string $time_zone ): string {
return ( new DateTime( $date_time, new DateTimeZone( 'UTC' ) ) )->setTimezone( new DateTimeZone( $time_zone ) )->format( 'Y-m-d H:i:s' );
}
}
8 changes: 2 additions & 6 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
<arg name="colors"/>
<arg name="extensions" value="php"/>

<!--
<file>./includes/</file>
<file>./templates/</file>
<file>./tests/</file>
-->
<file>./includes/class-wporg-gp-translation-events-active-events-cache.php</file>
<file>./includes/class-wporg-gp-translation-events-event.php</file>
<file>./includes/class-wporg-gp-translation-events-stats-calculator.php</file>
<file>./includes/class-wporg-gp-translation-events-translation-listener.php</file>
<file>./wporg-gp-translation-events.php</file>

<rule ref="WordPress">
Expand All @@ -25,5 +19,7 @@
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag"/>
<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
<exclude name="Generic.Files.OneObjectStructurePerFile.MultipleFound"/>
<exclude name="Universal.Operators.DisallowShortTernary.Found"/>
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
</rule>
</ruleset>
41 changes: 23 additions & 18 deletions templates/event.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
<?php
/**
* Template for event page.
*/

/** @var WP_Post $event */
/** @var int $event_id */
/** @var string $event_title */
/** @var string $event_description */
/** @var string $event_start_date */
/** @var string $event_start */
/** @var string $event_end */
/** @var bool $user_is_attending */
/** @var WPORG_GP_Translation_Events_Event_Stats $event_stats */

/* translators: %s: Event title. */
gp_title( sprintf( __( 'Translation Events - %s' ), esc_html( $event_title ) ) );
gp_tmpl_header();
gp_tmpl_load( 'events-header', get_defined_vars(), dirname( __FILE__ ) );

gp_tmpl_load( 'events-header', get_defined_vars(), __DIR__ );
?>

<div class="event-details-page">
<div class="event-details-head">
<h1>
<?php echo esc_html( $event_title ); ?>
<?php if ( 'draft' === $event->post_status ): ?>
<?php if ( 'draft' === $event->post_status ) : ?>
<span class="event-label-draft"><?php echo esc_html( $event->post_status ); ?></span>
<?php endif; ?>
</h1>
Expand All @@ -32,19 +37,19 @@
<div class="event-details-date">
<p><span class="dashicons dashicons-clock"></span> <time class="event-utc-time" datetime="<?php echo esc_attr( $event_start ); ?>"></time> - <time class="event-utc-time" datetime="<?php echo esc_attr( $event_end ); ?>"></time></p>
</div>
<?php if ( is_user_logged_in() ) : ?>
<?php if ( is_user_logged_in() ) : ?>
<div class="event-details-join">
<form class="event-details-attend" method="post" action="<?php echo esc_url( gp_url( "/events/attend/$event_id" ) )?>">
<?php if ( ! $user_is_attending ): ?>
<form class="event-details-attend" method="post" action="<?php echo esc_url( gp_url( "/events/attend/$event_id" ) ); ?>">
<?php if ( ! $user_is_attending ) : ?>
<input type="submit" class="button is-primary" value="Attend Event"/>
<?php else: ?>
<?php else : ?>
<input type="submit" class="button is-secondary" value="You're attending"/>
<?php endif ?>
</form>
</div>
<?php endif; ?>
</div>
<?php if ( ! empty( $event_stats->rows() ) ):?>
<?php if ( ! empty( $event_stats->rows() ) ) : ?>
<div class="event-details-stats">
<h2>Stats</h2>
<table>
Expand All @@ -57,20 +62,20 @@
</tr>
</thead>
<tbody>
<?php /** @var $row WPORG_GP_Translation_Events_Stats_Row */?>
<?php foreach ( $event_stats->rows() as $locale => $row ): ?>
<?php /** @var $row WPORG_GP_Translation_Events_Stats_Row */ ?>
<?php foreach ( $event_stats->rows() as $locale_ => $row ) : ?>
<tr>
<td><?php echo esc_html( $locale ) ?></td>
<td><?php echo esc_html( $row->created ) ?></td>
<td><?php echo esc_html( $row->reviewed ) ?></td>
<td><?php echo esc_html( $row->users ) ?></td>
<td><?php echo esc_html( $locale_ ); ?></td>
<td><?php echo esc_html( $row->created ); ?></td>
<td><?php echo esc_html( $row->reviewed ); ?></td>
<td><?php echo esc_html( $row->users ); ?></td>
</tr>
<?php endforeach ?>
<tr class="event-details-stats-totals">
<td>Total</td>
<td><?php echo esc_html( $event_stats->totals()->created ) ?></td>
<td><?php echo esc_html( $event_stats->totals()->reviewed ) ?></td>
<td><?php echo esc_html( $event_stats->totals()->users ) ?></td>
<td><?php echo esc_html( $event_stats->totals()->created ); ?></td>
<td><?php echo esc_html( $event_stats->totals()->reviewed ); ?></td>
<td><?php echo esc_html( $event_stats->totals()->users ); ?></td>
</tr>
</tbody>
</table>
Expand Down
19 changes: 17 additions & 2 deletions templates/events-form.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
<?php
/**
* Template for event form.
*/

/** @var string $event_form_title */
/** @var string $event_form_name */
/** @var int $event_id */
/** @var string $event_title */
/** @var string $event_description */
/** @var string $event_start */
/** @var string $event_end */
/** @var string $event_timezone */
/** @var string $event_url */
/** @var string $css_show_url */

gp_title( __( 'Translation Events' ) . ' - ' . esc_html( $event_form_title . ' - ' . $event_title ) );
gp_tmpl_header();
gp_tmpl_load( 'events-header', get_defined_vars(), dirname( __FILE__ ) );
gp_tmpl_load( 'events-header', get_defined_vars(), __DIR__ );
?>

<h2 class="event-page-title"><?php echo esc_html( $event_form_title ); ?></h2>
Expand All @@ -17,7 +32,7 @@
</div>
<div id="event-url" class="<?php echo esc_attr( $css_show_url ); ?>">
<label for="event-permalink">Event URL</label>
<a id="event-permalink" class="event-permalink" href="<?php echo esc_url( gp_url( wp_make_link_relative( $permalink ) ) ) ?>" target="_blank"><?php echo esc_url( get_site_url() . gp_url( wp_make_link_relative( $permalink ) ) ) ?></a>
<a id="event-permalink" class="event-permalink" href="<?php echo esc_url( $event_url ); ?>" target="_blank"><?php echo esc_url( $event_url ); ?></a>
</div>
<div>
<label for="event-description">Event Description</label>
Expand Down
Loading

0 comments on commit e8d2fcd

Please sign in to comment.