I am trying to sort CGCalendar events by a certain field, as all the events have the same day and time. This is for a conference when all the events have the same time but different topics etc... When I put them on the backend, the front end shows them as inserted. I need to show by a particular number.
Is there any way to do this?
I have seen this posting, but I am unable to get it to work for some reason...
viewtopic.php?f=7&t=69243
Sorting CG Calendar by a certain field
-
- Forum Members
- Posts: 41
- Joined: Sat Sep 15, 2012 9:12 pm
- Location: Columbus, Ohio
-
- Forum Members
- Posts: 41
- Joined: Sat Sep 15, 2012 9:12 pm
- Location: Columbus, Ohio
Re: Sorting CG Calendar by a certain field
Nevermind, I figured this out...
Thanks
Matthew
Thanks
Matthew
- paulbaker
- Dev Team Member
- Posts: 1465
- Joined: Sat Apr 18, 2009 10:09 pm
- Location: Maidenhead, UK
- Contact:
Re: Sorting CG Calendar by a certain field
Would you mind posting your solution to help others who search for the same thing?
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation
CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
https://docs.cmsmadesimple.org/troubles ... nformation
CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
-
- Forum Members
- Posts: 41
- Joined: Sat Sep 15, 2012 9:12 pm
- Location: Columbus, Ohio
Sorting CG Calendar by a certain field (Solution)
I was able to get the CG Calendar to sort using the Summary Field. This allowed me to use the summary field as a workshop # on the input of workshops for a conference.
This is the Code
You need to create a UDT with this info in it.
['event_summary'} calls the specific variable within the $events array
from there this is the code in the Calendar List View Template
The {sort} tag calls the array $events you then need to change the {foreach from=$events to {foreach from=$sorted
I am not sure if you are able to do the same thing with custom fields, but this solution worked for what I was wanting to do with it.
This is the Code
You need to create a UDT with this info in it.
['event_summary'} calls the specific variable within the $events array
Code: Select all
if (!function_exists('do_sort')) {
function do_sort($a, $b) {
return strcasecmp($a['event_summary'],$b['event_summary']);
}
}
$data = $params['data'];
usort($data, 'do_sort');
$smarty->assign('sorted', $data);
The {sort} tag calls the array $events you then need to change the {foreach from=$events to {foreach from=$sorted
Code: Select all
{sort data=$events}
{foreach from=$sorted key=key item=event}
<div class="calendar-event">
<div class="workshops">
<div class="workshop_time">{$details=$event.event_details|strip_tags|trim}
{if $event.event_summary != '' && $details != ''}{$event.event_summary}{/if} | {if $event.event_date_start == $event.event_date_end || $event.event_date_end == 0}
{$event.event_date_start|date_format:"%I %x"}
{else}
{if $event.event_date_start|date_format:" %B %e, %Y " == $event.event_date_end|date_format:" %B %e, %Y "}
{* event starts and ends on the same day *}
{fa icon='fa-clock-o'} {$event.event_date_start|date_format:"%l:%M %p"} {$lang.to} {$event.event_date_end|date_format:"%l:%M %p"}
{/if}
{/if}</div>
<div class="workshop_body">
<div class="workshop_header">{$event.event_title}</div>
<div class="clear"> </div>
{if isset($event.fields)}
<div class="workshop_presenter">
{foreach $event.fields as $fieldname => $fieldrec}
{$fieldname}: {$fieldrec.field_value}<br/>
{/foreach}
</div>
{/if}
{if $details != ''}
{$event.event_details}
- paulbaker
- Dev Team Member
- Posts: 1465
- Joined: Sat Apr 18, 2009 10:09 pm
- Location: Maidenhead, UK
- Contact:
Re: Sorting CG Calendar by a certain field
Great, thank you
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation
CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
https://docs.cmsmadesimple.org/troubles ... nformation
CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016