Skip to content

Commit

Permalink
v2.0.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Mar 13, 2018
1 parent 849bb7c commit b332d8f
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 872 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Solspace Freeform Changelog

## 2.0.0-beta.2 - 2018-03-13
### Fixed
- Fixed a bug where the `calendar.events` function was not displaying events in order.
- Fixed a bug where the `calendar.month` function was not prioritizing multi-day events to be displayed first (to improve overall display of month view).
- Fixed a bug where the time picker was showing behind the Quick Create feature in CP Month/Week/Day views.
- Fixed a bug where Calendar wouldn't work correctly with sites using database table prefixes.
- Fixed a bug where the Quick Create feature would not work with title format option.
- Fixed a bug where URI and slug generation was not working correctly.
- Fixed a bug where the 'Enabled for Site' toggle was missing on Event Create/Edit view.
- Fixed a bug where the `calendar.events` function was not ordering events correctly.
- Fixed a bug where the `calendar.events` function would display an error when filtering with a calendar handle and searching.
- Fixed a bug where an error would show when attempting to edit events on the front end templates.

## 2.0.0-beta.1 - 2018-03-09
### Added
- Added compatibility for Craft 3.x.
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.0-beta.1",
"version": "2.0.0-beta.2",
"type": "craft-plugin",
"minimum-stability": "dev",
"authors": [
Expand Down
10 changes: 5 additions & 5 deletions src/Controllers/CalendarsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function actionEditCalendar(string $handle): Response
* @throws \yii\web\BadRequestHttpException
* @throws \yii\web\ForbiddenHttpException
*/
public function actionSaveCalendar()
public function actionSaveCalendar(): Response
{
$this->requirePostRequest();
$request = \Craft::$app->request;
Expand Down Expand Up @@ -119,9 +119,9 @@ public function actionSaveCalendar()
continue;
}

$siteSettings = new CalendarSiteSettingsModel();
$siteSettings->siteId = $site->id;
$siteSettings->hasUrls = !empty($postedSettings['uriFormat']);
$siteSettings = new CalendarSiteSettingsModel();
$siteSettings->siteId = $site->id;
$siteSettings->hasUrls = !empty($postedSettings['uriFormat']);
$siteSettings->enabledByDefault = (bool) $postedSettings['enabledByDefault'];

if ($siteSettings->hasUrls) {
Expand All @@ -139,7 +139,7 @@ public function actionSaveCalendar()


// Set the field layout
$fieldLayout = \Craft::$app->getFields()->assembleLayoutFromPost();
$fieldLayout = \Craft::$app->getFields()->assembleLayoutFromPost();
$fieldLayout->type = Event::class;
$calendar->setFieldLayout($fieldLayout);

Expand Down
10 changes: 2 additions & 8 deletions src/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Solspace\Calendar\Calendar;
use Solspace\Calendar\Elements\Event;
use Solspace\Calendar\Library\CalendarPermissionHelper;
use Solspace\Calendar\Library\DatabaseHelper;
use Solspace\Calendar\Library\DateHelper;
use Solspace\Calendar\Library\Exceptions\EventException;
use Solspace\Calendar\Library\RecurrenceHelper;
Expand Down Expand Up @@ -218,14 +217,9 @@ public function actionSaveEvent()

$event->enabledForSite = (bool) \Craft::$app->request->post('enabledForSite', $event->enabledForSite);
$event->title = \Craft::$app->request->post('title', $event->title);
$event->slug = \Craft::$app->request->post('slug', $event->slug);
$event->setFieldValuesFromRequest('fields');

$slug = \Craft::$app->request->post('slug', $event->slug);
if (!$event->id) {
$slug = DatabaseHelper::getSuitableSlug($event->title);
}
$event->slug = $slug;

if ($this->getEventsService()->saveEvent($event)) {
$exceptions = $values['exceptions'] ?? [];
$this->getExceptionsService()->saveExceptions($event, $exceptions);
Expand Down Expand Up @@ -255,7 +249,7 @@ public function actionSaveEvent()
\Craft::$app->session->setError(Calendar::t('Couldn’t save event.'));

if (\Craft::$app->request->isCpRequest) {
return $this->renderEditForm($event, $event->title);
return $this->renderEditForm($event, $event->title ?? '');
} else {
\Craft::$app->urlManager->setRouteParams(['event' => $event, 'errors' => $event->getErrors()]);
}
Expand Down
29 changes: 13 additions & 16 deletions src/Controllers/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public function actionMonthData(): Response
{
$this->requirePostRequest();

$dateRangeStart = \Craft::$app->request->post('dateRangeStart');
$dateRangeEnd = \Craft::$app->request->post('dateRangeEnd');
$calendars = \Craft::$app->request->post('calendars');
$nonEditable = \Craft::$app->request->post('nonEditable');
$siteId = \Craft::$app->request->post('siteId');
$rangeStart = \Craft::$app->request->post('rangeStart');
$rangeEnd = \Craft::$app->request->post('rangeEnd');
$calendars = \Craft::$app->request->post('calendars');
$nonEditable = \Craft::$app->request->post('nonEditable');
$siteId = \Craft::$app->request->post('siteId');

$criteria = [
'rangeStart' => $dateRangeStart,
'rangeEnd' => $dateRangeEnd,
'rangeStart' => $rangeStart,
'rangeEnd' => $rangeEnd,
];

$calendarIds = null;
Expand Down Expand Up @@ -68,18 +68,15 @@ public function actionTargetTime(
int $year = null,
int $month = null,
int $day = null
): Response {
): Response
{
$view = $view ?? Calendar::VIEW_MONTH;
$calendarView = $view;

switch ($calendarView) {
case Calendar::VIEW_WEEK:
$calendarView = 'agendaWeek';
break;

case Calendar::VIEW_DAY:
$calendarView = 'agendaDay';
break;
if ($calendarView === Calendar::VIEW_WEEK) {
$calendarView = 'agendaWeek';
} else if ($calendarView === Calendar::VIEW_DAY) {
$calendarView = 'agendaDay';
}

$currentSiteId = \Craft::$app->sites->currentSite->id;
Expand Down
59 changes: 46 additions & 13 deletions src/Elements/Db/EventQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ class EventQuery extends ElementQuery
/** @var int */
private $totalCount;

public function __construct(string $elementType, array $config = [])
{
$this->orderBy = ['startDate' => SORT_ASC];

parent::__construct($elementType, $config);
}

/**
* @param int|array $value
*
Expand Down Expand Up @@ -331,11 +338,7 @@ public function all($db = null): array
$this->cutOffExcess($this->eventCache);

$this->cacheToStorage();

if (!$this->loadOccurrences && $this->shouldOrderByStartDate()) {
// Order the events based on strict ordering rules
$this->orderEvents($this->events);
}
$this->orderEvents($this->events);

// Build up an event cache, to be accessed later
$this->cacheEvents();
Expand Down Expand Up @@ -427,22 +430,23 @@ public function getEventsByHour(Carbon $date): array
*/
protected function beforePrepare(): bool
{
$table = Event::TABLE_STD;
$calendarTable = CalendarRecord::TABLE_STD;
$table = Event::TABLE_STD;
$calendarTable = CalendarRecord::TABLE;
$calendarTableStd = CalendarRecord::TABLE_STD;

// join in the products table
$this->joinElementTable($table);

$hasCalendarJoin = false;
if (\is_array($this->join)) {
foreach ($this->join as $joinData) {
if (isset($joinData[1]) && $joinData[1] === $calendarTable) {
if (\is_array($this->subQuery->join)) {
foreach ($this->subQuery->join as $joinData) {
if (isset($joinData[1]) && $joinData[1] === $calendarTableStd) {
$hasCalendarJoin = true;
}
}
}
if (!$hasCalendarJoin) {
$this->innerJoin($calendarTable, "`$calendarTable`.`id` = `$table`.`calendarId`");
$this->subQuery->innerJoin($calendarTable, "$calendarTable.id = $table.calendarId");
}

// select the price column
Expand Down Expand Up @@ -848,10 +852,19 @@ function (array $arrayA, array $arrayB) use ($modifier) {
private function orderEvents(array &$events)
{
$modifier = $this->getSortModifier();
$orderBy = $this->getOrderByField();

usort(
$events,
function (Event $eventA, Event $eventB) use ($modifier) {
function (Event $eventA, Event $eventB) use ($modifier, $orderBy) {
if ($orderBy !== 'startDate') {
if ($modifier > 0) {
return $eventA->{$orderBy} <=> $eventB->{$orderBy};
}

return $eventB->{$orderBy} <=> $eventA->{$orderBy};
}

if ($eventA->diffInDays($eventB)) {
return $eventA->compareStartDates($eventB) * $modifier;
}
Expand Down Expand Up @@ -1027,12 +1040,32 @@ private function getSortModifier(): int
if (\is_array($this->orderBy) && count($this->orderBy)) {
$sortDirection = reset($this->orderBy);

return $sortDirection === SORT_ASC ? 1 : -1;
if (is_numeric($sortDirection)) {
return $sortDirection === SORT_DESC ? -1 : 1;
}

return strtolower($sortDirection) === 'desc' ? -1 : 1;
}

return 1;
}

/**
* Returns the first order by field
*
* @return string|null
*/
private function getOrderByField()
{
if (\is_array($this->orderBy) && \count($this->orderBy)) {
$keys = array_keys($this->orderBy);

return reset($keys);
}

return $this->orderBy;
}

/**
* @return EventsService
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Elements/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ public static function isLocalized(): bool
return true;
}

/**
* @return bool
*/
public static function hasUris(): bool
{
return true;
}

/**
* @param array $config
*
Expand Down
35 changes: 4 additions & 31 deletions src/Library/ColorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,22 @@

namespace Solspace\Calendar\Library;

use Solspace\Calendar\Library\ColorJizz\Exceptions\InvalidArgumentException;
use Solspace\Calendar\Library\ColorJizz\Formats\Hex;

class ColorHelper
class ColorHelper extends \Solspace\Commons\Helpers\ColorHelper
{
/**
* Generates a random HEX color code
*
* @return string
*/
public static function randomColor()
{
return sprintf('#%06X', mt_rand(0, 0xFFFFFF));
}

/**
* Lightens/darkens a given colour (hex format), returning the altered colour in hex format.7
*
* @param string $hexString Colour as hexadecimal (with or without hash);
* @param float $percent Decimal (0.2 = lighten by 20%, -0.4 = darken by 40%)
*
* @return string Lightened/Darkend colour as hexadecimal (with hash);
* @throws InvalidArgumentException
*/
public static function lightenDarkenColour($hexString, $percent)
public static function lightenDarkenColour($hexString, $percent): string
{
return '#' . Hex::fromString($hexString)->brightness($percent * 100);
}

/**
* Determines if the contrasting color to be used based on a HEX color code
*
* @param string $hexColor
*
* @return string
*/
public static function getContrastYIQ($hexColor)
{
$hexColor = str_replace('#', '', $hexColor);

$r = hexdec(substr($hexColor, 0, 2));
$g = hexdec(substr($hexColor, 2, 2));
$b = hexdec(substr($hexColor, 4, 2));
$yiq = (($r * 299) + ($g * 587) + ($b * 114)) / 1000;

return ($yiq >= 128) ? 'black' : 'white';
}
}
24 changes: 12 additions & 12 deletions src/Library/DatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class DatabaseHelper
const OPERATOR_NOT_IN = 'not';
const OPERATOR_IN = 'in';

private static $operatorList = array(
private static $operatorList = [
self::OPERATOR_NOT_EQUAL,
self::OPERATOR_NOT_IN,
);
];

/**
* Looks through the database to see if a given $slug has been used
Expand All @@ -33,8 +33,8 @@ public static function getSuitableSlug($slug): string
while ($iterator <= 100) {
$result = (new Query())
->select(['id'])
->from('elements_sites')
->where(array('slug' => $slug))
->from('{{%elements_sites}}')
->where(['slug' => $slug])
->scalar();

if ($result) {
Expand All @@ -59,33 +59,33 @@ public static function getSuitableSlug($slug): string
*/
public static function prepareOperator($value): array
{
if (is_array($value)) {
if (\is_array($value)) {
$firstValue = reset($value);

if (in_array($firstValue, self::$operatorList, true)) {
if (\in_array($firstValue, self::$operatorList, true)) {
$operator = array_shift($value);
} else {
$operator = self::OPERATOR_IN;
}

return array($operator, $value);
return [$operator, $value];
}

$operator = self::OPERATOR_EQUALS;
foreach (self::$operatorList as $searchableOperator) {
$length = strlen($searchableOperator);
if (substr($value, 0, $length) === $searchableOperator) {
$length = \strlen($searchableOperator);
if (0 === strpos($value, $searchableOperator)) {
$operator = $searchableOperator;
$value = substr($value, $length + 1);
$value = substr($value, $length + 1);

if ($operator === self::OPERATOR_NOT_IN) {
$value = explode(',', $value);
}

return array($operator, $value);
return [$operator, $value];
}
}

return array($operator, $value);
return [$operator, $value];
}
}
Loading

0 comments on commit b332d8f

Please sign in to comment.