Skip to content

Commit

Permalink
v2.0.0-beta.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Mar 20, 2018
1 parent 3187844 commit 265ac3e
Show file tree
Hide file tree
Showing 42 changed files with 549 additions and 236 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Solspace Freeform Changelog

## 2.0.0-beta.6 - 2018-03-20
### Fixed
- Actually added Calendar 1.x to 2.x (Craft 2.x to 3.x) migration path (sorry!).
- Fixed a bug where Live Preview would show duplicates of some Calendar fields if the calendar layout didn't have any custom fields assigned to it.
- Fixed a bug where the `calendar.events` function was localizing date ranges.
- Fixed a bug where translations were not correctly being rendered in some areas.
- Fixed a bug where reinstalling Demo Templates would generate extra duplicate routes.
- Fixed a bug where Calendar CP would not respect non-US date formatting.
- Fixed a bug where adding new Sites wouldn't populate the necessary event and calendar sites tables.

## 2.0.0-beta.5 - 2018-03-19
### Fixed
- Added Live Preview functionality back.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Calendar is the most powerful event management and calendaring plugin on the market for Craft CMS. The intuitive interface allows you to create events with complex recurring event rules and exclusions, while the flexible templating offers a variety of options to satisfy your calendaring needs.

🚨 **IMPORTANT: The first few releases will be a bit rough around the edges, and there are a number of known issues. We don't recommend using Calendar in production environments just yet, but feel free to try it out now. Any issues can be reported on GitHub Issues only please.** 🚨
🚨 **IMPORTANT:** *Calendar is becoming more stable now, but we still don't yet recommend using in production environments. If you do use Calendar, please take caution and always backup your site before upgrading, etc. 🐛 Any issues can be reported on [GitHub Issues](https://github.com/solspace/craft3-calendar/issues) only please.* 🚨

![Screenshot](src/icon.svg)

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.0-beta.5",
"version": "2.0.0-beta.6",
"type": "craft-plugin",
"minimum-stability": "dev",
"authors": [
Expand All @@ -25,7 +25,7 @@
}
},
"extra": {
"schemaVersion": "2.0.0",
"schemaVersion": "2.0.1",
"handle": "calendar",
"class": "Solspace\\Calendar\\Calendar",
"name": "Calendar",
Expand Down
4 changes: 4 additions & 0 deletions src/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use craft\events\RegisterUserPermissionsEvent;
use craft\services\Dashboard;
use craft\services\Fields;
use craft\services\Sites;
use craft\services\UserPermissions;
use craft\web\twig\variables\CraftVariable;
use craft\web\UrlManager;
Expand Down Expand Up @@ -162,6 +163,9 @@ function (RegisterComponentTypesEvent $event) {
// craft()->on('i18n.onAddLocale', [craft()->calendar_events, 'addLocaleHandler']);
// craft()->on('i18n.onAddLocale', [craft()->calendar_calendars, 'addLocaleHandler']);

Event::on(Sites::class, Sites::EVENT_AFTER_SAVE_SITE, [$this->events, 'addSiteHandler']);
Event::on(Sites::class, Sites::EVENT_AFTER_SAVE_SITE, [$this->calendars, 'addSiteHandler']);

if (\Craft::$app->request->getIsCpRequest() && \Craft::$app->getUser()->getId()) {
\Craft::$app->view->registerTranslations(self::TRANSLATION_CATEGORY, self::$javascriptTranslationKeys);
}
Expand Down
29 changes: 23 additions & 6 deletions src/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use craft\events\ElementEvent;
use craft\helpers\Json;
use craft\helpers\UrlHelper;
use craft\i18n\Locale;
use Solspace\Calendar\Calendar;
use Solspace\Calendar\Elements\Event;
use Solspace\Calendar\Library\CalendarPermissionHelper;
Expand Down Expand Up @@ -186,12 +187,24 @@ public function actionSaveEvent()
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);
$event->startDate = Carbon::createFromFormat(
$format,
$values['startDate']['date'] . ' ' . $values['startDate']['time'],
DateHelper::UTC
);
}

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

