Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Search

 
Advanced search

8043 Posts in 1856 Topics- by 2099 Members - Latest Member: roi
Pages: [1]   Go Down
Print
Author Topic: Sorting of events  (Read 794 times)
0 Members and 1 Guest are viewing this topic.
sully
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« on: April 05, 2002, 07:22:00 AM »

Is there any way to sort entries alphabeticaly?
Logged

Sully
kayleigh
New Member
*

Karma: 0
Offline Offline

Posts: 0

Computer Analyst


WWW
« Reply #1 on: April 08, 2002, 01:09:00 PM »

Matt showed me the way a while back. Check here http://www.calendarscript.com/support/forum/Forum4/HTML/000189.ht ml

Stephanie Meemken
Webmaster, Minnesota Jaycees http://www.mnjaycees.org/

------------------
*Updated Link*

[This message has been edited by DanO (edited April 29, 2006).]

Logged

Stephanie Meemken
Webmaster, Minnesota Jaycees

http://www.mnjaycees.org/
sully
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« Reply #2 on: April 10, 2002, 07:15:00 AM »

OK I found the area in the calendar.pl where I'm supposed to make the changes but how do I or what do I change to make it an alphabetical listing?
Logged

Sully
TubaDave
New Member
*

Karma: 0
Offline Offline

Posts: 0

Student


WWW
« Reply #3 on: April 10, 2002, 12:49:00 PM »

So you found the line:

@{$Grid->{'grid'}->[$y]->[$x]->{'events'}} = sort { ($a->{'schedule'}->{'start'} <=> $b->{'schedule'}->{'start'}) | | ($a->{'details'}->{'id'} <=> $b->{'details'}->{'id'}) } @{$Grid->{'grid'}->[$y]->[$x]->{'events'}};

The general for of that line looks this:

@array = sort {
#return -1 if $a < $b, 0 if $a == $b, and 1 if $a > $b
} @array;

So you are basically passing an inline subroutine to sort, followed by an array you want sorted.  The sort function invokes the subroutine with $a and $b being two items in the array that need comparing.  Also, Perl is nice enough to provide the <=> (numbers) and the cmp (strings) functions that return -1, 0, or 1 as specified above.  Finally, if you don't provide a return statement, Perl returns the value of the last statement.

Now that you've got the general knowledge, here's how you would sort by Chapter, then start time:

@{$Grid->{'grid'}->[$y]->[$x]->{'events'}} = sort { ($a->{'details'}->{'chapter'} cmp $b->{'details'}->{'chapter'}) | | ($a->{'schedule'}->{'start'} <=> $b->{'schedule'}->{'start'}) | | ($a->{'details'}->{'id'} <=> $b->{'details'}->{'id'}) } @{$Grid->{'grid'}->[$y]->[$x]->{'events'}};

When I post that, the UBB is probably going to put a space between the to pipes ( | | ).  You'll need to remove the space.  So the above routine will compare to events by chapter (using cmp since I assume they are strings), then by time, and if you happen to have two things in the same chapter at the same time, by id.

Hope that helps.

------------------
David Whittaker
http://www.uabcm.com/
http://www.csworkbench.com/

Logged

sully
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« Reply #4 on: April 11, 2002, 08:13:00 AM »

Is there any way to sort by just events and not worry about time frame? Time frame is always set to all day. When I add the line above it sorts but I would like to keep everyday the same only changing the person who is responcible for each event. Thanks a bunch for the help. Working better.
Logged

Sully
TubaDave
New Member
*

Karma: 0
Offline Offline

Posts: 0

Student


WWW
« Reply #5 on: April 11, 2002, 03:04:00 PM »

Whoops!  I was looking at the link above and wrote the code to solve their problem instead of yours.  Either way, if you just want to sort by the title of the event, change that same line to this:

@{$Grid->{'grid'}->[$y]->[$x]->{'events'}} = sort { $a->{'details'}->{'title'} cmp $b->{'details'}->{'title'} } @{$Grid->{'grid'}->[$y]->[$x]->{'events'}};

Sorry for the mixup.

