1
0
mirror of https://github.com/dwaxweiler/connector-mobilizon synced 2025-06-05 21:59:25 +02:00

fix widget, wip on shortcut

This commit is contained in:
Daniel Waxweiler
2023-05-07 19:53:24 +02:00
parent e28cdb7158
commit e1898af935
6 changed files with 31 additions and 16 deletions

View File

@ -24,10 +24,21 @@ class EventsListShortcut {
), $atts ), $atts
); );
$classNamePrefix = NAME; $url = Settings::getUrl();
$eventsCount = $atts_with_overriden_defaults['events-count']; $eventsCount = $atts_with_overriden_defaults['events-count'];
$groupName = $atts_with_overriden_defaults['group-name']; $groupName = $atts_with_overriden_defaults['group-name'];
if ($groupName) {
$data = GraphQlClient::get_upcoming_events_by_group_name($url, (int) $eventsCount, $groupName);
} else {
$data = GraphQlClient::get_upcoming_events($url, (int) $eventsCount);
}
$classNamePrefix = NAME;
$locale = get_locale();
$isShortOffsetNameShown = Settings::isShortOffsetNameShown();
$timeZone = wp_timezone_string();
ob_start(); ob_start();
require dirname(__DIR__) . '/view/events-list.php'; require dirname(__DIR__) . '/view/events-list.php';
$output = ob_get_clean(); $output = ob_get_clean();

View File

@ -25,17 +25,21 @@ class EventsListWidget extends \WP_Widget {
echo $args['before_title'].apply_filters('widget_title', $options['title']).$args['after_title']; echo $args['before_title'].apply_filters('widget_title', $options['title']).$args['after_title'];
} }
$classNamePrefix = NAME; $url = Settings::getUrl();
$eventsCount = $options['eventsCount']; $eventsCount = $options['eventsCount'];
$locale = str_replace('_', '-', get_locale()); // TODO _ is okay too.
$groupName = isset($options['groupName']) ? $options['groupName'] : ''; $groupName = isset($options['groupName']) ? $options['groupName'] : '';
if ($groupName) { if ($groupName) {
$data = GraphQlClient::get_upcoming_events_by_group_name($url, (int) $eventsCount, $groupName); // TODO wrap and put into shortcut as well $data = GraphQlClient::get_upcoming_events_by_group_name($url, (int) $eventsCount, $groupName);
} else { } else {
$data = GraphQlClient::get_upcoming_events($url, (int) $eventsCount); $data = GraphQlClient::get_upcoming_events($url, (int) $eventsCount);
} }
$classNamePrefix = NAME;
$locale = get_locale();
$isShortOffsetNameShown = Settings::isShortOffsetNameShown();
$timeZone = wp_timezone_string();
require dirname(__DIR__) . '/view/events-list.php'; require dirname(__DIR__) . '/view/events-list.php';
echo $args['after_widget']; echo $args['after_widget'];

View File

