Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/app/src/pages/calendar/calendar.fullcalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { PopoverViewEvent } from "./popovers/view-event/view-event";
export const CalendarFullcalendar: FC = () => {
const { hidePopover, showPopover } = usePopover();
const { view, setView, isReady } = useViewSettings();
const { currentDay, language, formats, weekStartDay, overlapThresholdString } = useConfig();
const { currentDay, language, formats, weekStartDay, overlapThresholdString, canEditEvents, allowEventsToBeModifiedByDragAndDrop } = useConfig();

const calendar = useRef<FullCalendar>(null);
const [draft, setDraft] = useState<CalendarCreateDraft | null>(null);
Expand Down Expand Up @@ -275,6 +275,7 @@ export const CalendarFullcalendar: FC = () => {
nextDayThreshold={overlapThresholdString}
fixedWeekCount
dayMaxEventRows
editable={canEditEvents && allowEventsToBeModifiedByDragAndDrop}
selectable
selectMirror={false}
selectMinDistance={5}
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type CalendarConfig = {
currentSiteId: number;
currentDay: Date;
siteMap: SiteMap;
allowEventsToBeModifiedByDragAndDrop: boolean;
Comment thread
seandelaney marked this conversation as resolved.
Outdated
isQuickCreateEnabled: boolean;
isMultiSite: boolean;
canEditEvents: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/plugin/src/Controllers/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function actionIndex(?string $year = null, ?string $month = null, ?string
'canEditEvents' => $user && $user->can('calendar-manageEvents') && !empty($calendarOptions),
'isMultiSite' => \Craft::$app->getIsMultiSite(),
'isQuickCreateEnabled' => $this->getSettingsService()->isQuickCreateEnabled(),
'allowEventsToBeModifiedByDragAndDrop' => $this->getSettingsService()->allowEventsToBeModifiedByDragAndDrop(),
'weekStartDay' => $this->getSettingsService()->getFirstDayOfWeek(),
'overlapThreshold' => $this->getSettingsService()->getOverlapThreshold(),
];
Expand Down
75 changes: 38 additions & 37 deletions packages/plugin/src/Elements/Db/EventQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,16 @@ public function setOverlapThreshold(?int $overlapThreshold = null): self

protected function beforePrepare(): bool
{
$events = Event::TABLE;
$eventsTable = Event::TABLE;
$eventsAlias = 'calendar_events';
// $occurrences = OccurrenceRecord::TABLE;
$calendar = CalendarRecord::TABLE;
$users = Table::USERS;

$this->joinElementTable($events);
$this->joinElementTable($eventsTable);
if (!$this->joinedTables) {
$this->join('INNER JOIN', $calendar, "{$calendar}.[[id]] = {$events}.[[calendarId]]");
$this->join('LEFT JOIN', $users, "{$users}.[[id]] = {$events}.[[authorId]]");
$this->join('INNER JOIN', $calendar, "{$calendar}.[[id]] = [[{$eventsAlias}.calendarId]]");
$this->join('LEFT JOIN', $users, "{$users}.[[id]] = [[{$eventsAlias}.authorId]]");

$this->joinedTables = true;
}
Expand All @@ -345,25 +346,25 @@ protected function beforePrepare(): bool
// $occExists = (new Query())
// ->select(new Expression('1'))
// ->from(["occ" => $occurrences])
// ->where("[[occ.eventId]] = {$events}.[[id]]")
// ->where("[[occ.eventId]] = [[{$eventsAlias}.id]]")
// ;
//
// $this->subQuery->andWhere(['exists', $occExists]);

$this->query->select([
$events.'.[[calendarId]]',
$events.'.[[authorId]]',
$events.'.[[startDate]]',
$events.'.[[endDate]]',
$events.'.[[until]]',
$events.'.[[timezone]]',
$events.'.[[allDay]]',
$events.'.[[rrule]]',
$events.'.[[repeatType]]',
$events.'.[[repeatEndType]]',
$events.'.[[postDate]]',
$events.'.[[dateCreated]]',
$events.'.[[dateUpdated]]',
"[[{$eventsAlias}.calendarId]]",
"[[{$eventsAlias}.authorId]]",
"[[{$eventsAlias}.startDate]]",
"[[{$eventsAlias}.endDate]]",
"[[{$eventsAlias}.until]]",
"[[{$eventsAlias}.timezone]]",
"[[{$eventsAlias}.allDay]]",
"[[{$eventsAlias}.rrule]]",
"[[{$eventsAlias}.repeatType]]",
"[[{$eventsAlias}.repeatEndType]]",
"[[{$eventsAlias}.postDate]]",
"[[{$eventsAlias}.dateCreated]]",
"[[{$eventsAlias}.dateUpdated]]",
$users.'.[[username]]',
$calendar.'.[[name]]',
]);
Expand All @@ -377,7 +378,7 @@ protected function beforePrepare(): bool
}

if (!$isWildcard) {
$this->subQuery->andWhere(Db::parseParam($events.'.[[calendarId]]', $this->calendarId));
$this->subQuery->andWhere(Db::parseParam("[[{$eventsAlias}.calendarId]]", $this->calendarId));
}
}

Expand All @@ -390,14 +391,14 @@ protected function beforePrepare(): bool
}

if ($this->authorId) {
$this->subQuery->andWhere(Db::parseParam($events.'.[[authorId]]', $this->authorId));
$this->subQuery->andWhere(Db::parseParam("[[{$eventsAlias}.authorId]]", $this->authorId));
}

if ($this->dateCreated) {
$value = $this->dateCreated;
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[dateCreated]]',
"[[{$eventsAlias}.dateCreated]]",
\is_array($value) ? $value : $this->extractDateAsFormattedString($value)
)
);
Expand All @@ -407,7 +408,7 @@ protected function beforePrepare(): bool
$value = $this->dateUpdated;
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[dateUpdated]]',
"[[{$eventsAlias}.dateUpdated]]",
\is_array($value) ? $value : $this->extractDateAsFormattedString($value)
)
);
Expand All @@ -417,7 +418,7 @@ protected function beforePrepare(): bool
$value = $this->postDate;
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[postDate]]',
"[[{$eventsAlias}.postDate]]",
\is_array($value) ? $value : $this->extractDateAsFormattedString($value)
)
);
Expand All @@ -426,7 +427,7 @@ protected function beforePrepare(): bool
if ($this->startDate) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[startDate]]',
"[[{$eventsAlias}.startDate]]",
$this->extractDateAsFormattedString($this->startDate)
)
);
Expand All @@ -435,7 +436,7 @@ protected function beforePrepare(): bool
if ($this->startsBefore) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[startDate]]',
"[[{$eventsAlias}.startDate]]",
$this->extractDateAsFormattedString($this->startsBefore),
'<'
)
Expand All @@ -445,7 +446,7 @@ protected function beforePrepare(): bool
if ($this->startsBeforeOrAt) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[startDate]]',
"[[{$eventsAlias}.startDate]]",
$this->extractDateAsFormattedString($this->startsBeforeOrAt),
'<='
)
Expand All @@ -455,7 +456,7 @@ protected function beforePrepare(): bool
if ($this->startsAfter) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[startDate]]',
"[[{$eventsAlias}.startDate]]",
$this->extractDateAsFormattedString($this->startsAfter),
'>'
)
Expand All @@ -465,7 +466,7 @@ protected function beforePrepare(): bool
if ($this->startsAfterOrAt) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[startDate]]',
"[[{$eventsAlias}.startDate]]",
$this->extractDateAsFormattedString($this->startsAfterOrAt),
'>='
)
Expand All @@ -475,7 +476,7 @@ protected function beforePrepare(): bool
if ($this->endsAfter) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[endDate]]',
"[[{$eventsAlias}.endDate]]",
$this->extractDateAsFormattedString($this->endsAfter),
'>'
)
Expand All @@ -485,7 +486,7 @@ protected function beforePrepare(): bool
if ($this->endsAfterOrAt) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[endDate]]',
"[[{$eventsAlias}.endDate]]",
$this->extractDateAsFormattedString($this->endsAfterOrAt),
'>='
)
Expand All @@ -495,7 +496,7 @@ protected function beforePrepare(): bool
if ($this->endsBefore) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[endDate]]',
"[[{$eventsAlias}.endDate]]",
$this->extractDateAsFormattedString($this->endsBefore),
'<'
)
Expand All @@ -505,7 +506,7 @@ protected function beforePrepare(): bool
if ($this->endsBeforeOrAt) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[endDate]]',
"[[{$eventsAlias}.endDate]]",
$this->extractDateAsFormattedString($this->endsBeforeOrAt),
'<='
)
Expand All @@ -515,27 +516,27 @@ protected function beforePrepare(): bool
if ($this->endDate) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[endDate]]',
"[[{$eventsAlias}.endDate]]",
$this->extractDateAsFormattedString($this->endDate)
)
);
}

