Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#589 2011-01-11 15:55:08

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: smd_calendar: complete schedule / event / calendar / diary

Thanks Stef. time="today" sounds like a very good idea.

Hmm, I might be pasting it wrong but nothing is displayed when I try that.

Offline

#590 2011-01-11 16:18:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: smd_calendar: complete schedule / event / calendar / diary

Algaris wrote:

Hmm, I might be pasting it wrong but nothing is displayed when I try that.

Nope, nothing wrong with you. I was being a tool (told you I hadn’t tested it!)

Now I’ve just tried it, here’s a better version:

<txp:smd_article_event form="events"
   from='<txp:smd_cal_now format="%Y-%m-%d 00:00:00" />'
   to='<txp:smd_cal_now format="%Y-%m-%d 23:59:59" />' />

Last edited by Bloke (2011-01-11 16:19:01)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#591 2011-01-11 16:32:56

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: smd_calendar: complete schedule / event / calendar / diary

Whoo! You rock Stef. This should be enough for now, although I’ll ask one more question that’ll be very useful further down the line.

Is it possible to display all the events for Monday to Sunday, for the current week, in the same way as the example you provided above. Ideally I’d like a heading saying Week Beginning Date (st, nd, th) Month Year and each days events under a heading of that day. For example

Week Beginning 6th December 2010

Monday
Event 1
Event 2
Event 3
Etc.

Tuesday
Event 1
Event 2
Event 3
Etc.

And so on.

I haven’t had time to experiment with this yet, so I don’t know what is possible at the moment. Thanks.

Last edited by Algaris (2011-01-11 16:42:47)

Offline

#592 2011-01-11 17:00:31

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: smd_calendar: complete schedule / event / calendar / diary

Algaris wrote:

Is it possible to display all the events for Monday to Sunday, for the current week

Yes, with some cunning (I don’t have time to impart said cunning right now, but I’ve seen it done).

It will largely depend how you want the info to be displayed, i.e. how it interacts with the URL. Do you want people to be able to click on a date on the calendar and see that week’s events or will it always show just the current week (or maybe current week + next week)?

Off the top of my head, what you’ll need to do is determine a start date — be that from the URL bar or some other mechanism — then use smd_cal_now (or maybe some PHP) to either figure out the end date, or simply add 7 days to the start date using smd_cal_now’s offset="7 days" feature. Then you can plug them into smd_article_event as above. Determining the start date might be tricky if, say, today is Tuesday and you want the previous Sunday as the start date. But PHP’s strtotime() function might help with that.

Once you have the start and end dates figured out, you’ll probably need some <txp:if_different> magic in your smd_article_event form/container to only output the heading once for each day and after that the usual tags to show all the events (up to your limit/eventlimit settings).

Someone here has probably done this and can give you some pointers if you get stuck in the details.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#593 2011-01-12 08:33:02

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: smd_calendar: complete schedule / event / calendar / diary

Thanks Stef. It’s good that your asking me these questions, it makes me think of all the possibilities.

In my calendar I have two views.

1) Daily View
This is in effect the homepage showing just the events for today’s date. I have a menu that divides the calendar into four sub calendars using categories, with the homepage displaying all of them. The daily view will need to work if a date is clicked in the smd mini calendar and if a category is chosen.

2) Weekly view
This will use its own section ‘week’. When the week view button is clicked it will display the current weeks events which will always be Monday – Sunday

For example if someone is viewing Thursday 13th January and they click the week view button the events from Monday 10th – Sunday 16th of January will be shown.

If a date from the mini calendar is clicked it will switch to the daily view for that day. If the week view button is clicked again it will respond as above. If a category is chosen it will display only the events from that category but keep the week view.

Throughout the calendar will need to remember any categories or sections it has been assigned.

—Edit—

Thinking about it I’m also going to need a day button. I guess if someone clicks the day button it can take them to the Monday of the current week they are viewing.

Crickey this is getting complicated.

Last edited by Algaris (2011-01-12 12:16:40)

Offline

#594 2011-01-12 15:30:02

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: smd_calendar: complete schedule / event / calendar / diary

Algaris wrote:

The daily view will need to work if a date is clicked in the smd mini calendar and if a category is chosen.

OK, that’s fairly easy to do. But do yourself a favour and don’t use the bulit-in mini-cal. Use a large calendar and fudge it to look like a minical using cellform. Here’s one way of doing it. Just note the caveat that you’ll need to alter the logic if you have more than one event per day.

When the week view button is clicked it will display the current weeks events which will always be Monday – Sunday

OK, that is a bit trickier, but not insurmountable. First question: will it display the current week’s events even if the person views the site on, say, Sunday? That might not be the most useful thing to do, so from a usability perspective you should probably make sure it’s nice and easy for them to click to see the following week’s view (you probably figured that already though, right?!)

I think we may need some PHP to do this but the calendar might be able to figure it out. I’d be tempted to try and use the ISO week as a go-between because that’s pretty much universal and also, coincidentally, always runs from Monday – Sunday by convention. So if you can get the calendar to either display the ISO week or simply use the ISO week behind the scenes and pass it about on the URL then your smd_article_event can pick it up and find the start and end.

As a starter for ten, here’s a neat bit of code I found to figure out the start and end day given the current ISO week. It uses a little-known format parameter to strftime() that can specify not only the current year and ISO week but also the offset in days (and in our case, hours). Here goes:

<txp:hide>Find and store the current ISO week</txp:hide>
<txp:variable name="isoweek"><txp:smd_cal_now format="%V" /></txp:variable>

<txp:smd_article_event
   from='<txp:smd_cal_now format=''%Y-W<txp:variable name="isoweek" />'' />'
   to='<txp:smd_cal_now format=''%Y-W<txp:variable name="isoweek" />-7 23:59:59'' />'
   form="events" />

The -7 23:59:59 simply says “find me the date 7 days 23hrs, 59mins and 59secs on from the start of this ISO week (the from doesn’t need it because it defaults to ‘0’ which is midnight on the first day of the current week, i.e. Monday morning). How’s that for some calendar-fu :-)

P.S. also note the double apostrophes because we’re putting tags-in-tags-in-tags!

Throughout the calendar will need to remember any categories or sections it has been assigned.

You’ll probably need to look into the maintain attribute. That’ll give you a headache but it’ll be worth it if you can figure it out.

Last edited by Bloke (2011-01-12 15:31:14)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#595 2011-01-12 16:19:55

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: smd_calendar: complete schedule / event / calendar / diary

Thanks again Stef. I’ll have a look over this tomorrow and see how it goes.

Offline

#596 2011-01-14 10:27:31

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: smd_calendar: complete schedule / event / calendar / diary

Algaris wrote:
The daily view will need to work if a date is clicked in the smd mini calendar and if a category is chosen.

Bloke wrote:
OK, that’s fairly easy to do. But do yourself a favour and don’t use the bulit-in mini-cal. Use a large calendar and fudge it to look like a minical using cellform. Here’s one way of doing it. Just note the caveat that you’ll need to alter the logic if you have more than one event per day.

I’m working though your post bit by bit so I don’t run ahead and get confused. It’s a treasure trove of information, thank you for posting it.

I see what you mean when you say it doesn’t work well with more than one event per day. It tries to fit every event into the calendar with the date as the hyperlink text.

I’m experimenting with this so I might come up with a solution. What I’m hoping to achieve is when you click on a date it displays a list of events using <txp:smd_article_event form="events" section="calendar" /> (or something simular) for that day made up of <txp:title /> and <txp:excerpt /> tags elsewhere on the page (i.e not inside the calendar).

Offline

#597 2011-01-14 12:08:39

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: smd_calendar: complete schedule / event / calendar / diary

Algaris wrote:

it doesn’t work well with more than one event per day. It tries to fit every event into the calendar with the date as the hyperlink text.

Yes. That’s just a way to emulate what the minical does but to have the advantage of using other things that are only available in a large calendar. A few simple ways round this:

  1. Continue to link using the date from every calendar event, then on the destination page (which of course could be the same page if you wished), read the date and display a listing of all events on that day. You can utilise smd_article_event on this page to display them all as a list and perhaps they could open/close using a jQuery accordion. Or, you could simply further link to each individual article.
  2. Link each individual event to its individual article directly from the calendar (like the large calendar does by default) but display the information in a compressed format in each cell so the calendar doesn’t take up too much space. You could just put little markers in if you like and make the abridged info pop up when you hover over each and maybe link to the individual articles from there.

I’m sure there are others. The point is, if you use a large calendar you can decide how you do it and it’s pretty much up to your imagination. The small calendar is too limited to be of much use, which is why I’m dropping it in a future version (well, the large and small will still be available but the minical will (internally) actually be a large calendar made to look like a minical so it makes the code smaller).

Hope that gives you some inspiration / ideas.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#598 2011-01-14 13:26:37

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: smd_calendar: complete schedule / event / calendar / diary

That’s just what I needed, thanks Stef and for taking the time to answer my many questions.

Offline

#599 2011-01-18 16:37:24

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: smd_calendar: complete schedule / event / calendar / diary

I’ve managed to get the calendar working in the same way as the mini calendar and I’ve managed to capture the date from the URL as a variable (using adi_gps). I’m currently having trouble passing this variable into my smd_article_event tag though.

Does anyone have some quick pointers that could help me get this working?

Thanks.

default (Page)

<txp:smd_calendar section="calendar" firstday="1" select="month" cellform="faux_minical" />

faux_minical (Form)

<txp:smd_if_cal flag="SMD_ANY">
<a href="<txp:site_url />?s=details&date={year}-{month}-{day}">{day}</a>
<txp:else />
{day}
</txp:smd_if_cal>

events (Page)

<txp:adi_gps name="date" quiet="1" />

<txp:php>print_r($GLOBALS['variable']);</txp:php>

<txp:smd_article_event form="events" section="calendar"
from="<txp:variable name='date' />" to="<txp:variable name='date' />" />

Offline

#600 2011-01-18 16:46:51

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: smd_calendar: complete schedule / event / calendar / diary

Algaris

Very close! Try using single quotes around each entire tag-in-tag:

<txp:smd_article_event form="events" section="calendar" from='<txp:variable name="date" />' to='<txp:variable name="date" />' />

As an aside, if you’re doing it this way, have you considered sending ?s=details&month={year}-{month}-{day} to the destination page? TXP has a built-in understanding of the (badly-named, imo) month attribute and will try and retrieve the article that matches that date (err, I think…) which might save you having to use adi_gps.

Although then I guess you still have to extract the dates from the URL. Hmmm. The page_url tag seems to return the ‘month’ which may or may mot be the whole string you supplied — you’d have to try it and see. Just an idea.

Last edited by Bloke (2011-01-18 16:48:10)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB