Sorting CG Calendar by a certain field

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
mlestat1131
Forum Members
Forum Members
Posts: 41
Joined: Sat Sep 15, 2012 9:12 pm
Location: Columbus, Ohio

Sorting CG Calendar by a certain field

Post by mlestat1131 »

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
mlestat1131
Forum Members
Forum Members
Posts: 41
Joined: Sat Sep 15, 2012 9:12 pm
Location: Columbus, Ohio

Re: Sorting CG Calendar by a certain field

Post by mlestat1131 »

Nevermind, I figured this out...

Thanks
Matthew
User avatar
paulbaker
Dev Team Member
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

Post by paulbaker »

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
mlestat1131
Forum Members
Forum Members
Posts: 41
Joined: Sat Sep 15, 2012 9:12 pm
Location: Columbus, Ohio

Sorting CG Calendar by a certain field (Solution)

Post by mlestat1131 »

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

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);
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

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">&nbsp;</div>
{if isset($event.fields)}
  <div class="workshop_presenter">
    {foreach $event.fields as $fieldname => $fieldrec}
      {$fieldname}:&nbsp;{$fieldrec.field_value}<br/>
    {/foreach}
  </div>
{/if}
      {if $details != ''}
       {$event.event_details}
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.
User avatar
paulbaker
Dev Team Member
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

Post by paulbaker »

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
Post Reply

Return to “The Lounge”