if ($this->allDay) {
$this->subQuery->andWhere(Db::parseParam($events.'.[[allDay]]', $this->allDay));
$this->subQuery->andWhere(Db::parseParam("[[{$eventsAlias}.allDay]]", $this->allDay));
}

if ($this->until) {
$this->subQuery->andWhere(
Db::parseParam(
$events.'.[[until]]',
"[[{$eventsAlias}.until]]",
$this->extractDateAsFormattedString($this->until)
)
);
}

if ($this->timezone) {
$this->subQuery->andWhere(Db::parseParam($events.'.[[timezone]]', $this->timezone));
$this->subQuery->andWhere(Db::parseParam("[[{$eventsAlias}.timezone]]", $this->timezone));
}

if ($this->allowedCalendarsOnly) {
Expand All @@ -548,7 +549,7 @@ protected function beforePrepare(): bool
}

if (!PermissionHelper::isAdmin() && Calendar::getInstance()->settings->isAuthoredEventEditOnly()) {
$this->subQuery->andWhere($events.'.[[authorId]]', \Craft::$app->user->id);
$this->subQuery->andWhere(["[[{$eventsAlias}.authorId]]" => \Craft::$app->user->id]);
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/plugin/src/Elements/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,9 @@ public function jsonSerialize(): array
'handle' => $this->getSite()->handle,
'language' => $this->getSite()->language,
],
'editable' => $this->isEditable(),
'canEdit' => $this->isEditable(),
'startEditable' => $this->isEditable() && Calendar::getInstance()->settings->allowEventsToBeModifiedByDragAndDrop(),
'durationEditable' => $this->isEditable() && Calendar::getInstance()->settings->allowEventsToBeModifiedByDragAndDrop(),
'enabled' => (bool) $this->enabled,
'backgroundColor' => $this->getCalendar()->color,
'borderColor' => $this->getCalendar()->getDarkerColor(),
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin/src/Models/SettingsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SettingsModel extends Model
public const DEFAULT_SHOW_MINI_CAL = true;
public const DEFAULT_SHOW_DISABLED_EVENTS = true;
public const DEFAULT_VIEW = Calendar::VIEW_DASHBOARD;
public const DEFAULT_ALLOW_EVENTS_TO_BE_MODIFIED_BY_DRAG_AND_DROP = true;
public const DEFAULT_ALLOW_QUICK_CREATE = true;
public const DEFAULT_AUTHORED_EVENT_EDIT_ONLY = false;
public const DEFAULT_FIRST_DAY_OF_WEEK = -1;
Expand All @@ -37,6 +38,7 @@ class SettingsModel extends Model
public array|bool|null $showDisabledEvents = null;

