Skip to content

Commit

Permalink
v2.0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Apr 15, 2019
1 parent 068d118 commit a1b7e1f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Solspace Calendar Changelog

## 2.0.19 - 2019-04-15
### Fixed
- Fixed a bug where the `occurrences` object date ranges were not working correctly with events using the Select Dates repeat rule type.
- Fixed a bug where Calendar would hard error for events attempting to be created without times.
- Fixed a bug where events couldn't be ordered by `RAND()`.

## 2.0.18 - 2019-04-05
### Fixed
- Fixed a bug where events that started early in day but repeated daily and ended on a specific date would error due to timezone issues.
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.18",
"version": "2.0.19",
"type": "craft-plugin",
"authors": [
{
Expand Down
13 changes: 9 additions & 4 deletions src/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,15 @@ public function actionSaveEvent()
);
}

$event->startDateLocalized = new Carbon($event->getStartDate()->toDateTimeString());
$event->endDateLocalized = new Carbon($event->getEndDate()->toDateTimeString());
$event->initialStartDate = $event->getStartDate()->copy();
$event->initialEndDate = $event->getEndDate()->copy();
if ($event->getStartDate()) {
$event->startDateLocalized = new Carbon($event->getStartDate()->toDateTimeString());
$event->initialStartDate = $event->getStartDate()->copy();
}

if ($event->getEndDate()) {
$event->endDateLocalized = new Carbon($event->getEndDate()->toDateTimeString());
$event->initialEndDate = $event->getEndDate()->copy();
}

$this->handleRepeatRules($event, $values);

Expand Down
36 changes: 32 additions & 4 deletions src/Elements/Db/EventQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ public function all($db = null): array
$this->orderDates($this->eventCache);
}

if ($this->shouldRandomize()) {
$this->randomizeDates($this->eventCache);
}

if ($this->shuffle) {
shuffle($this->eventCache);
}
Expand Down Expand Up @@ -855,11 +859,13 @@ protected function beforePrepare(): bool
}
}

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

unset($this->orderBy['dateCreated']);
unset($this->orderBy['dateCreated']);
}
}

return parent::beforePrepare();
Expand Down Expand Up @@ -1197,6 +1203,14 @@ function (array $arrayA, array $arrayB) use ($modifier) {
);
}

/**
* @param array $dates
*/
private function randomizeDates(array &$dates)
{
shuffle($dates);
}

/**
* Orders events by their start dates
*
Expand Down Expand Up @@ -1408,6 +1422,20 @@ private function shouldOrderByStartDate(): bool
return false;
}

/**
* Checks whether the events should be randomized
*
* @return bool
*/
private function shouldRandomize(): bool
{
if (\is_array($this->orderBy)) {
return array_key_exists('RAND()', $this->orderBy);
}

return null !== $this->orderBy && $this->orderBy === 'RAND()';
}

/**
* Returns 1 for ASC and -1 for DESC
* Based on ::$sort
Expand Down
2 changes: 1 addition & 1 deletion src/Elements/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ public function getOccurrences(array $config = null): array
if ($this->getRRuleObject()) {
$occurrenceDates = $this->getOccurrenceDatesBetween($rangeStart, $rangeEnd);
} else if ($this->getSelectDates()) {
$occurrenceDates = $this->getSelectDatesAsDates();
$occurrenceDates = $this->getSelectDatesAsDates($rangeStart, $rangeEnd);
}

$occurrences = [];
Expand Down

0 comments on commit a1b7e1f

Please sign in to comment.