add location
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 41s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m8s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m7s

This commit is contained in:
André Menrath 2024-10-15 17:47:54 +02:00
parent da9076a4f5
commit bee70bcb88

View file

@ -14,7 +14,9 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Activity\Extended_Object\Place; use Activitypub\Activity\Extended_Object\Place;
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event; use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
use MEC;
use MEC\Events\Event as MEC_Event; use MEC\Events\Event as MEC_Event;
use MEC_main;
/** /**
* ActivityPub Tribe Transformer * ActivityPub Tribe Transformer
@ -29,6 +31,14 @@ final class Modern_Events_Calendar_Lite extends Event {
*/ */
protected $mec_event; protected $mec_event;
/**
* The MEC main instance.
*
* @var MEC_main|null
*/
protected $mec_main;
/** /**
* Extend the constructor, to also set the tribe object. * Extend the constructor, to also set the tribe object.
* *
@ -40,6 +50,7 @@ final class Modern_Events_Calendar_Lite extends Event {
*/ */
public function __construct( $wp_object, $wp_taxonomy ) { public function __construct( $wp_object, $wp_taxonomy ) {
parent::__construct( $wp_object, $wp_taxonomy ); parent::__construct( $wp_object, $wp_taxonomy );
$this->mec_main = MEC::getInstance( 'app.libraries.main' );
$this->mec_event = new MEC_Event( $wp_object ); $this->mec_event = new MEC_Event( $wp_object );
} }
@ -61,9 +72,33 @@ final class Modern_Events_Calendar_Lite extends Event {
* Get the location. * Get the location.
*/ */
public function get_location(): ?Place { public function get_location(): ?Place {
$location_id = $this->mec_main->get_master_location_id( $this->mec_event->ID );
if ( ! $location_id ) {
return null; return null;
} }
$data = $this->mec_main->get_location_data( $location_id );
$location = new Place();
$location->set_sensitive( null );
if ( ! empty( $data['address'] ) ) {
$location->set_address( $data['address'] );
}
if ( ! empty( $data['name'] ) ) {
$location->set_name( $data['name'] );
}
if ( ! empty( $data['longitude'] ) ) {
$location->set_longitude( $data['longitude'] );
}
if ( ! empty( $data['latitude'] ) ) {
$location->set_latitude( $data['latitude'] );
}
return $location;
}
/** /**
* Get the location. * Get the location.
*/ */
@ -73,6 +108,7 @@ final class Modern_Events_Calendar_Lite extends Event {
if ( 'global' === $timezone ) { if ( 'global' === $timezone ) {
return parent::get_timezone(); return parent::get_timezone();
} }
return $timezone; return $timezone;
} }
} }