Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#505 2010-04-01 21:59:12

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

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

Arghgh!

What format is the date in your custom field?

It was:

29/03/2010

…and no joy. It’s now:

29-03-2010

and it works. Why didn’t I think to change that… So sorry for using cycles — thanks Stef and Els.

Cheeky extra question — the ‘/’ comes from the lovely date picker courtesy of glz_custom_fields — if I can’t change that, is there a way to ask smd_cal_now to accept ‘/’ instead of ‘-’?


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#506 2010-04-01 22:15:15

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

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

…RTFM Alan… I think I am solving (I think) my ‘Cheeky extra question’ by seeing your use of ‘strftime’ for the format in smd_cal_now. If/when I solve it I’ll drop a note here to close my question and in case it helps others — thanks tons again >^_^<


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#507 2010-04-01 22:24:55

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

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

alanfluff wrote:

Why didn’t I think to change that…

Because it’s counter-intuitive; it’s not your fault at all! You would expect PHP to handle dd/mm/yyyy but in reality it doesn’t due to the complexities of being able to correctly distinguish the US mm/dd/yyyy from dd/mm/yyyy in all cases. Plus I would guess that PHP’s core functionality here may have stemmed from US programmers :-)

This:

<txp:php>
dmp(strtotime('29-03-2010'));
dmp(strtotime('29/03/2010'));
</txp:php>

only renders one string; the first one. The second one is deemed ‘invalid’ by strtotime (at least in my version of PHP) even though there’s blatantly only one way to interpret that string as a date. Internally, smd_cal_now uses strtotime() so we’re stuck with it.

I was hoping to fix this in the next version of the plugin because it’ll be PHP 5+ so I could have offered an additional parameter to allow you to specify what format you expect the dates to be in. I would then use strptime to parse it, before refactoring the numbers into a format that strtotime can understand. But the caveat on the strptime page states:

Note: This function is not implemented on Windows platforms.

So I’d only swap a solution for another problem :-|

is there a way to ask smd_cal_now to accept ‘/’ instead of ‘-’?

Nope, but there are some wonderful plugins out there that can transmogrify strings before smd_cal_now sees them. I think rah_replace would do it so you could swap / for -.

Last edited by Bloke (2010-04-01 22:27:28)


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

#508 2010-04-01 22:29:33

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

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

Yippee! Thank you for your wonderful explanation — like after-burn on sun-burn after the fruitless hours of Google and trial and error I have spent.

I’ll certainly look at rah_replace and if that does not do it, I’m guessing I could ask jQuery to spot when that field looses focus during edit and replace ‘/’ for ‘-’ on-the-fly (before the human clicks ‘Save’ ;) One way or another, sure to solve it.

THANK you.


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#509 2010-04-01 23:08:52

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

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

And, thanks in large part to Els and Stef, here is the code that works, 100% — it is not my completed code (lots of other TITLE etc stuff to add, now the logic is working) and probably maybe some intermediary variables are used that could be missed out, but it WORKS and I am SO happy — so happy I wanted to note it here in case it saves anyone else pain.

Summary

For Articles in a section called Events, I am using a custom field, set by the Author, to reflect the date the event is to happen on. The code is designed to take that date and report that there IS a future event, if the date is today or any day in the future. Here’s the code:

<txp:if_custom_field name="Event date">
	<txp:variable name="kate" value='<txp:custom_field name="Event date" />' />
	<txp:variable name="julie" value='<txp:rah_replace from="/" to="-"><txp:variable name="kate" /></txp:rah_replace>' /><br />
	<txp:variable name="numEvent" value='<txp:smd_cal_now format="%s" now=''<txp:variable name="julie" />'' />' />
	<txp:variable name="numNow" value='<txp:smd_cal_now offset="-1 day" format="%s" />' />
	<txp:smd_if field='<txp:variable name="numEvent" />' operator="gt" value='<txp:variable name="numNow" />'>
		<p>There IS something coming up</p>
	<txp:else />
		<p>There is NOT something coming up</p>
	</txp:smd_if>
</txp:if_custom_field>