public array|bool|null $quickCreateEnabled = null;
public null|array|bool $allowEventsToBeModifiedByDragAndDrop = null;

public ?string $defaultView = null;

Expand Down Expand Up @@ -93,6 +95,7 @@ public function __construct(array $attributes = [])
$this->defaultView = self::DEFAULT_VIEW;
$this->guestAccess = null;
$this->quickCreateEnabled = self::DEFAULT_ALLOW_QUICK_CREATE;
$this->allowEventsToBeModifiedByDragAndDrop = self::DEFAULT_ALLOW_EVENTS_TO_BE_MODIFIED_BY_DRAG_AND_DROP;
$this->showDisabledEvents = self::DEFAULT_SHOW_DISABLED_EVENTS;
$this->authoredEventEditOnly = self::DEFAULT_AUTHORED_EVENT_EDIT_ONLY;
$this->firstDayOfWeek = self::DEFAULT_FIRST_DAY_OF_WEEK;
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/Resources/Bundles/EventEditBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public function getScripts(): array
}

return [
'js/event-builder/vendor.js',
'js/event-builder/event-builder.js',
'js/app/vendor.js',
'js/app/event-builder.js',
];
}
}
2 changes: 1 addition & 1 deletion packages/plugin/src/Resources/js/app/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/plugin/src/Resources/js/app/event-builder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/plugin/src/Resources/js/app/vendor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/plugin/src/Resources/js/app/widget-event.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/plugin/src/Services/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function showDisabledEvents(): bool
return $this->getSettingsModel()->showDisabledEvents;
}

