Skip to content

Commit

Permalink
v2.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Oct 17, 2018
1 parent 0a27fe7 commit 9efacc4
Show file tree
Hide file tree
Showing 38 changed files with 300 additions and 111 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Solspace Calendar Changelog

## 2.0.7 - 2018-10-17
### Added
- Added `timezone` parameter for `calendar.export` function, allowing users to simulate a localized timezone, more-so as a workaround for Google Calendar not correctly supporting floating timezones.

### Changed
- Updated Events list CP page to only show available calendars when switching Sites, and to always append Site handle in URL when creating new events.

### Fixed
- Fixed a bug where CP and front end templates (month/week/day functions) were not localizing correctly for today's date.
- Fixed a bug where the End Repeat on Date input was incorrectly localizing the selected date when editing events.
- Fixed a bug where disabling the "Display Mini Calendar" setting for Calendar Month/Week/Day CP views would gives a JS error on those pages.
- Fixed a bug where CP Month/Week/Day views were looking for `jquery.qtip.min.map` and resulted in a JS error.
- Fixed a bug where CP Month/Week/Day views were not loading correctly if Fruit Studios Linkit fields were being used.
- Fixed a bug where querying manually for a list of events in a month was not always including all events that overlapped before the current month.

## 2.0.6 - 2018-09-06
### Fixed
- Fixed a bug where the `readableRepeatRule` was using the currently viewed occurrence of the event as the "starting from..." date, and not the original main start date of the event.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "solspace/craft3-calendar",
"description": "The most powerful event management plugin for Craft.",
"version": "2.0.6",
"version": "2.0.7",
"type": "craft-plugin",
"minimum-stability": "dev",
"authors": [
Expand All @@ -26,7 +26,7 @@
}
},
"extra": {
"schemaVersion": "2.0.4",
"schemaVersion": "2.0.5",
"handle": "calendar",
"class": "Solspace\\Calendar\\Calendar",
"name": "Calendar",
Expand Down
3 changes: 3 additions & 0 deletions src/Controllers/CalendarsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use craft\records\Field;
use Solspace\Calendar\Calendar;
use Solspace\Calendar\Elements\Event;
use Solspace\Calendar\Library\DateHelper;
use Solspace\Calendar\Models\CalendarModel;
use Solspace\Calendar\Models\CalendarSiteSettingsModel;
use Solspace\Calendar\Resources\Bundles\CalendarEditBundle;
Expand Down Expand Up @@ -110,6 +111,7 @@ public function actionSaveCalendar(): Response
$calendar->titleFormat = $request->post('titleFormat');
$calendar->titleLabel = $request->post('titleLabel');
$calendar->hasTitleField = (bool) $request->post('hasTitleField');
$calendar->icsTimezone = $request->post('icsTimezone');

// Site-specific settings
$allSiteSettings = [];
Expand Down Expand Up @@ -285,6 +287,7 @@ private function renderEditTemplate(CalendarModel $calendar, string $title): Res
'calendar' => $calendar,
'continueEditingUrl' => 'calendar/calendars/{handle}',
'customFields' => $customFieldData,
'timezoneOptions' => DateHelper::getTimezoneOptions(),
]
);
}
Expand Down
8 changes: 7 additions & 1 deletion src/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Solspace\Calendar\Models\ExceptionModel;
use Solspace\Calendar\Models\SelectDateModel;
use Solspace\Calendar\Resources\Bundles\EventEditBundle;
use Solspace\Calendar\Resources\Bundles\EventIndexBundle;
use yii\db\Exception;
use yii\helpers\FormatConverter;
use yii\web\HttpException;
Expand All @@ -40,6 +41,8 @@ public function actionEventsIndex(): Response
{
$this->requireEventPermission();

\Craft::$app->view->registerAssetBundle(EventIndexBundle::class);

return $this->renderTemplate(
'calendar/events/_index',
[
Expand Down Expand Up @@ -415,6 +418,8 @@ private function renderEditForm(Event $event, string $title): Response
);
}

$siteHandle = $event->getSite()->handle;

$variables = [
'name' => self::EVENT_FIELD_NAME,
'event' => $event,
Expand All @@ -436,13 +441,14 @@ private function renderEditForm(Event $event, string $title): Response
'timeFormat' => $timeFormat,
'showPreviewBtn' => $showPreviewButton,
'shareUrl' => $shareUrl,
'site' => $event->getSite(),
'crumbs' => [
['label' => Calendar::t('calendar'), 'url' => UrlHelper::cpUrl('calendar')],
['label' => Calendar::t('Events'), 'url' => UrlHelper::cpUrl('calendar/events')],
[
'label' => $title,
'url' => UrlHelper::cpUrl(
'calendar/events/' . ($event->id ?: 'new/' . $calendar->handle)
'calendar/events/' . ($event->id ?: 'new/' . $calendar->handle) . '/' . $siteHandle
),
],
],
Expand Down
51 changes: 30 additions & 21 deletions src/Elements/Db/EventQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ protected function beforePrepare(): bool
// join in the products table
$this->joinElementTable($table);
$hasCalendarsJoined = false;
$hasRelations = false;
$hasUsers = false;
$hasRelations = false;
$hasUsers = false;

if (!empty($this->join)) {
foreach ($this->join as $join) {
Expand Down Expand Up @@ -618,23 +618,23 @@ protected function beforePrepare(): bool
}

$select = [
$table . '.[[calendarId]]',
$table . '.[[authorId]]',
$table . '.[[startDate]]',
$table . '.[[endDate]]',
$table . '.[[allDay]]',
$table . '.[[rrule]]',
$table . '.[[freq]]',
$table . '.[[interval]]',
$table . '.[[count]]',
$table . '.[[until]]',
$table . '.[[byMonth]]',
$table . '.[[byYearDay]]',
$table . '.[[byMonthDay]]',
$table . '.[[byDay]]',
'{{%users}}.[[username]]',
$calendarTable . '.[[name]]',
];
$table . '.[[calendarId]]',
$table . '.[[authorId]]',
$table . '.[[startDate]]',
$table . '.[[endDate]]',
$table . '.[[allDay]]',
$table . '.[[rrule]]',
$table . '.[[freq]]',
$table . '.[[interval]]',
$table . '.[[count]]',
$table . '.[[until]]',
$table . '.[[byMonth]]',
$table . '.[[byYearDay]]',
$table . '.[[byMonthDay]]',
$table . '.[[byDay]]',
'{{%users}}.[[username]]',
$calendarTable . '.[[name]]',
];

if ($hasRelations) {
$select[] = '[[relations.sortOrder]]';
Expand Down Expand Up @@ -811,7 +811,7 @@ protected function beforePrepare(): bool
}

if (\is_array($this->orderBy) && isset($this->orderBy['dateCreated'])) {
$sortDirection = $this->orderBy['dateCreated'];
$sortDirection = $this->orderBy['dateCreated'];
$this->orderBy['[[calendar_events.dateCreated]]'] = $sortDirection;

unset($this->orderBy['dateCreated']);
Expand Down Expand Up @@ -1227,11 +1227,20 @@ private function cacheEvents()
$endDate = $event->getEndDate();
$diffInDays = DateHelper::carbonDiffInDays($startDate, $endDate);

$month = $startDate->format(self::FORMAT_MONTH);
$month = $startDate->format(self::FORMAT_MONTH);
$endMonth = $endDate->format(self::FORMAT_MONTH);
$this->addEventToCache($eventsByMonth, $month, $event);
if ($month !== $endMonth) {
$this->addEventToCache($eventsByMonth, $endMonth, $event);
}


$week = DateHelper::getCacheWeekNumber($startDate);
$endWeek = DateHelper::getCacheWeekNumber($endDate);
$this->addEventToCache($eventsByWeek, $week, $event);
if ($week !== $endWeek) {
$this->addEventToCache($eventsByWeek, $endWeek, $event);
}

$day = $startDate->copy();
for ($i = 0; $i <= $diffInDays; $i++) {
Expand Down
37 changes: 27 additions & 10 deletions src/Elements/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Solspace\Calendar\Models\ExceptionModel;
use Solspace\Calendar\Models\SelectDateModel;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use yii\base\Model;

class Event extends Element implements \JsonSerializable
{
Expand Down Expand Up @@ -233,6 +234,13 @@ protected static function defineSources(string $context = null): array
'key' => 'calendar:' . $calendar->id,
'label' => $calendar->name,
'criteria' => ['calendarId' => $calendar->id],
'sites' => array_keys($calendar->getSiteSettings()),
'data' => [
'id' => $calendar->id,
'name' => $calendar->name,
'handle' => $calendar->handle,
'color' => $calendar->color,
],
];
}

Expand Down Expand Up @@ -270,13 +278,13 @@ protected static function defineTableAttributes(): array
protected static function defineSortOptions(): array
{
return [
'title' => Calendar::t('Title'),
'name' => Calendar::t('Calendar'),
'startDate' => Calendar::t('Start Date'),
'endDate' => Calendar::t('End Date'),
'allDay' => Calendar::t('All Day'),
'username' => Calendar::t('Author'),
'dateCreated' => Calendar::t('Post Date'),
'title' => Calendar::t('Title'),
'name' => Calendar::t('Calendar'),
'startDate' => Calendar::t('Start Date'),
'endDate' => Calendar::t('End Date'),
'allDay' => Calendar::t('All Day'),
'username' => Calendar::t('Author'),
'dateCreated' => Calendar::t('Post Date'),
];
}

Expand Down Expand Up @@ -450,9 +458,9 @@ public function getCpEditUrl()
return false;
}

$siteHandle = static::isLocalized() ? '/' . $this->getSite()->handle : '';
$siteHandle = $this->getSite()->handle;

return UrlHelper::cpUrl('calendar/events/' . $this->id . $siteHandle);
return UrlHelper::cpUrl('calendar/events/' . $this->id . '/' . $siteHandle);
}

/**
Expand Down Expand Up @@ -1295,7 +1303,16 @@ public function jsonSerialize(): array
'textColor' => $this->getCalendar()->getContrastColor(),
];

return array_merge($object, $this->getFieldValues());
$fieldValues = [];
foreach ($this->getFieldValues() as $key => $value) {
if (is_a($value, 'fruitstudios\linkit\base\Link')) {
$value = $value->getLink([], false);
}

$fieldValues[$key] = $value;
}

return array_merge($object, $fieldValues);
}

public function rules()
Expand Down
51 changes: 50 additions & 1 deletion src/Library/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class DateHelper
{
const UTC = 'utc';
const FLOATING_TIMEZONE = 'floating';
const UTC = 'utc';

/** @var array */
private static $weekDays = [
Expand Down Expand Up @@ -412,6 +413,54 @@ public static function getRelativeEventDates(Carbon $startDate, Carbon $endDate,
return [$occurrenceStartDate, $occurrenceEndDate];
}

/**
* @return array
*/
public static function getTimezoneOptions(): array
{
// Assemble the timezone options array (Technique adapted from http://stackoverflow.com/a/7022536/1688568)
$timezoneOptions = [];

$utc = new \DateTime();
$offsets = [];
$timezoneIds = [];

foreach (\DateTimeZone::listIdentifiers() as $timezoneId) {
$timezone = new \DateTimeZone($timezoneId);
$transition = $timezone->getTransitions($utc->getTimestamp(), $utc->getTimestamp());
$abbr = $transition[0]['abbr'];

$offset = round($timezone->getOffset($utc) / 60);

if ($offset) {
$hour = floor($offset / 60);
$minutes = floor(abs($offset) % 60);

$format = sprintf('%+d', $hour);

if ($minutes) {
$format .= ':' . sprintf('%02u', $minutes);
}
} else {
$format = '';
}

$offsets[] = $offset;
$timezoneIds[] = $timezoneId;
$timezoneOptions[] = [
'value' => $timezoneId,
'label' => 'UTC' . $format . ($abbr !== 'UTC' ? " ({$abbr})" : '') . ($timezoneId !== 'UTC' ? '' . $timezoneId : ''),
];
}

array_multisort($offsets, $timezoneIds, $timezoneOptions);

$appended = [self::FLOATING_TIMEZONE => 'Floating Timezone (recommended)'];
$timezoneOptions = array_merge($appended, $timezoneOptions);

return $timezoneOptions;
}

/**
* @param array $array
* @param int $keyOffset - reorders the array putting $keyOffset amount of elements at the end
Expand Down
4 changes: 2 additions & 2 deletions src/Library/Duration/DayDuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class DayDuration extends AbstractDuration
*/
protected function init(Carbon $targetDate)
{
$startDate = Carbon::createFromTimestampUTC($targetDate->getTimestamp());
$startDate = Carbon::createFromTimestamp($targetDate->getTimestamp());
$startDate->setTime(0, 0, 0);

$endDate = $startDate->copy();
$endDate->setTime(23, 59, 59);

$this->startDate = $startDate;
$this->endDate = $endDate;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Library/Duration/HourDuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class HourDuration extends AbstractDuration
*/
protected function init(Carbon $targetDate)
{
$startDate = Carbon::createFromTimestampUTC($targetDate->getTimestamp());
$startDate = Carbon::createFromTimestamp($targetDate->getTimestamp());
$startDate->minute = 0;
$startDate->second = 0;

$endDate = $startDate->copy();
$endDate->minute = 59;
$endDate->second = 59;

$this->startDate = $startDate;
$this->endDate = $endDate;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Library/Duration/MonthDuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MonthDuration extends AbstractDuration
*/
protected function init(Carbon $targetDate)
{
$startDate = Carbon::createFromTimestampUTC($targetDate->getTimestamp());
$startDate = Carbon::createFromTimestamp($targetDate->getTimestamp());
$startDate->startOfMonth();

$endDate = $startDate->copy();
Expand Down
4 changes: 2 additions & 2 deletions src/Library/Duration/WeekDuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class WeekDuration extends AbstractDuration
*/
protected function init(Carbon $targetDate)
{
$startDate = Carbon::createFromTimestampUTC($targetDate->getTimestamp());
$startDate = Carbon::createFromTimestamp($targetDate->getTimestamp());
$startDate->startOfWeek();

$endDate = $startDate->copy();
$endDate->endOfWeek();

$this->startDate = $startDate;
$this->endDate = $endDate;
}
Expand Down
Loading

0 comments on commit 9efacc4

Please sign in to comment.