if (isset($values['allDay'])) {
Expand Down Expand Up @@ -469,7 +482,7 @@ private function populateEventModel(Event $event)
$event->title = $request->getBodyParam('title', $event->title);

$event->fieldLayoutId = null;
$fieldsLocation = $request->getParam('fieldsLocation', 'fields');
$fieldsLocation = $request->getParam('fieldsLocation', 'fields');
$event->setFieldValuesFromRequest($fieldsLocation);

$authorId = \Craft::$app->getRequest()->getBodyParam('author', ($event->authorId ?: \Craft::$app->getUser()->getIdentity()->id));
Expand Down Expand Up @@ -524,7 +537,7 @@ private function populateEventModel(Event $event)

if (isset($values['exceptions'])) {
foreach ($values['exceptions'] as $date) {
$exception = new ExceptionModel();
$exception = new ExceptionModel();
$exception->eventId = $event->id;
$exception->date = new Carbon($date, DateHelper::UTC);

Expand All @@ -534,7 +547,7 @@ private function populateEventModel(Event $event)

if (isset($values['selectDates'])) {
foreach ($values['selectDates'] as $date) {
$selectDate = new SelectDateModel();
$selectDate = new SelectDateModel();
$selectDate->eventId = $event->id;
$selectDate->date = new Carbon($date, DateHelper::UTC);

Expand Down Expand Up @@ -649,7 +662,11 @@ private function handleRepeatRules(Event $event, array $postedValues)
if ($untilType === Event::UNTIL_TYPE_UNTIL) {
$until = null;
if (isset($postedValues['untilDate']['date']) && $postedValues['untilDate']['date']) {
$until = new Carbon($postedValues['untilDate']['date'], DateHelper::UTC);
$until = Carbon::createFromFormat(
\Craft::$app->locale->getDateFormat('short', Locale::FORMAT_PHP),
$postedValues['untilDate']['date'],
DateHelper::UTC
);
$until->setTime(23, 59, 59);
$event->until = $until;
} else {
Expand Down
10 changes: 7 additions & 3 deletions src/Elements/Db/EventQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,15 @@ private function parseCarbon($value = null)
return $value;
}

if ($value instanceof \DateTime) {
return Carbon::createFromTimestampUTC($value->getTimestamp());
if (!$value instanceof \DateTime) {
$value = new \DateTime($value);
}

return new Carbon($value, DateHelper::UTC);
return Carbon::createFromFormat(
'Y-m-d H:i:s',
$value->format('Y-m-d H:i:s'),
DateHelper::UTC
);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/Elements/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,16 @@ public function getUntil()
return $this->until;
}

/**
* An alias for getUntil()
*
* @return Carbon|null
*/
public function getUntilDate()
{
return $this->getUntil();
}

/**
* Returns the repeats ON rule, which could be -1, 1, 2, 3 or 4
* Or 0 if no rule is set
Expand Down Expand Up @@ -930,7 +940,7 @@ public function getDuration(): EventDuration
*/
public function isAllDay(): bool
{
return $this->allDay;
return (bool) $this->allDay;
}

/**
Expand Down
50 changes: 48 additions & 2 deletions src/Library/CodePack/Components/RoutesComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Solspace\Calendar\Library\CodePack\Components;

use craft\db\Query;
use craft\helpers\Json;

class RoutesComponent extends AbstractJsonComponent
{
/**
Expand All @@ -20,7 +23,7 @@ public function install(string $prefix = null)
if (isset($route->urlParts, $route->template) && \is_array($route->urlParts)) {
$urlParts = $route->urlParts;

array_walk_recursive($urlParts, function(&$value) {
array_walk_recursive($urlParts, function (&$value) {
$value = stripslashes($value);
});

Expand All @@ -29,7 +32,50 @@ public function install(string $prefix = null)
$pattern = "/(\/?)(.*)/";
$template = preg_replace($pattern, "$1$demoFolder$2", $route->template, 1);

$routeService->saveRoute($urlParts, $template);
// Compile the URI parts into a regex pattern
$uriPattern = '';
$uriParts = array_filter($urlParts);
$subpatternNameCounts = [];

foreach ($uriParts as $part) {
if (\is_string($part)) {
$uriPattern .= preg_quote($part, '/');
} else if (\is_array($part)) {
// Is the name a valid handle?
if (preg_match('/^[a-zA-Z]\w*$/', $part[0])) {
$subpatternName = $part[0];
} else {
$subpatternName = 'any';
}

// Make sure it's unique
if (isset($subpatternNameCounts[$subpatternName])) {
$subpatternNameCounts[$subpatternName]++;

// Append the count to the end of the name
$subpatternName .= $subpatternNameCounts[$subpatternName];
} else {
$subpatternNameCounts[$subpatternName] = 1;
}

// Add the var as a named subpattern
$uriPattern .= '<' . preg_quote($subpatternName, '/') . ':' . $part[1] . '>';
}
}

$id = (new Query())
->select('id')
->from('{{%routes}}')
->where(
[
'uriParts' => Json::encode($uriParts),
'uriPattern' => $uriPattern,
'template' => $template,
]
)
->scalar();

$routeService->saveRoute($urlParts, $template, null, $id ?: null);
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/Services/CalendarsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use craft\base\Component;
use craft\db\Query;
use craft\events\SiteEvent;
use craft\queue\jobs\ResaveElements;
use Solspace\Calendar\Calendar;
use Solspace\Calendar\Elements\Event;
Expand Down Expand Up @@ -554,6 +555,47 @@ public function isEventTemplateValid(CalendarModel $calendar, int $siteId): bool
return $templateExists;
}

/**
* @param SiteEvent $event
*
* @return bool
*/
public function addSiteHandler(SiteEvent $event): bool
{
$siteId = $event->site->id;

$rows = [];
$calendars = $this->getAllCalendars();
foreach ($calendars as $calendar) {
$rows[] = [
$calendar->id,
$siteId,
0,
0,
null,
null,
];
}

(new Query())
->createCommand()
->batchInsert(
CalendarSiteSettingsRecord::TABLE,
[
'calendarId',
'siteId',
'enabledByDefault',
'hasUrls',
'uriFormat',
'template',
],
$rows
)
->execute();

return true;
}

/**
* @return Query
*/
Expand Down
Loading

0 comments on commit 265ac3e

Please sign in to comment.