The date is entered in via the date-picker as dd/mm/yy, the rah_replace gets it to dd-mm-yy (thanks Stef). The smd_cal_now blows pixie dust on the date to allow me to compare it with smd_if (thanks, twice more Stef). The offset=-1 means that an event with todays date will show up also, since I am going to call the list “Future or current events” this fixes the issue where at midnight, the events for today are ‘older’ that the start of today and so would otherwise not show.

Cheers, -Alan


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#510 2010-04-03 02:12:58

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

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

Stef — I’ve searched and scoured this thread trying to find an answer to this question, but I’m stumped.

Take a look at this page

Do see how several spanned events break because of preceding events? I tried to insert a transparent placeholder ABOVE the broken spanned event, but it seems as though the middle or last day of a spanned event does not respect the actual time, so no matter what, I cannot insert a blank placeholder to push the broken events down to line everything up nicely. Any hints on solving this?


Kevin
(graphicpush)

Offline

#511 2010-04-03 02:58:36

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

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

Awesome and beautiful work, Kevin.
smd_calendar is an amazing thing too.

Tricky thing that issue you want to fix, aligning those spanned events…
Certainly, this doesn’t seem a job for CSS, not for using transparent placeholders. It seems that the only way would be to create/program some kind of time grid (using …errr… tables or maybe alls) inside each daily cell, and render an event on its corresponding row time.
Another path could be to count how many events were rendered on the previous cell, and try to do something with that info, but that would seem hackish.
Also, there is at least one case that it’s not represented in the current May calendar: when you have an spanned event (for example, a 4-days long event) and, for example, on the 3rd or 4th day you have one even earlier than the spanned one.

I hope you or Stef find a clever solution.

In the meanwhile, a visual aid to help the eyes following broken spanned events could be using a few different colors for each event.
The easiest way to achieve this is probably by using a custom field and manually assigning a color to each event. Or maybe you can find a way to do it randomly and programmatically fetching the colors from a limited list of allowed colors. But again, it maybe tricky to make “broken spanned events” to render the same color on each cell…


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#512 2010-04-03 03:07:45

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

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

Awesome and beautiful work, Kevin.

Thank you. It’s a work in progress. These are the types of bugs that are starting to appear.

It seems that the only way would be to create/program some kind of time grid (using …errr… tables or maybe alls) inside each daily cell, and render an event on its corresponding row time. Another path could be to count how many events were rendered on the previous cell, and try to do something with that info, but that would seem hackish

I thought about this, but it’s essentially the same solution. At some point, something has to count something else and react accordingly. I actually think jQuery could do this, but that level of development is miles beyond me. It’s certainly not impossible; Google Calendar and others managed to figure it out at some point. With all that in mind, having transparent placeholders made a lot of sense because it doesn’t really break anything. And it would be perfect, except for the fact that spanned events do not respect other events’ start time within the same day; they seem to be laid in by article ID and that’s that. I’ll continue to plug away at it.

UPDATE: OK, I’ve turned this plugin inside and out, and there does not seem to a way to force this out of the box. Stef, this could be solved one of two ways:

  1. Create a sort attribute for <txp:smd_calendar /> like there is for <txp:smd_article_event /> to explicitly control the ordering of events inside a day’s cell.
  2. Add a time attribute to <txp:smd_if_cal> so I can sniff if my transparent placeholder falls within a specific time so it renders first.

Hope that makes sense.

Last edited by kevinpotts (2010-04-03 03:40:42)


Kevin
(graphicpush)

Offline

#513 2010-04-03 21:57:20

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

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

kevinpotts wrote:

Add a time attribute to <txp:smd_if_cal> so I can sniff if my transparent placeholder falls within a specific time

The next version is better at time handling so you’ll be able to do this.

Create a sort attribute for <txp:smd_calendar /> like there is for <txp:smd_article_event /> to explicitly control the ordering of events inside a day’s cell

You could try modding the plugin a little. I’m not convinced it’ll achieve what you want in this simplistic form, but if you want to try it:

1) In this block at the very top of the plugin:

