From 5a75245adc4705872100fd714620a639b7bd8308 Mon Sep 17 00:00:00 2001 From: Kelsey Martens Date: Tue, 5 Jun 2018 12:06:22 -0500 Subject: [PATCH] v2.0.2 --- CHANGELOG.md | 15 ++- composer.json | 10 +- src/Elements/Db/EventQuery.php | 102 +++++++++++++++++- src/Elements/Event.php | 24 ++++- .../CodePack/Components/RoutesComponent.php | 8 +- .../m180316_130028_Craft3Upgrade.php | 9 ++ ...1_113607_MigrateCalendarEventFieldtype.php | 41 +++++++ 7 files changed, 190 insertions(+), 19 deletions(-) create mode 100644 src/migrations/m180601_113607_MigrateCalendarEventFieldtype.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a1c730c..a021a035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Solspace Calendar Changelog +## 2.0.2 - 2018-06-05 +### Added +- Added `startsBefore`, `endsAfter`, `startsBeforeOrAt`, and `endsAfterOrAt` parameters to `calendar.events` function, for more flexibility to narrow down results. + +### Changed +- Updated Symfony dependencies to avoid conflicting with other plugins. + +### Fixed +- Fixed a bug where the Calendar 1.x to 2.x (Craft 2.x to 3.x) migration was not migrating the Calendar fieldtype for elements. +- Fixed a bug where the Demo Templates installer would install duplicate routes if they already existed. +- Fixed a bug where searching on events in the control panel was not always reliable and would sometimes error. +- Fixed a bug where the EventQuery would not process negative limits properly. + ## 2.0.1 - 2018-05-16 ### Fixed - Fixed a bug where the Event UI dates and times were being localized while editing an existing event in control panel. @@ -39,7 +52,7 @@ ## 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!). +- Actually added Calendar 1.x to 2.x (Craft 2.x to 3.x) migration path. - 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. diff --git a/composer.json b/composer.json index 9c443a0a..141d1208 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "solspace/craft3-calendar", "description": "The most powerful event management plugin for Craft.", - "version": "2.0.1", + "version": "2.0.2", "type": "craft-plugin", "minimum-stability": "dev", "authors": [ @@ -13,9 +13,9 @@ "require": { "php": ">=7.0", "rlanvin/php-rrule": "~1.6.0", - "symfony/property-access": "^3.3", - "symfony/finder": "^3.3", - "symfony/filesystem": "^3.3", + "symfony/property-access": "^2.8|^3.0|^4.0", + "symfony/finder": "^2.8|^3.0|^4.0", + "symfony/filesystem": "^2.8|^3.0|^4.0", "solspace/craft3-commons": "^1.0.8", "nesbot/carbon": "^1.22.1" }, @@ -25,7 +25,7 @@ } }, "extra": { - "schemaVersion": "2.0.1", + "schemaVersion": "2.0.2", "handle": "calendar", "class": "Solspace\\Calendar\\Calendar", "name": "Calendar", diff --git a/src/Elements/Db/EventQuery.php b/src/Elements/Db/EventQuery.php index 967b3dd7..6b64dde8 100644 --- a/src/Elements/Db/EventQuery.php +++ b/src/Elements/Db/EventQuery.php @@ -42,6 +42,18 @@ class EventQuery extends ElementQuery implements \Countable /** @var \DateTime */ private $endDate; + /** @var \DateTime */ + private $startsBefore; + + /** @var \DateTime */ + private $startsBeforeOrAt; + + /** @var \DateTime */ + private $endsAfter; + + /** @var \DateTime */ + private $endsAfterOrAt; + /** @var bool */ private $allDay = false; @@ -172,6 +184,54 @@ public function setEndDate($value = null): EventQuery return $this; } + /** + * @param \DateTime $startsBefore + * + * @return EventQuery + */ + public function setStartsBefore($startsBefore): EventQuery + { + $this->startsBefore = $this->parseCarbon($startsBefore); + + return $this; + } + + /** + * @param \DateTime $startsBeforeOrAt + * + * @return EventQuery + */ + public function setStartsBeforeOrAt($startsBeforeOrAt): EventQuery + { + $this->startsBeforeOrAt = $this->parseCarbon($startsBeforeOrAt); + + return $this; + } + + /** + * @param \DateTime $endsAfter + * + * @return EventQuery + */ + public function setEndsAfter($endsAfter): EventQuery + { + $this->endsAfter = $this->parseCarbon($endsAfter); + + return $this; + } + + /** + * @param \DateTime $endsAfterOrAt + * + * @return EventQuery + */ + public function setEndsAfterOrAt($endsAfterOrAt): EventQuery + { + $this->endsAfterOrAt = $this->parseCarbon($endsAfterOrAt); + + return $this; + } + /** * @param bool $value * @@ -525,6 +585,46 @@ protected function beforePrepare(): bool ); } + if ($this->startsBefore) { + $this->subQuery->andWhere( + Db::parseParam( + $table . '.[[startDate]]', + $this->extractDateAsFormattedString($this->startsBefore), + '<' + ) + ); + } + + if ($this->startsBeforeOrAt) { + $this->subQuery->andWhere( + Db::parseParam( + $table . '.[[startDate]]', + $this->extractDateAsFormattedString($this->startsBeforeOrAt), + '<=' + ) + ); + } + + if ($this->endsAfter) { + $this->subQuery->andWhere( + Db::parseParam( + $table . '.[[endDate]]', + $this->extractDateAsFormattedString($this->endsAfter), + '>' + ) + ); + } + + if ($this->endsAfterOrAt) { + $this->subQuery->andWhere( + Db::parseParam( + $table . '.[[endDate]]', + $this->extractDateAsFormattedString($this->endsAfterOrAt), + '>=' + ) + ); + } + if ($this->endDate) { $this->subQuery->andWhere( Db::parseParam( @@ -996,7 +1096,7 @@ function (Event $eventA, Event $eventB) use ($modifier, $orderBy) { */ private function cutOffExcess(array &$array) { - if (null !== $this->limit) { + if ($this->limit >= 0) { $offset = $this->offset ?: 0; $array = \array_slice($array, $offset, $this->limit); diff --git a/src/Elements/Event.php b/src/Elements/Event.php index da5d16b2..604c3ec1 100644 --- a/src/Elements/Event.php +++ b/src/Elements/Event.php @@ -100,6 +100,9 @@ class Event extends Element implements \JsonSerializable /** @var int */ public $sortOrder; + /** @var int */ + public $score; + /** * @return EventQuery|ElementQueryInterface */ @@ -249,12 +252,23 @@ protected static function defineTableAttributes(): array */ protected static function defineSortOptions(): array { - $sortOptions = parent::defineSortOptions(); - - $keys = array_keys($sortOptions); - $keys[array_search('calendar', $keys, true)] = 'name'; + return [ + 'title' => Calendar::t('Title'), + 'name' => Calendar::t('Calendar'), + 'startDate' => Calendar::t('Start Date'), + 'endDate' => Calendar::t('End Date'), + 'allDay' => Calendar::t('All Day'), + 'users.username' => Calendar::t('Author'), + 'dateCreated' => Calendar::t('Post Date'), + ]; + } - return array_combine($keys, $sortOptions); + /** + * @return array + */ + protected static function defineSearchableAttributes(): array + { + return ['id', 'title', 'startDate', 'endDate']; } /** diff --git a/src/Library/CodePack/Components/RoutesComponent.php b/src/Library/CodePack/Components/RoutesComponent.php index 1722a075..5186454a 100644 --- a/src/Library/CodePack/Components/RoutesComponent.php +++ b/src/Library/CodePack/Components/RoutesComponent.php @@ -66,13 +66,7 @@ public function install(string $prefix = null) $id = (new Query()) ->select('id') ->from('{{%routes}}') - ->where( - [ - 'uriParts' => Json::encode($uriParts), - 'uriPattern' => $uriPattern, - 'template' => $template, - ] - ) + ->where(['uriParts' => Json::encode($uriParts)]) ->scalar(); $routeService->saveRoute($urlParts, $template, null, $id ?: null); diff --git a/src/migrations/m180316_130028_Craft3Upgrade.php b/src/migrations/m180316_130028_Craft3Upgrade.php index f19a3779..55eac9aa 100644 --- a/src/migrations/m180316_130028_Craft3Upgrade.php +++ b/src/migrations/m180316_130028_Craft3Upgrade.php @@ -4,6 +4,7 @@ use craft\db\Migration; use craft\db\Query; +use Solspace\Calendar\FieldTypes\EventFieldType; use Solspace\Commons\Migrations\ForeignKey; use Solspace\Commons\Migrations\Table; @@ -36,6 +37,14 @@ public function safeUp(): bool return true; } + $this->update( + '{{%fields}}', + ['type' => EventFieldType::class], + ['type' => 'Calendar_Event'], + [], + false + ); + $table = (new Table('calendar_calendar_sites')) ->addField('id', $this->primaryKey()) ->addField('calendarId', $this->integer()) diff --git a/src/migrations/m180601_113607_MigrateCalendarEventFieldtype.php b/src/migrations/m180601_113607_MigrateCalendarEventFieldtype.php new file mode 100644 index 00000000..864d5517 --- /dev/null +++ b/src/migrations/m180601_113607_MigrateCalendarEventFieldtype.php @@ -0,0 +1,41 @@ +update( + '{{%fields}}', + ['type' => EventFieldType::class], + ['type' => 'Calendar_Event'], + [], + false + ); + } + + /** + * @inheritdoc + */ + public function safeDown() + { + $this->update( + '{{%fields}}', + ['type' => 'Calendar_Event'], + ['type' => EventFieldType::class], + [], + false + ); + } +}