How can the basic info of an event be displayed? I know how to display custom event attributes, but I can not figure out how to display the basic info, e.g. event title, start/end time, description, calendar, etc.
I am not sure if I am missing the point but have you looked at basically placing the Calendar & Event blocks onto a page? There’s one for listing events within one calendar (Calendar or Event List) and another for displaying the information for one individual event (Calendar Event) which would include the ‘basic info’?
@dfirm Following our conversation in support, I’m posting my answer here so it can be useful to others
First, you grab your event attribute from the current page
$c = Page::getCurrentPage();
if ($c && !$c->isError()) {
$eventAtt = $c->getAttribute('class_attribute');
if ($eventAtt) {
// grab your information here
}
}
I am not 100% sure but I think you’d do something like this. Once you have your event attribute $eventAtt you can get the title and description like this:
$event = $eventAtt->getSelectedVersion();
$title = $event->getName();
$description = $event->getDescription();
$topics = $event->getCategories();
While start and end times are relative to occurrences so you’d do it like this:
$eventOccurrences = $eventAtt->getOccurrences();
if (is_array($eventOccurrences)) {
foreach($eventOccurrences as $occurrence) {
$startTime = $occurrence->getStart();
$endTime = $occurrence->getEnd();
// do something with it
}
}
```
@mnakalay thanks for posting this here. I was going to copy it over, but you beat me to it
Another issue I’ve run into and haven’t been able to find some documentation or other posts relating to it:
How do you retrieve the Occurrence Object by using the Occurrence ID?
Basically so you can use GET to parse the Occurrence ID from the URL and then retrieve that specific Occurrence info.
I found this in documentation - EventOccurrenceService::getByOccurrenceID() - but I get this error when I use it - Class ‘EventOccurrenceService’ not found.
@mnakalay slight update. I added -
use Concrete\Core\Calendar\Event\EventOccurrenceService;
to my view.php
but now I am getting this error -
Using $this
when not in object context - …/src/Calendar/Event/EventOccurrenceService.php 37
@dfirm Try this instead
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
$service = $app->make(EventOccurrenceService::class);
$occurence = $service->getByOccurrenceID(your_id);
I don’t want to push in on this topic but it has some relevance to the Calendar Event block. Is there a way to change the date and time formating that is output?
Change: 31 Aug 2021 to 31st August 2021
Use formatCustom()
along with the formatting you want:
$date = \Core::make('date');
$formatted = $date->formatCustom('jS F Y', $occurrence->getStart());
Minor addendum. Core::make is deprecated and any new code should be using $app->make or similar.
https://documentation.concretecms.org/developers/appendix/deprecated-code-reference-ongoing
Thank you Myq and JohntheFish. I have now managed to sort the date formatting out.
Can you please post your solution so others get help
This is how I solved the custom formatting in my case…
<?php
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
$date = $app->make('date');
$eventDate = $date->formatCustom('jS F Y', $occurrence->getStart());
echo '<h3>';
echo $eventDate;
echo '</h3>';
?>
Note: this example is only displaying the start date and if you wanted you could add the time as well by using the standard php date & time formatting.
I hope this may help someone. If there are tidier coding methods rather than the solution I have shown here you are welcome to add to this post.