------------------
David Whittaker
http://www.uabcm.com/
http://www.csworkbench.com/

Logged

kayleigh
New Member
*

Karma: 0
Offline Offline

Posts: 0

Computer Analyst


WWW
« Reply #6 on: April 12, 2002, 04:10:00 PM »

You helped me a little further with problem, too   Have a good day, Dave!

------------------
Stephanie Meemken
Webmaster, Minnesota Jaycees
http://www.mnjaycees.org/

Logged

Stephanie Meemken
Webmaster, Minnesota Jaycees

http://www.mnjaycees.org/
sully
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« Reply #7 on: April 12, 2002, 06:52:00 PM »

That worked PERFECTLY !!!! . Thank you so much  
Logged

Sully
wderzawiec
New Member
*

Karma: 0
Offline Offline

Posts: 15

Web site coordinator


WWW
« Reply #8 on: November 29, 2004, 09:10:00 PM »

Hi all,

I'd like to have events on the monthly grid show in chronological order if they have a start time, but in alphabetical order if they are "all day".  I changed the code in calendar.cgi (had to change the extension for it to work on my server) from this:

@{$Grid->{'grid'}->[$y]->[$x]->{'events'}} = sort { ($a->{'schedule'}->{'start'} <=> $b->{'schedule'}->{'start'}) | | ($a->{'details'}->{'id'} <=> $b->{'details'}->{'id'}) } @{$Grid->{'grid'}->[$y]->[$x]->{'events'}};

to this:

@{$Grid->{'grid'}->[$y]->[$x]->{'events'}} = sort { ($a->{'schedule'}->{'start'} <=> $b->{'schedule'}->{'start'}) | | ($a->{'details'}->{'title'} cmp $b->{'details'}->{'title'}) } @{$Grid->{'grid'}->[$y]->[$x]->{'events'}};


I assumed that since all day events were being sorted by ID, if I just changed the 'id' to 'title', and changed <=> to cmp, the all day events would be sorted by title.  But it's not working.  The events that have start times get sorted by title, but not the all-day ones, they seem to default to sort by id.  What I am doing wrong?  Thanks very much for your help, this is a very helpful forum.

Wendy

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #9 on: November 30, 2004, 12:54:00 PM »

** But it's not working. The events that have start times get sorted by title, but not the all-day ones **

Just a guess but try changing the | | in the sort parameter to && so it sorts on both criteria. Events of the same time should be sorted by title then too.

As I said, it is just a guess though.

Failing that, make sure your spellings are correct and that there is no space between the | | in the sort expression.

Dan O.

------------------

Logged
wderzawiec
New Member
*

Karma: 0
Offline Offline

Posts: 15

Web site coordinator


WWW
« Reply #10 on: November 30, 2004, 01:56:00 PM »

Hm.  I tried the && and it seemed to show everything by ID.  So I tried the | | again and it seems to be doing what I want now.  I think the problem was that there were two all_day events that I wanted to show in alphabetical order, but one was a recurring event and the other was a single event. The recurring event was showing before the single event, even though it should have come after alphabetically.  I guess if I am going to be that picky I'll need to make them all single events. :-)  Thanks again for your help!!!

------------------

Logged
kcatmull
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« Reply #11 on: December 23, 2004, 09:23:00 AM »

I'd like our calendar to sort events chronologically, by start time, but currently it's not doing that--or rather, itseems to do it on some dates, but not on others.
http://www.hydeparktheatre.org/site/index.html

January 30, 2005 is an example of a date where events are sorted randomly

Is there a way to make it sort chronologically?

------------------

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #12 on: December 23, 2004, 01:53:00 PM »

** I'd like our calendar to sort events chronologically, by start time **

If you find the lines (there are 4) in the default.html template file:

<%FOREACH EVENT%>

You can try adding

code:
<% @$EVENTS = sort {$a->{'schedule'}->{'start_time'} <=> $b->{'schedule'}->{'start_time'} } @$EVENTS; %>

On the line immediately before them.

This is untested so use at your own risk and be sure to keep a back up of original files just in case.

Dan O.

------------------

Logged
Pages: [1]   Go Up
Print
Jump to: