Skip to content

Commit

Permalink
v2.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Jul 4, 2018
1 parent e630756 commit 5c17b9a
Show file tree
Hide file tree
Showing 14 changed files with 355 additions and 51 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.4 - 2018-07-04
### Added
- Added `endsBefore`, `endsBeforeOrAt`, `startsAfter` and `startsAfterOrAt` parameters to `calendar.events` function, for more flexibility to narrow down results.

### Fixed
- Fixed a bug where editing events would display a localized time in time pickers for start and end dates in recent versions of Craft.
- Fixed a bug where events with Select Dates rule were not having selected dates show up in calendars.
- Fixed a bug where the `rangeEnd` parameter was not correctly setting end time to `23:59:59`.
- Fixed a bug where dragging and dropping disabled events in CP Month/Week/Day views was not working.
- Fixed a bug where the Calendar 1.x to 2.x (Craft 2.x to 3.x) migration was not correctly fully migrating the Calendar fieldtype.

## 2.0.3 - 2018-06-12
### Changed
- Updated Demo Templates routes to be extension agnostic (no longer specifically include `.html` in route path).
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.3",
"version": "2.0.4",
"type": "craft-plugin",
"minimum-stability": "dev",
"authors": [
Expand All @@ -25,7 +25,7 @@
}
},
"extra": {
"schemaVersion": "2.0.2",
"schemaVersion": "2.0.4",
"handle": "calendar",
"class": "Solspace\\Calendar\\Calendar",
"name": "Calendar",
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/EventsApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private function validateAndReturnModificationData(): array
$isAllDay = \Craft::$app->request->post('isAllDay') === 'true';
$deltaSeconds = \Craft::$app->request->post('deltaSeconds');

$event = $this->getEventsService()->getEventById($eventId, $siteId);
$event = $this->getEventsService()->getEventById($eventId, $siteId, true);

if ($event) {
CalendarPermissionHelper::requireCalendarEditPermissions($event->getCalendar());
Expand Down
10 changes: 7 additions & 3 deletions src/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public function actionCreateEvent(string $handle, string $siteHandle = null): Re
$site = \Craft::$app->sites->currentSite;
}

$locale = $site->language;
$locale = str_replace('_', '-', strtolower($locale));

EventEditBundle::$locale = $locale;

$event = Event::create($site->id);
$event->calendarId = $calendar->id;

Expand Down Expand Up @@ -109,9 +114,8 @@ public function actionEditEvent(int $id, string $siteHandle = null): Response
$siteId = $site->id;
$locale = $site->language;
$locale = str_replace('_', '-', strtolower($locale));
if (file_exists(__DIR__ . '/../Resources/js/lib/moment/locale/' . $locale . '.js')) {
\Craft::$app->view->registerJsFile('calendar/js/lib/moment/locale/' . $locale . '.js');
}

EventEditBundle::$locale = $locale;
}

$event = $this->getEventsService()->getEventById($id, $siteId);
Expand Down
111 changes: 104 additions & 7 deletions src/Elements/Db/EventQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,24 @@ class EventQuery extends ElementQuery implements \Countable
/** @var \DateTime */
private $startsBeforeOrAt;

/** @var \DateTime */
private $startsAfter;

/** @var \DateTime */
private $startsAfterOrAt;

/** @var \DateTime */
private $endsAfter;

/** @var \DateTime */
private $endsAfterOrAt;

/** @var \DateTime */
private $endsBefore;

/** @var \DateTime */
private $endsBeforeOrAt;

/** @var bool */
private $allDay = false;

Expand Down Expand Up @@ -208,6 +220,30 @@ public function setStartsBeforeOrAt($startsBeforeOrAt): EventQuery
return $this;
}

/**
* @param \DateTime $startsAfter
*
* @return EventQuery
*/
public function setStartsAfter($startsAfter): EventQuery
{
$this->startsAfter = $this->parseCarbon($startsAfter);

return $this;
}

/**
* @param \DateTime $startsAfterOrAt
*
* @return EventQuery
*/
public function setStartsAfterOrAt($startsAfterOrAt): EventQuery
{
$this->startsAfterOrAt = $this->parseCarbon($startsAfterOrAt);

return $this;
}

/**
* @param \DateTime $endsAfter
*
Expand All @@ -232,6 +268,30 @@ public function setEndsAfterOrAt($endsAfterOrAt): EventQuery
return $this;
}

/**
* @param \DateTime $endsBefore
*
* @return EventQuery
*/
public function setEndsBefore($endsBefore): EventQuery
{
$this->endsBefore = $this->parseCarbon($endsBefore);

return $this;
}

/**
* @param \DateTime $endsBeforeOrAt
*
* @return EventQuery
*/
public function setEndsBeforeOrAt($endsBeforeOrAt): EventQuery
{
$this->endsBeforeOrAt = $this->parseCarbon($endsBeforeOrAt);

return $this;
}

/**
* @param bool $value
*
Expand Down Expand Up @@ -288,6 +348,9 @@ public function setRangeStart($rangeStart = null): EventQuery
public function setRangeEnd($rangeEnd = null): EventQuery
{
$this->rangeEnd = $this->parseCarbon($rangeEnd);
if ($this->rangeEnd->format('His') === '000000') {
$this->rangeEnd->setTime(23, 59, 59);
}

return $this;
}
Expand Down Expand Up @@ -619,6 +682,26 @@ protected function beforePrepare(): bool
);
}

if ($this->startsAfter) {
$this->subQuery->andWhere(
Db::parseParam(
$table . '.[[startDate]]',
$this->extractDateAsFormattedString($this->startsAfter),
'>'
)
);
}

if ($this->startsAfterOrAt) {
$this->subQuery->andWhere(
Db::parseParam(
$table . '.[[startDate]]',
$this->extractDateAsFormattedString($this->startsAfterOrAt),
'>='
)
);
}

if ($this->endsAfter) {
$this->subQuery->andWhere(
Db::parseParam(
Expand All @@ -639,6 +722,26 @@ protected function beforePrepare(): bool
);
}

if ($this->endsBefore) {
$this->subQuery->andWhere(
Db::parseParam(
$table . '.[[endDate]]',
$this->extractDateAsFormattedString($this->endsBefore),
'<'
)
);
}

if ($this->endsBeforeOrAt) {
$this->subQuery->andWhere(
Db::parseParam(
$table . '.[[endDate]]',
$this->extractDateAsFormattedString($this->endsBeforeOrAt),
'<='
)
);
}

if ($this->endDate) {
$this->subQuery->andWhere(
Db::parseParam(
Expand All @@ -664,13 +767,7 @@ protected function beforePrepare(): bool
}

if ($this->rangeEnd) {
$rangeEnd = $this->rangeEnd->copy();

if ($rangeEnd->format('His') === '000000') {
$rangeEnd->setTime(23, 59, 59);
}

$rangeEndString = $this->extractDateAsFormattedString($rangeEnd);
$rangeEndString = $this->extractDateAsFormattedString($this->rangeEnd);

$this->subQuery->andWhere(
"$table.[[startDate]] <= :rangeEnd OR $table.[[freq]] = :freq",
Expand Down
16 changes: 15 additions & 1 deletion src/Resources/Bundles/EventEditBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,29 @@

class EventEditBundle extends CalendarAssetBundle
{
/** @var string - worst hack ever made */
static public $locale;

/**
* @return array
*/
public function getScripts(): array
{
return [
$scripts = [
'js/lib/fullcalendar/lib/moment.min.js',
'js/src/event-edit.js',
];

if (self::$locale) {
$locale = self::$locale;

$localeJsPath = __DIR__ . '/../Resources/js/lib/moment/locale/' . $locale . '.js';
if (file_exists($localeJsPath)) {
$scripts[] = 'js/lib/moment/locale/' . $locale . '.js';
}
}

return $scripts;
}

/**
Expand Down
13 changes: 9 additions & 4 deletions src/Services/EventsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Solspace\Calendar\Services;

use craft\base\Component;
use craft\base\Element;
use craft\base\ElementInterface;
use craft\db\Query;
use craft\events\SiteEvent;
Expand All @@ -27,16 +28,18 @@ class EventsService extends Component
/**
* Returns an event by its ID.
*
* @param int $eventId
* @param int $siteId
* @param int $eventId
* @param int $siteId
* @param bool $includeDisabled
*
* @return Event|ElementInterface
*/
public function getEventById(int $eventId, int $siteId = null): Event
public function getEventById(int $eventId, int $siteId = null, bool $includeDisabled = false): Event
{
$query = Event::find()
->setAllowedCalendarsOnly(false)
->enabledForSite(false)
->status($includeDisabled ? null : Element::STATUS_ENABLED)
->id($eventId);

if (null !== $siteId) {
Expand All @@ -51,15 +54,17 @@ public function getEventById(int $eventId, int $siteId = null): Event
*
* @param string $slug
* @param int $siteId
* @param bool $includeDisabled
*
* @return Event|ElementInterface
*/
public function getEventBySlug(string $slug, int $siteId = null): Event
public function getEventBySlug(string $slug, int $siteId = null, bool $includeDisabled = false): Event
{
return Event::find()
->slug($slug)
->setAllowedCalendarsOnly(false)
->enabledForSite(false)
->status($includeDisabled ? null : Element::STATUS_ENABLED)
->siteId($siteId)
->one();
}
Expand Down
Loading

0 comments on commit 5c17b9a

Please sign in to comment.