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.
There’s some really interesting things in here. Does anyone know how i would get a custom attribute value given an occurrence? Ex: I have an occurrence that is getting returned from $occurrence=EventOccurenceList()->getResults()
I can say $occurence->getStart(), ->getEnd(), ->getTitle() and get the correct info. But if i say getAttribute(‘attribute_handle’) i always get a null response even though i know it’s defined
What is the attribute?
If you using a event list I do something like this
if ($total = count($events)) {
foreach ($events as $occurrence) {
$event = $occurrence->getEvent();
$description = $event->getDescription();
$myattribute = $event->getAttribute('attribute_handle');
Thanks for taking the time to respond so quick! The attribute is a custom attribute with name vtiger_group_appointment . I know it has values because wen i’m editing the event from the calendar in the dashboard i display them and allow the user to edit them - the data is correct and changes. But when i execute the code below getAttribute always returns null
$list = new EventOccurrenceList();
$results = $list->getResults();
$data = [];
foreach ($results as $occurrence) {
$event = $occurrence->getEvent();
$obj = new \stdClass();
$obj->vtigerPrototypeEventId=$occurrence->getAttribute('vtiger_group_appointment');
$obj->id = $occurrence->getID();
$obj->title = $event->getName();
$obj->start = $occurrence->getStart();
$obj->end = $occurrence->getEnd();
$obj->allDay = false;
$repetition = $occurrence->getRepetition();
if ($repetition->isStartDateAllDay()) $obj->allDay = true;
$data[] = $obj;
}
var_dump($data);
Try just
echo $occurrence->getAttribute('vtiger_group_appointment')
Same result. However i think i found the problem and maybe a bug/suggested improvement. First, the attribute belongs to the event. That said, calling getAttribute on the occurrence is identical to calling it on the event ($occurence->getEvent()->getRecentVersion()->getAttributes($ak)), and, there is only one database record in the atDefault table.
Second, getAttributes on an occurrence, requires an attribute key not a handle. If I call:
Preformatted text
echo $occurrence->getAttribute(CollectionKey::getByHandle(‘vtiger_group_appointment’))`
if works great.
If you look at the getAttribute function of the attribute object interface, it specifies that it will accept a key or a handle…and i think within the event form that’s what we’re accessing. I don’t know what we’re really accessing when you use EventOccurenceList to return a list of occurences…because it only accept the key on getAttribute. i may dig into this some more.
Can anyone over here tell me how I would get the following done:
I’ve made custom attributes for my events, such as who organizes it, costs, website, email address. But on the detail page with the Calendar event block, it only shows the values of those attributes, not the names, so that looks a little weird and out of place. How do I get the template to show the attribute name and then the value?
<?php if (count($displayEventAttributes)) { ?>
<div class="ccm-block-calendar-event-attributes">
<?php foreach ($displayEventAttributes as $akID) {
$ak = EventKey::getByID($akID);
if (is_object($ak)) {
echo $event->getAttribute($ak->getAttributeKeyHandle(), 'display');
}
}
?>
</div>
<?php } ?>
Would love to hear from someone
You’d have to build and use a custom template for the Calendar Event block.