2022-06-03 23:48:19 +02:00
|
|
|
<?php
|
|
|
|
namespace MobilizonConnector;
|
|
|
|
|
|
|
|
class EventsListBlock {
|
|
|
|
|
|
|
|
public static function initAndReturnScriptName(): string {
|
|
|
|
$scriptName = NAME . '-block-starter';
|
|
|
|
wp_register_script($scriptName, plugins_url(NAME . '/front/block-events-loader.js'), [
|
|
|
|
'wp-block-editor',
|
|
|
|
'wp-blocks',
|
|
|
|
'wp-components',
|
|
|
|
'wp-i18n'
|
2024-11-09 11:20:34 +01:00
|
|
|
], '<wordpress-version>');
|
2022-06-03 23:48:19 +02:00
|
|
|
register_block_type(NAME . '/events-list', [
|
|
|
|
'api_version' => 2,
|
|
|
|
'title' => __('Events List', 'connector-mobilizon'),
|
|
|
|
'description' => __('A list of the upcoming events of the connected Mobilizon instance.', 'connector-mobilizon'),
|
|
|
|
'category' => 'widgets',
|
|
|
|
'icon' => 'list-view',
|
|
|
|
'supports' => [
|
|
|
|
'html' => false
|
|
|
|
],
|
|
|
|
'attributes' => [
|
|
|
|
'eventsCount' => [
|
|
|
|
'type' => 'number',
|
|
|
|
'default' => 3,
|
|
|
|
],
|
|
|
|
'groupName' => [
|
|
|
|
'type' => 'string',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'editor_script' => $scriptName,
|
|
|
|
'render_callback' => 'MobilizonConnector\EventsListBlock::render',
|
|
|
|
]);
|
|
|
|
return $scriptName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function render($block_attributes, $content) {
|
2024-04-05 23:26:11 +02:00
|
|
|
$url = Settings::getUrl();
|
2022-06-03 23:48:19 +02:00
|
|
|
$eventsCount = $block_attributes['eventsCount'];
|
|
|
|
$groupName = isset($block_attributes['groupName']) ? $block_attributes['groupName'] : '';
|
2024-05-14 10:28:39 +02:00
|
|
|
$classNamePrefix = NAME;
|
2022-06-03 23:48:19 +02:00
|
|
|
|
|
|
|
ob_start();
|
2024-04-05 23:26:11 +02:00
|
|
|
try {
|
|
|
|
if ($groupName) {
|
|
|
|
$events = GraphQlClient::get_upcoming_events_by_group_name($url, (int) $eventsCount, $groupName);
|
|
|
|
} else {
|
|
|
|
$events = GraphQlClient::get_upcoming_events($url, (int) $eventsCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
$locale = get_locale();
|
|
|
|
$isShortOffsetNameShown = Settings::isShortOffsetNameShown();
|
|
|
|
$timeZone = wp_timezone_string();
|
|
|
|
|
|
|
|
require dirname(__DIR__) . '/view/events-list.php';
|
|
|
|
} catch (GeneralException $e) {
|
|
|
|
require dirname(__DIR__) . '/view/events-list-not-loaded.php';
|
|
|
|
} catch (GroupNotFoundException $e) {
|
|
|
|
require dirname(__DIR__) . '/view/events-list-group-not-found.php';
|
|
|
|
}
|
2022-06-03 23:48:19 +02:00
|
|
|
$output = ob_get_clean();
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|