Skip to content

Commit

Permalink
v2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Jun 5, 2018
1 parent c7d744d commit 5a75245
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 19 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 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.1",
"version": "2.0.2",
"type": "craft-plugin",
"minimum-stability": "dev",
"authors": [
Expand All @@ -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"
},
Expand All @@ -25,7 +25,7 @@
}
},
"extra": {
"schemaVersion": "2.0.1",
"schemaVersion": "2.0.2",
"handle": "calendar",
"class": "Solspace\\Calendar\\Calendar",
"name": "Calendar",
Expand Down
102 changes: 101 additions & 1 deletion src/Elements/Db/EventQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 19 additions & 5 deletions src/Elements/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class Event extends Element implements \JsonSerializable
/** @var int */
public $sortOrder;

/** @var int */
public $score;

/**
* @return EventQuery|ElementQueryInterface
*/
Expand Down Expand Up @@ -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'];
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Library/CodePack/Components/RoutesComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/migrations/m180316_130028_Craft3Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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())
Expand Down
41 changes: 41 additions & 0 deletions src/migrations/m180601_113607_MigrateCalendarEventFieldtype.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Solspace\Calendar\migrations;

use Craft;
use craft\db\Migration;
use Solspace\Calendar\FieldTypes\EventFieldType;

/**
* m180601_113607_MigrateCalendarEventFieldtype migration.
*/
class m180601_113607_MigrateCalendarEventFieldtype extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$this->update(
'{{%fields}}',
['type' => EventFieldType::class],
['type' => 'Calendar_Event'],
[],
false
);
}

/**
* @inheritdoc
*/
public function safeDown()
{
$this->update(
'{{%fields}}',
['type' => 'Calendar_Event'],
['type' => EventFieldType::class],
[],
false
);
}
}

0 comments on commit 5a75245

Please sign in to comment.