@ -99,7 +99,7 @@ final class GraphQlClient {
// if (dataInCache !== null) { // if (dataInCache !== null) {
// return Promise.resolve(dataInCache) // return Promise.resolve(dataInCache)
// } // }
$afterDatetime = date(DateTime::ISO8601); $afterDatetime = date(\DateTime::ISO8601);
$data = self::query($endpoint, $query, ['afterDatetime'=> $afterDatetime, 'groupName' => $groupName, 'limit' => $limit]); $data = self::query($endpoint, $query, ['afterDatetime'=> $afterDatetime, 'groupName' => $groupName, 'limit' => $limit]);
// return request(url, query, { afterDatetime, groupName, limit }).then( // return request(url, query, { afterDatetime, groupName, limit }).then(
// (data) => { // (data) => {

View File

@ -4,16 +4,11 @@ if (!defined('ABSPATH')) {
exit; exit;
} }
?> ?>
<div class="<?php echo esc_attr($classNamePrefix); ?>_events-list" <div class="<?php echo esc_attr($classNamePrefix); ?>_events-list">
data-maximum="<?php echo esc_attr($eventsCount); ?>"
data-group-name="<?php echo esc_attr($groupName); ?>"
data-time-zone="<?php echo esc_attr($timeZone); ?>"
<?php echo $isShortOffsetNameShown ? 'data-is-short-offset-name-shown' : ''; ?>>
<li style="display: none;"><?php esc_html_e('The events could not be loaded!', 'connector-mobilizon'); ?></li> <li style="display: none;"><?php esc_html_e('The events could not be loaded!', 'connector-mobilizon'); ?></li>
<li style="display: none;"><?php esc_html_e('The group could not be found!', 'connector-mobilizon'); ?></li> <li style="display: none;"><?php esc_html_e('The group could not be found!', 'connector-mobilizon'); ?></li>
</ul> </ul>
<?php /*print_r($data);*/ ?>
<ul> <ul>
<?php foreach($data['data']['events']['elements'] as $event) { ?> <?php foreach($data['data']['events']['elements'] as $event) { ?>
<li> <li>

View File

@ -7,6 +7,11 @@ final class DateTimeWrapperTest extends TestCase {
$this->assertEquals('24/12/2020', $d->getShortDate()); $this->assertEquals('24/12/2020', $d->getShortDate());
} }
public function testCanGetShortDateForUsualDateWithLocaleWithUnderscore(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z');
$this->assertEquals('24/12/2020', $d->getShortDate(), 'en_GB');
}
public function testCanGetShortDateForUsualDateWithTimezoneString(): void { public function testCanGetShortDateForUsualDateWithTimezoneString(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z', 'en-GB', 'Europe/Rome'); $d = new DateTimeWrapper('2020-12-24T16:45:00Z', 'en-GB', 'Europe/Rome');
$this->assertEquals('24/12/2020', $d->getShortDate()); $this->assertEquals('24/12/2020', $d->getShortDate());
@ -35,5 +40,5 @@ final class DateTimeWrapperTest extends TestCase {
public function testCanGetShortOffsetNameForUsualTime(): void { public function testCanGetShortOffsetNameForUsualTime(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z'); $d = new DateTimeWrapper('2020-12-24T16:45:00Z');
$this->assertEquals(0, $d->getOffset()); // TODO was UTC $this->assertEquals(0, $d->getOffset()); // TODO was UTC
} }
} }

View File

@ -10,19 +10,19 @@ final class FormatterTest extends TestCase
public function testCanDateFormatOneDateWithOffset(): void { public function testCanDateFormatOneDateWithOffset(): void {
$this->assertEquals('15/04/2021 10:30 - 15:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', true)); $this->assertEquals('15/04/2021 10:30 - 15:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', true));
} }
public function testCanDateFormatTwoDates(): void { public function testCanDateFormatTwoDates(): void {
$this->assertEquals('15/04/2021 10:30 - 16/04/2021 15:30', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', false)); $this->assertEquals('15/04/2021 10:30 - 16/04/2021 15:30', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', false));
} }
public function testCanDateFormatTwoDatesWithOffset(): void { public function testCanDateFormatTwoDatesWithOffset(): void {
$this->assertEquals('15/04/2021 10:30 - 16/04/2021 15:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', true)); $this->assertEquals('15/04/2021 10:30 - 16/04/2021 15:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', true));
} }
public function testCanDateFormatWhenSecondDateIsNull(): void { public function testCanDateFormatWhenSecondDateIsNull(): void {
$this->assertEquals('15/04/2021 10:30', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', null, false)); $this->assertEquals('15/04/2021 10:30', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', null, false));
} }
public function testCanDateFormatWhenSecondDateIsNullWithOffset(): void { public function testCanDateFormatWhenSecondDateIsNullWithOffset(): void {
$this->assertEquals('15/04/2021 10:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', null, true)); $this->assertEquals('15/04/2021 10:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', null, true));
} }