public function allowEventsToBeModifiedByDragAndDrop(): bool
{
return $this->getSettingsModel()->allowEventsToBeModifiedByDragAndDrop;
}

public function isQuickCreateEnabled(): bool
{
return $this->getSettingsModel()->quickCreateEnabled;
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin/src/Transformers/FullCalTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Solspace\Calendar\Transformers;

use Solspace\Calendar\Bundles\Occurrences\OccurrenceList;
use Solspace\Calendar\Calendar;
use Solspace\Calendar\Elements\Event;
use Solspace\Calendar\Models\OccurrenceModel;

Expand Down Expand Up @@ -32,7 +33,7 @@ public function fromElement(Event $element): array
'borderColor' => $calendar->getDarkerColor(),
'textColor' => $calendar->getContrastColor(),

'editable' => true,
'editable' => Calendar::getInstance()->settings->allowEventsToBeModifiedByDragAndDrop(),
'rrule' => $element->getRRuleRFCString(),
];
}
Expand Down Expand Up @@ -70,7 +71,7 @@ public function fromModel(OccurrenceModel $model): array
'borderColor' => $model->calendar->getDarkerColor(),
'textColor' => $model->calendar->getContrastColor(),

'editable' => true,
'editable' => Calendar::getInstance()->settings->allowEventsToBeModifiedByDragAndDrop(),
'rrule' => $model->event->getRRuleRFCString(),
];
}
Expand Down
9 changes: 9 additions & 0 deletions packages/plugin/src/templates/settings/_general.twig
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@
errors: settings.getErrors('showDisabledEvents')
}) }}

{{ forms.lightswitchField({
label: "Allow events to be modified by drag and drop in Month/Week/Day views?"|t('calendar'),
instructions: "Allows all users with event creation privileges to use drag and drop to modify events."|t('calendar'),
id: 'allowEventsToBeModifiedByDragAndDrop',
name: 'settings[allowEventsToBeModifiedByDragAndDrop]',
on: settings.allowEventsToBeModifiedByDragAndDrop,
errors: settings.getErrors('allowEventsToBeModifiedByDragAndDrop')
}) }}

{{ forms.lightswitchField({
label: "Allow new events to be created in Month/Week/Day views?"|t('calendar'),
instructions: "Allows all users with event creation privileges to use the Quick Create event feature."|t('calendar'),
Expand Down
1 change: 1 addition & 0 deletions packages/plugin/src/templates/view/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
data-current-site-id="{{ selectedSiteId }}"
data-current-day="{{ currentDay.toDateString }}"
data-site-map="{{ siteMap|json_encode }}"
{% if allowEventsToBeModifiedByDragAndDrop %}data-allow-events-to-be-modified-by-drag-and-drop{% endif %}
{% if isQuickCreateEnabled %}data-can-quick-create{% endif %}
{% if isMultiSite %}data-is-multi-site{% endif %}
{% if currentUser and currentUser.can('calendar-manageEvents') and calendarOptions is not empty %}
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin/src/translations/de/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@
'Displays a side menu with mini calendar and list of calendars, allowing you to filter your event results.' => 'Zeigt ein seitliches Menü mit dem Mini-Kalender und einer Liste aller Kalender an, mit der Ereignisse gefiltert werden können.',
'Include Disabled Events in Month/Week/Day views?' => 'Deaktivierte Ereignisse in Monats-/Wochen-/Tagesansicht anzeigen?',
'Events that are disabled will be displayed in the views with faded styles.' => 'Deaktivierte Ereignisse werden mit einem ausgegrautem Stil angezeigt.',
'Allow events to be modified by drag and drop in Month/Week/Day views?' => 'Soll es möglich sein, Ereignisse in der Monats-/Wochen-/Tagesansicht per Drag & Drop zu bearbeiten?',
'Allows all users with event creation privileges to use drag and drop to modify events.' => 'Ermöglicht allen Benutzern mit Berechtigung zum Erstellen von Ereignissen, Ereignisse per Drag & Drop zu bearbeiten.',
'Default View' => 'Standardansicht',
'The default page to go to when clicking the Calendar nav item.' => 'Die Standardansicht, wenn im Menü auf den Kalendereintrag geklickt wird.',
'Allow new events to be created in Month/Week/Day views?' => 'Das Erstellen neuer Ereignisse in der Monats-/Wochen-/Tagesansicht zulassen?',
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin/src/translations/en-US/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
'Displays a side menu with mini calendar and list of calendars, allowing you to filter your event results.' => 'Displays a side menu with mini calendar and list of calendars, allowing you to filter your event results.',
'Include Disabled Events in Month/Week/Day views?' => 'Include Disabled Events in Month/Week/Day views?',
'Events that are disabled will be displayed in the views with faded styles.' => 'Events that are disabled will be displayed in the views with faded styles.',
'Allow events to be modified by drag and drop in Month/Week/Day views?' => 'Allow events to be modified by drag and drop in Month/Week/Day views?',
'Allows all users with event creation privileges to use drag and drop to modify events.' => 'Allows all users with event creation privileges to use drag and drop to modify events.',
'Default View' => 'Default View',
'The default page to go to when clicking the Calendar nav item.' => 'The default page to go to when clicking the Calendar nav item.',
'Allow new events to be created in Month/Week/Day views?' => 'Allow new events to be created in Month/Week/Day views?',
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin/src/translations/lv/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@
'Displays a side menu with mini calendar and list of calendars, allowing you to filter your event results.' => 'Parāda sānu izvēlni ar mini kalendāru un kalendāru sarakstu, ļaujot filtrēt pasākumus pēc kalendāra.',
'Include Disabled Events in Month/Week/Day views?' => 'Iekļaut izslēgtos pasājumus mēneša/nedēļas/dienas skatos?',
'Events that are disabled will be displayed in the views with faded styles.' => 'Izslēgtie pasākumi tiks atrādīti kalendāra skatos caurspīdīgāki.',
'Allow events to be modified by drag and drop in Month/Week/Day views?' => 'Vai atļaut notikumus mainīt, velkot un nometot tos mēneša/nedēļas/dienas skatos?',
'Allows all users with event creation privileges to use drag and drop to modify events.' => 'Atļauj visiem lietotājiem ar notikumu izveides privilēģijām modificēt notikumus, izmantojot vilkšanas un nomešanas funkciju.',
'Default View' => 'Kalendāra skats pēc noklusējuma',
'The default page to go to when clicking the Calendar nav item.' => 'Lapa uz kuru doties spiežot uz Kalendāra navigācijas pogas',
'Allow new events to be created in Month/Week/Day views?' => 'Vai atļaut izveidot pasākumus kalendāra mēneša/nedēļas/dienas skatos',
Expand Down
Loading