Skip to content

Commit

Permalink
v2.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Sep 6, 2018
1 parent 7c1cc4d commit 6a20a6b
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 45 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Solspace Calendar Changelog

## 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.
- Fixed a bug where the list of occurrences (`event.occurrences`) was being incorrectly incremented based on the currently viewed occurrence and the number of "times" it's supposed to repeat.
- Fixed a bug where the list of Select Dates recurrences in CP Edit event view was displaying the previous day when going back to edit an event.
- Fixed a bug where the Share button in CP Create/Edit event view was not generating a token in URL for disabled events.
- Fixed a bug where Live Preview template was not correctly showing all date formatting options correctly.
- Fixed a bug where Live Preview template was not displaying at all when the Select Dates repeat rule was used.
- Fixed a bug where the `simplifiedRepeatRule` property was not parsing as anything.
- Fixed a bug where required fields were not being validated when creating/editing events (in main create/edit CP page).

## 2.0.5 - 2018-07-26
### Fixed
- Fixed a bug where disabled events would error when being viewed/edited.
Expand Down
2 changes: 1 addition & 1 deletion 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.5",
"version": "2.0.6",
"type": "craft-plugin",
"minimum-stability": "dev",
"authors": [
Expand Down
134 changes: 121 additions & 13 deletions src/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Solspace\Calendar\Controllers;

use Carbon\Carbon;
use craft\base\Element;
use craft\db\Query;
use craft\elements\User;
use craft\events\ElementEvent;
Expand All @@ -18,6 +19,7 @@
use Solspace\Calendar\Models\ExceptionModel;
use Solspace\Calendar\Models\SelectDateModel;
use Solspace\Calendar\Resources\Bundles\EventEditBundle;
use yii\db\Exception;
use yii\helpers\FormatConverter;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
Expand Down Expand Up @@ -207,19 +209,27 @@ public function actionSaveEvent()
$format = "$dateFormat $timeFormat";

if (isset($values['startDate'])) {
$event->startDate = Carbon::createFromFormat(
$format,
$values['startDate']['date'] . ' ' . $values['startDate']['time'],
DateHelper::UTC
);
try {
$event->startDate = Carbon::createFromFormat(
$format,
$values['startDate']['date'] . ' ' . $values['startDate']['time'],
DateHelper::UTC
);
} catch (\InvalidArgumentException $exception) {
$event->startDate = null;
}
}

if (isset($values['endDate'])) {
$event->endDate = Carbon::createFromFormat(
$format,
$values['endDate']['date'] . ' ' . $values['endDate']['time'],
DateHelper::UTC
);
try {
$event->endDate = Carbon::createFromFormat(
$format,
$values['endDate']['date'] . ' ' . $values['endDate']['time'],
DateHelper::UTC
);
} catch (\InvalidArgumentException $e) {
$event->endDate = null;
}
}

if (isset($values['allDay'])) {
Expand Down Expand Up @@ -250,6 +260,11 @@ public function actionSaveEvent()
$event->slug = \Craft::$app->request->post('slug', $event->slug);
$event->setFieldValuesFromRequest('fields');

// Save the entry (finally!)
if ($event->enabled && $event->enabledForSite) {
$event->setScenario(Element::SCENARIO_LIVE);
}

if ($this->getEventsService()->saveEvent($event)) {
$exceptions = $values['exceptions'] ?? [];
$this->getExceptionsService()->saveExceptions($event, $exceptions);
Expand Down Expand Up @@ -387,6 +402,19 @@ private function renderEditForm(Event $event, string $title): Response
$showPreviewButton = true;
}

$shareUrl = null;
if ($event->enabled) {
$shareUrl = $event->getUrl();
} else {
$shareUrl = UrlHelper::actionUrl(
'calendar/events/share-event',
[
'eventId' => $event->getId(),
'siteId' => $event->siteId,
]
);
}

$variables = [
'name' => self::EVENT_FIELD_NAME,
'event' => $event,
Expand All @@ -407,7 +435,7 @@ private function renderEditForm(Event $event, string $title): Response
'dateFormat' => $dateFormat,
'timeFormat' => $timeFormat,
'showPreviewBtn' => $showPreviewButton,
'shareUrl' => $event->getUrl() ?: null,
'shareUrl' => $shareUrl,
'crumbs' => [
['label' => Calendar::t('calendar'), 'url' => UrlHelper::cpUrl('calendar')],
['label' => Calendar::t('Events'), 'url' => UrlHelper::cpUrl('calendar/events')],
Expand All @@ -423,6 +451,55 @@ private function renderEditForm(Event $event, string $title): Response
return $this->renderTemplate('calendar/events/_edit', $variables);
}

/**
* @param int $eventId
* @param int $siteId
*
* @return Response
* @throws NotFoundHttpException
*/
public function actionShareEvent(int $eventId, int $siteId): Response
{
$event = $this->getEventsService()->getEventById($eventId, $siteId, true);
if (!$event) {
throw new NotFoundHttpException('Entry not found');
}

$params = ['eventId' => $eventId, 'siteId' => $siteId];

// Create the token and redirect to the entry URL with the token in place
$token = \Craft::$app->getTokens()->createToken(['calendar/events/view-shared-event', $params]);

if ($token === false) {
throw new Exception('There was a problem generating the token.');
}

$url = UrlHelper::urlWithToken($event->getUrl(), $token);

return \Craft::$app->getResponse()->redirect($url);
}

/**
* @param int|null $eventId
* @param int|null $siteId
*
* @return Response
* @throws NotFoundHttpException
* @throws ServerErrorHttpException
* @throws \yii\web\BadRequestHttpException
*/
public function actionViewSharedEvent(int $eventId = null, int $siteId = null): Response
{
$this->requireToken();

$event = $this->getEventsService()->getEventById($eventId, $siteId, true);
if (!$event) {
throw new NotFoundHttpException('Event not found');
}

return $this->showEvent($event);
}

/**
* Previews an entry.
*
Expand Down Expand Up @@ -518,12 +595,33 @@ private function populateEventModel(Event $event)
CalendarPermissionHelper::requireCalendarEditPermissions($event->getCalendar());
}


$dateFormat = \Craft::$app->locale->getDateFormat('short', Locale::FORMAT_PHP);
$timeFormat = \Craft::$app->locale->getTimeFormat('short', Locale::FORMAT_PHP);
$format = "$dateFormat $timeFormat";

if (isset($values['startDate'])) {
$event->startDate = new Carbon($values['startDate']['date'] . ' ' . $values['startDate']['time'], DateHelper::UTC);
try {
$event->startDate = Carbon::createFromFormat(
$format,
$values['startDate']['date'] . ' ' . $values['startDate']['time'],
DateHelper::UTC
);
} catch (\InvalidArgumentException $exception) {
$event->startDate = null;
}
}

if (isset($values['endDate'])) {
$event->endDate = new Carbon($values['endDate']['date'] . ' ' . $values['endDate']['time'], DateHelper::UTC);
try {
$event->endDate = Carbon::createFromFormat(
$format,
$values['endDate']['date'] . ' ' . $values['endDate']['time'],
DateHelper::UTC
);
} catch (\InvalidArgumentException $e) {
$event->endDate = null;
}
}

if (isset($values['allDay'])) {
Expand All @@ -550,7 +648,12 @@ private function populateEventModel(Event $event)
$this->handleRepeatRules($event, $values);

if (isset($values['exceptions'])) {
$existingExceptions = $event->getExceptionDateStrings();
foreach ($values['exceptions'] as $date) {
if (\in_array($date, $existingExceptions, true)) {
continue;
}

$exception = new ExceptionModel();
$exception->eventId = $event->id;
$exception->date = new Carbon($date, DateHelper::UTC);
Expand All @@ -560,7 +663,12 @@ private function populateEventModel(Event $event)
}

if (isset($values['selectDates'])) {
$existingSelectDates = $event->getSelectDatesAsString();
foreach ($values['selectDates'] as $date) {
if (\in_array($date, $existingSelectDates, true)) {
continue;
}

$selectDate = new SelectDateModel();
$selectDate->eventId = $event->id;
$selectDate->date = new Carbon($date, DateHelper::UTC);
Expand Down
8 changes: 5 additions & 3 deletions src/Elements/Db/EventQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,11 @@ public function all($db = null): array
$configHash = $this->getConfigStateHash();

// Nasty elements index hack
$context = \Craft::$app->request->post('context');
if (\in_array($context, ['index', 'modal'], true)) {
$this->loadOccurrences = false;
if (!\Craft::$app->request->isConsoleRequest) {
$context = \Craft::$app->request->post('context');
if (\in_array($context, ['index', 'modal'], true)) {
$this->loadOccurrences = false;
}
}

if (null === $this->events || self::$lastCachedConfigStateHash !== $configHash) {
Expand Down
Loading

0 comments on commit 6a20a6b

Please sign in to comment.