Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include a Base layer for Settings and Commerce fieldsets #2922

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ Check out our extensive [knowledgebase](https://evnt.is/18wm) for articles on us

== Changelog ==

* Tweak - Include Telemetry data points to help us understand how the plugin is being used so we can remove deprecated code and add features later.

= [5.8.0] 2024-01-22 =

* Version - Event Tickets 5.8.0 is only compatible with The Events Calendar 6.3.0 and higher.
Expand Down
116 changes: 116 additions & 0 deletions src/Tickets/Site_Health/Contracts/Fieldset_Abstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
bordoni marked this conversation as resolved.
Show resolved Hide resolved
/**
* Abstract Contract for the Fieldset that handles setting up a group of fields for the Site Health page.
*
* @since TBD
*
* @package TEC\Tickets\Site_Health\Contracts
*/
bordoni marked this conversation as resolved.
Show resolved Hide resolved
namespace TEC\Tickets\Site_Health\Contracts;

use TEC\Common\Site_Health\Fields\Generic_Info_Field;
use TEC\Common\Site_Health\Info_Field_Abstract;
use TEC\Common\Site_Health\Info_Section_Abstract;

/**
* Abstract Class Fieldset_Abstract
*
* @since TBD
*
* @package TEC\Tickets\Site_Health\Contracts
*/
abstract class Fieldset_Abstract implements Fieldset_Interface {

/**
* The value for yes, intentionally not translated.
*
* @since TBD
*
* @var string
*/
protected const YES = 'yes';

/**
* The value for no, intentionally not translated.
*
* @since TBD
*
* @var string
*/
protected const NO = 'no';

/**
* Stores the base priority for the fields in this set.
*
* @since TBD
*
* @var float $priority
*/
protected float $priority = 10.0;

/**
* Every time you get the priority it adds a bit to it, allowing fields to be grouped together.
*
* @since TBD
*
* @return float
*/
protected function get_priority(): float {
return $this->priority + 0.1;
}

/**
bordoni marked this conversation as resolved.
Show resolved Hide resolved
* @inheritdoc
*/
public function register_fields_to( Info_Section_Abstract $section ): void {
$fields = $this->to_array();

foreach ( $fields as $field ) {
$section->add_field( $field );
}
}

/**
* Get the fields for this fieldset.
*
* @since TBD
*
* @return array<Info_Field_Abstract|array>
*/
abstract protected function get_fields(): array;

/**
* @inheritdoc
*/
public function to_array(): array {
$fields = array_map(
function ( $field ) {
if ( $field instanceof Info_Field_Abstract ) {
return $field;
}

if ( ! is_array( $field ) ) {
return null;
}

if ( is_callable( $field['value'] ) ) {
$field['value'] = call_user_func_array( $field['value'], [] );
}

if ( ! isset( $field['priority'] ) ) {
$field['priority'] = $this->get_priority();
}

return Generic_Info_Field::from_array( $field );
},
$this->get_fields()
);

return array_filter(
$fields,
static function ( $field ) {
return $field instanceof Info_Field_Abstract;
}
);
}
}
bordoni marked this conversation as resolved.
Show resolved Hide resolved
41 changes: 41 additions & 0 deletions src/Tickets/Site_Health/Contracts/Fieldset_Interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
bordoni marked this conversation as resolved.
Show resolved Hide resolved
/**
* Interface Contract for the Fieldset that handles setting up a group of fields for the Site Health page.
*
* @since TBD
*
* @package TEC\Tickets\Site_Health\Contracts
*/
bordoni marked this conversation as resolved.
Show resolved Hide resolved
namespace TEC\Tickets\Site_Health\Contracts;

use TEC\Common\Site_Health\Info_Section_Abstract;

/**
* Interface Fieldset_Interface
*
* @since TBD
*
* @package TEC\Tickets\Site_Health\Contracts
*/
interface Fieldset_Interface {

/**
* Register the fields to the section.
*
* @since TBD
*
* @param Info_Section_Abstract $section
bordoni marked this conversation as resolved.
Show resolved Hide resolved
*
*/
bordoni marked this conversation as resolved.
Show resolved Hide resolved
public function register_fields_to( Info_Section_Abstract $section ): void;

/**
* Convert the fields to an array of Info_Field_Abstract.
*
* @since TBD
*
* @return array
*/
public function to_array(): array;

}
bordoni marked this conversation as resolved.
Show resolved Hide resolved
bordoni marked this conversation as resolved.
Show resolved Hide resolved
121 changes: 121 additions & 0 deletions src/Tickets/Site_Health/Fieldset/Commerce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
bordoni marked this conversation as resolved.
Show resolved Hide resolved
/**
* Fieldset for Commerce related fields in the Site Health page.
*
* @since TBD
*
* @package TEC\Tickets\Site_Health\Fieldset
*/
bordoni marked this conversation as resolved.
Show resolved Hide resolved
namespace TEC\Tickets\Site_Health\Fieldset;

use TEC\Tickets\Commerce\Gateways\Manager;
bordoni marked this conversation as resolved.
Show resolved Hide resolved
use TEC\Tickets\Commerce\Gateways\PayPal\Gateway as PayPal_Gateway;
use TEC\Tickets\Commerce\Gateways\Stripe\Gateway as Stripe_Gateway;
use TEC\Tickets\Site_Health\Contracts\Fieldset_Abstract;

/**
* Class Commerce
*
* @since TBD
*
* @package TEC\Tickets\Site_Health\Fieldset
*/
class Commerce extends Fieldset_Abstract {

/**
* @inheritdoc
*/
bordoni marked this conversation as resolved.
Show resolved Hide resolved
protected float $priority = 20.0;

/**
* @inheritdoc
*/
protected function get_fields(): array {
return [
[
'id' => 'tickets_commerce_enabled',
'label' => esc_html__( 'Tickets Commerce Enabled', 'event-tickets' ),
'value' => [ $this, 'is_tickets_commerce_enabled' ],
],
[
'id' => 'tickets_commerce_sandbox_mode',
'label' => esc_html__( 'Tickets Commerce Sandbox Mode', 'event-tickets' ),
'value' => [ $this, 'is_tickets_commerce_sandbox_mode' ],
],
[
'id' => 'tribe_commerce_is_available',
'label' => esc_html__( 'Tribe Commerce Available', 'event-tickets' ),
'value' => [ $this, 'is_tribe_commerce_available' ],
],
[
'id' => 'tickets_commerce_gateway_stripe_active',
'label' => esc_html__( 'Tickets Commerce gateway Stripe active', 'event-tickets' ),
'value' => [ $this, 'is_tc_stripe_active' ],
],
[
'id' => 'tickets_commerce_gateway_paypal_active',
'label' => esc_html__( 'Tickets Commerce gateway PayPal active', 'event-tickets' ),
'value' => [ $this, 'is_tc_paypal_active' ],
],
];
}

/**
* Check if Tickets Commerce is enabled.
*
* @since TBD
*
* @return string
*/
public function is_tickets_commerce_enabled(): string {
return tec_tickets_commerce_is_enabled() ? static::YES : static::NO;
}

/**
* Check if Tickets Commerce is in sandbox mode.
*
* @since TBD
*
* @return string
*/
public function is_tickets_commerce_sandbox_mode(): string {
return tec_tickets_commerce_is_sandbox_mode() ? static::YES : static::NO;
}

/**
* Check if Tribe Commerce is available.
*
* @since TBD
*
* @return string
*/
public function is_tribe_commerce_available(): string {
return tec_tribe_commerce_is_available() ? static::YES : static::NO;
}

/**
* Check if the Stripe payment gateway is active.
*
* @since TBD
*
* @return string
*/
public function is_tc_stripe_active(): string {
$gateway = tribe( Manager::class )->get_gateway_by_key( Stripe_Gateway::get_key() );

return tec_tickets_commerce_is_enabled() && $gateway::is_active() && $gateway::is_enabled() ? static::YES : static::NO;
}

/**
* Check if the PayPal payment gateway is active.
*
* @since TBD
*
* @return string
*/
public function is_tc_paypal_active(): string {
$gateway = tribe( Manager::class )->get_gateway_by_key( PayPal_Gateway::get_key() );

return tec_tickets_commerce_is_enabled() && $gateway::is_active() && $gateway::is_enabled() ? static::YES : static::NO;
}
}
bordoni marked this conversation as resolved.
Show resolved Hide resolved
92 changes: 92 additions & 0 deletions src/Tickets/Site_Health/Fieldset/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
bordoni marked this conversation as resolved.
Show resolved Hide resolved
/**
* Fieldset for Settings related fields in the Site Health page.
*
* @since TBD
*
* @package TEC\Tickets\Site_Health\Fieldset
*/
bordoni marked this conversation as resolved.
Show resolved Hide resolved
namespace TEC\Tickets\Site_Health\Fieldset;

use TEC\Tickets\Site_Health\Contracts\Fieldset_Abstract;
use Tribe__Utils__Array as Arr;

/**
* Class Settings
*
* @since TBD
*
* @package TEC\Tickets\Site_Health\Fieldset
*/
class Settings extends Fieldset_Abstract {

/**
* @inheritdoc
*/
bordoni marked this conversation as resolved.
Show resolved Hide resolved
protected float $priority = 10.0;

/**
* @inheritdoc
*/
protected function get_fields(): array {
return [
[
'id' => 'ticket_enabled_post_types',
'label' => esc_html__( 'Ticket-enabled post types', 'event-tickets' ),
'value' => [ $this, 'get_post_types_enabled' ],
],
[
'id' => 'tickets_login_required_for_tickets',
'label' => esc_html__( 'Login required for Tickets', 'event-tickets' ),
'value' => [ $this, 'get_is_login_required_for_tickets' ],
],
[
'id' => 'tickets_login_required_for_rsvp',
'label' => esc_html__( 'Login required for RSVP', 'event-tickets' ),
'value' => [ $this, 'get_is_login_required_for_rsvp' ],
],
];
}

/**
* Get the post types enabled for tickets.
*
* @since TBD
*
* @return string
*/
public function get_post_types_enabled(): string {
$value = (array) tribe_get_option( 'ticket-enabled-post-types', [] );
$value = array_filter( $value );

return Arr::to_list( $value, ', ' );
}

/**
* Get if login is required for tickets.
*
* @since TBD
*
* @return string
*/
public function get_is_login_required_for_tickets(): string {
$value = (array) tribe_get_option( 'ticket-authentication-requirements', [] );
$value = array_filter( $value );

return in_array( 'event-tickets_all', $value, true ) ? static::YES : static::NO;
}

/**
* Get if login is required for RSVP.
*
* @since TBD
*
* @return string
*/
public function get_is_login_required_for_rsvp(): string {
$value = (array) tribe_get_option( 'ticket-authentication-requirements', [] );
$value = array_filter( $value );

return in_array( 'event-tickets_rsvp', $value, true ) ? static::YES : static::NO;
}
}
bordoni marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading