I have a youth sports club website and each team has a calendar on it to show their upcoming events. Adding an event to a calendar seems like a lot of work, permissions-wise, to allow a simple ‘Head Coach’ to add/edit an event on their calendar. I don’t really relish the idea of fighting with Dashboard permissions to allow these coaches to only have access to the Calendar Events area. Is there no simple way for a coach to add an event FROM the calendar that’s sitting on their team’s page? I thought that by giving a person/group permission to add events to a calendar, that some button would automagically appear in the top Day/Week/Month menu called “Add Event” but nope, gotta go to the dashboard. Perhaps I’m missing something deeply philosophical about how this all works. LOL
1 Like
I do not believe that there is a simple way for a user who does not have Dashboard access to add an Event to a Calendar.
It’s not terribly hard to add an Event to a Calendar in code, if you wanted to generate your own block with a form on it and add that functionality.
This is the basic code to do it
<?php
use Concrete\Core\Calendar\Calendar;
use Concrete\Core\Calendar\Event\EventRepetition;
use Concrete\Core\Calendar\Event\EventService;
use Concrete\Core\Entity\Calendar\CalendarEvent;
use Concrete\Core\Entity\Calendar\CalendarEventVersionRepetition;
use Concrete\Core\Entity\Calendar\CalendarEventRepetition;
use Concrete\Core\User\User;
use Concrete\Core\Workflow\Request\ApproveCalendarEventRequest;
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
$calendarName = 'Calendar Name';
$calendar = Calendar::getByName($calendarName);
$eventService = $app->make(EventService::class);
$u = User::getByUserID(1);
$timezone = $calendar->getSite()->getConfigRepository()->get('timezone');
if (!$timezone) {
$timezone = date_default_timezone_get();
}
$timezone = new \DateTimeZone($timezone);
$repetitions = array();
$dateStart = date('Y-m-d H:i:s', strtotime($session['start']));
$dateEnd = date('Y-m-d H:i:s', strtotime($session['end']));
$pd = new EventRepetition();
$pd->setTimezone($timezone);
$pd->setStartDateAllDay(0);
$pd->setStartDate($dateStart);
$pd->setEndDate($dateEnd);
$pd->setRepeatPeriod($pd::REPEAT_NONE);
$pdEntity = new CalendarEventRepetition($pd);
$event = new CalendarEvent($calendar);
$eventVersion = $eventService->getVersionToModify($event, $u);
$eventVersion->setName($session['title']);
$eventVersion->setDescription(NULL);
$repetitions[] = new CalendarEventVersionRepetition($eventVersion, $pdEntity);
$eventService->addEventVersion($event, $calendar, $eventVersion, $repetitions);
$eventService->generateDefaultOccurrences($eventVersion);
//if you have attributes you want to fill out here
$eventVersion->setAttribute('event_type', 'Front of House');
$pkr = new ApproveCalendarEventRequest();
$pkr->setCalendarEventVersionID($eventVersion->getID());
$pkr->setRequesterUserID($u->getUserID());
$response = $pkr->trigger();
2 Likes
Well aren’t you a sweetheart! I’ll give it a go. Thx.
I have similar wish as mhawke does. I’d like to allow site visitor add his own event to the Event calendar BUT it won’t be publish live before admin has accepted/modified it.
Maybe site visitor should have to register first for a calendar user group.
Hope someone makes this as add-on to Marketplace or an update to Calendar and Events.