extract(lAtts(array(
	'time' => 'any',
	'size' => 'large',
	'expired' => '',
...

add a sort attribute to the list, like this:

'sort' => 'Posted asc',

2) Search the plugin for this line (around line 270ish I think):

$sql2 = $stati . " HAVING uPosted <= ".$ts_last . $expired . $extrasql ." ORDER BY Posted ASC";

and change it to this:

$sql2 = $stati . " HAVING uPosted <= ".$ts_last . $expired . $extrasql ." ORDER BY $sort";

That’ll pull out all events in the order you give via the sort attribute, though I don’t know if it’ll help because it might need to be more clever than that to order them on a per-cell basis. You can try and let me know how it goes if you don’t mind.


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

#514 2010-04-04 12:57:05

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

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

Stef —

You are one of the smartest guys I’ve never met. Your quick’n‘dirty patch proved most effective, but not how I expected. First of all, changing those two bits of code enables the sort attribute perfectly as if I were using the <txp:article /> tag or something. HOWEVER, the sorting within a cell still does not completely respect the Posted time. I have no idea why. I changed it to sort="LastMod asc" and it worked perfectly, as expected. Go figure.

With the sorting working but the Posted time still acting all wonky, I had to resort to less elegant tactics. I added a custom field called “sort”. Every “real” event and every “placeholder” event is assigned a number from 01-05, which dictates, obviously, the order in which they appear inside the day’s cell. Then placeholder events are given a category of “placeholder”, which, through the magical and wonderful code of your plugin, results in class of smd_cal_ev_placeholder applied to the spanning element. Then I simply added this bit to the CSS:

#cal td.smd_cal_event span.smd_cal_ev_placeholder a { visibility: hidden; }

visibility: hidden; respects the block element’s width and height, but simply hides it, creating a nice blank area that pushes everything else down.

So in the end, your patch worked perfectly, and my placeholders are correctly pushing “broken” events into place. You can see the nicely aligned events here.

Stef, thank you. I’ve said this before and I am sure I will say it again, but your plugins are so ridiculously powerful and scalable that they are pretty much systems unto themselves. smd_calendar and smd_gallery are amazing to play with.

Last edited by kevinpotts (2010-04-04 12:59:25)


Kevin
(graphicpush)

Offline

#515 2010-04-27 02:19:11

andocobo
New Member
Registered: 2010-04-27
Posts: 2

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

Hi Stef,
Firstly, I’ve used many of your plugins in the past and I appreciate the great work you’ve done for the txp community very much…i don’t know how you find the time to do it all. Secondly, I’ve got an issue with smd_article_event, when i use it i get the following error message:

Tag error: <txp:smd_article_event datefields="datefield" sort="posted desc" time="any" limit="1" form="nextEvent" category="events" /> -> Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag on line 1

I am using the tag thusly in the page template:

<txp:smd_article_event datefields="datefield" sort="posted desc" time="any" limit="1" form="nextEvent" category="events" />

And the form it is calling has the following code: <h5><txp:custom_field name="city" /> - <txp:custom_field name="datefield" /></h5> <p><txp:title /></p> <a href="<txp:permlink />">Learn more about this event &raquo;</a>

I hope you can help me out, this problem is driving me crazy.

Thanks!

Offline

#516 2010-05-04 03:31:20

laptophobo
Member
Registered: 2010-03-01
Posts: 216
Website

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

Hi Bloke,

I just came across your smd_calendar plug-in. I’m sure I’ll be able to use it (nonprofit/charity groups are full of events!) But, unfortunately, I’m not getting the Article tag thing.

On your posting #8 you state the following quite clearly as part of your “Quick Start Demo:

◦Install the plugin [which I’ve done]
◦Make a section called something like events [done]
◦In your page template for that section, add <txp:smd_calendar section=“events” /> [done.]
◦Go and create some articles in the events section, set the dates to whenever you want those events to occur [Huh?]
◦View yoursite.com/events

As you can see, I’ve done the above. The calendar views with a link the Article, along with a copy of that item below the Calendar. However, it lists the event date as today (when I created this article). So, how would I tag it so the event date be the actual event date (e.g.: 10 June 2010).

I’m sure it has to do with the fact that I don’t know how to “set the dates to whenever you want those events to occur”. Could you provide me with an example of tags to use on my Article?

Thanks so much for your great product.

I’m not worthy.

Last edited by laptophobo (2010-05-04 04:07:45)


Living the Location-Independent Life: www.NuNomad.com

Offline

Board footer

Powered by FluxBB