Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#733 2011-07-05 13:56:21

BKawalec
Member
From: Poland
Registered: 2011-04-11
Posts: 23
Website

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

Hi,
is there any way of preventing users from adding overlapping events? For example showing only the one that was created first? I’m adding the calendar to a website where members of a club can reserve a shooting range and two people shouldn’t have reservations for the same time.
Any ideas? Or is it impossible?

Offline

#734 2011-07-05 14:19:17

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,740
Website GitHub

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

BKawalec wrote:

is it impossible?

Hehe, impossible is not in my vocabulary ;-)

is there any way of preventing users from adding overlapping events?

Since events are articles, and articles can be set to any date then no, not on the input side of things. The only way you could do that is to go through the rigmarole of setting up a public-side event manager so you could control the permissible dates.

showing only the one that was created first?

If you only want to display the first one on the calendar — even if more than one event exists for any given day — then that’s simpler.

By default, the large cal will show them all, but using some conditional magic you can keep a record of which days you have seen so far and skip the entry if there’s already one displayed. Like this:

<txp:smd_calendar blah blah options>

   <txp:hide> Is there a variable named "has_{day_of_month}"? </txp:hide>
   <txp:if_variable name='has_<txp:smd_cal_info type="day" />' value="1">
      <txp:hide> If so, do nothing because we've already output an event </txp:hide>
   <txp:else />
      <txp:permlink><txp:title /></txp:permlink>
   </txp:if_variable>

   <txp:hide> Now set the has_{day_of_month} variable to say we've got one </txp:hide>
   <txp:variable name='has_<txp:smd_cal_info type="day" />' value="1" />

</txp:smd_calendar>

Job done?


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

#735 2011-07-08 07:10:19

BKawalec
Member
From: Poland
Registered: 2011-04-11
Posts: 23
Website

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

Thanks for the answer.

Unfortunately the problem is more complicated. There can be an unlimited amount of reservations for each day. What the client wants is this:
If for example someone makes a reservation from 10.00am to 11.00am and then later another person makes a reservation from 10.30am to 12.00am then only the reservation that was made earlier (has a lower Id) should be shown. The two reservations overlap between 10.00 and 10.30. If the second reservation started half an hour later then it would be valid and it would show in the calendar.

Offline

#736 2011-07-08 13:33:20

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,740
Website GitHub

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

BKawalec wrote:

the problem is more complicated

Then the solution has to step up a gear too :-)

It appears that all you are interested in, when you ecounter an event, are two factors:

  1. Is there another event on today?
  2. If so, is the start time of this event greater than the expiry of the last event?

If the answer to both those questions is yes then your event is clear to show up. You will need the smd_if plugin to do this successfully because it can handle comparing the event start and end times. I don’t think <txp:smd_if_cal> has the granularity required.

Something like this scary-looking piece of logic should help:

<txp:smd_calendar options...>

   <txp:hide> Is there an event on this day already? </txp:hide>
   <txp:if_variable name='has_<txp:smd_cal_info type="day" />' value="1">

      <txp:hide> Is the posted date of the current event greater than the expiry of the last event on this day? </txp:hide>
      <txp:smd_if
            field='<txp:posted format="%s" />'
            operator="ge"
            value='<txp:variable name=''last_<txp:smd_cal_info type="day" />'' />'>
         <txp:permlink><txp:title /></txp:permlink>
      </txp:smd_if>

   <txp:else />
      <txp:permlink><txp:title /></txp:permlink>
   </txp:if_variable>

   <txp:hide> Indicate that this day has an event on it </txp:hide>
   <txp:variable name='has_<txp:smd_cal_info type="day" />' value="1" />

   <txp:hide> Make a note of the expiry time of this event </txp:hide>
   <txp:variable name='last_<txp:smd_cal_info type="day" />'><txp:expires format="%s" /></txp:variable>

</txp:smd_calendar>

The format="%s" is a trick to convert the timestamp into a UNIX epoch time value so the two numbers can be directly compared inside smd_if. If you’re on a Windoze server that conversion may or may not work.

How’s that?


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

#737 2011-07-10 18:05:19

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 220
Website

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

I’m using this calendar plugin with cellform=“cellform” and would like to show max. one link to event per day. I found that there’s a function eventlimit=“1” but this doesn’t do the trick. Is there any solution to limit the amount of links to events per cell?

Offline

#738 2011-07-11 08:13:02

BKawalec
Member
From: Poland
Registered: 2011-04-11
Posts: 23
Website

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

Thanks a lot. Indeed, it doesn’t work on XAMPP on Windows but it works on a Linux server.

Bloke wrote:

  1. Is there another event on today?
  2. If so, is the start time of this event greater than the expiry of the last event?

The logic above works for most cases, except for one: when someone adds two events overlapping another, like this:
event 1: 9.00-12.00
event 2: 10.00-11.00
event 3: 11.30-13.00

Event 2 won’t show because it overlaps event 1. Event 3 will show because it doesn’t overlap event 2 but it shouldn’t show because it overlaps event1 (the date of an event is compared only with the date of the one before it, isnt it?).

And then there is a problem with the order in which they were really posted (Ids). Event 2 won’t show because it overlaps event 1, but it may have been added earlier (have a lower Id) so it shouldn’t be cancelled by someone later adding an earlier overlapping event (event 1).

So now it’s even more complicated :)

Offline

#739 2011-07-11 08:39:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,740
Website GitHub

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

BKawalec wrote:

the date of an event is compared only with the date of the one before it, isnt it?

Correct. That makes it more tricky because you need to track the ‘highest’ end date. I guess something like this might work, replacing the last segment of the smd_calendar tag with:

...
   <txp:hide> Make a note of the highest expiry time </txp:hide>
   <txp:smd_if field='<txp:expires format="%s" />' operator="gt" value='last_<txp:smd_cal_info type="day" />'>
      <txp:variable name='last_<txp:smd_cal_info type="day" />'><txp:expires format="%s" /></txp:variable>
   </txp:smd_if>

Not sure if that’ll fix it.

And then there is a problem with the order in which they were really posted (Ids).

Hmmm, this is probably a show stopper with this approach. The smd_calendar tag pulls the events out of the database in ascending Posted date order and you can’t change it. Even if you could, I doubt it would help.

The best I can suggest is to ditch the smd_calendar tag and use smd_article_event with sort="ID, Posted asc" to get your event list in the order you want. Then inside the article_event container, make up your own calendarish looking output. It’s not easy (in fact, I wouldn’t know where to start!) but if this is your goal then I think it might be the only way.

I suppose longer term I could look at another attribute to smd_calendar which specifies the actual event (IDs) you want to see on the calendar. That would mean you could sort of do this fictional idea:

<txp:smd_calendar options here
     event_list ='<txp:smd_article_event
            from="start of current month calculation"
            to="end of current month calculation"
            break=",">
        <txp:article_id />
     </txp:smd_article_event>'>
   // your event display, as normal
</txp:smd_calendar>

Not sure if that kind of thing is possible, nor if it’ll fix the problem but it might be a way out. Can’t think of anything else, sorry.


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

#740 2011-07-11 11:45:51

BKawalec
Member
From: Poland
Registered: 2011-04-11
Posts: 23
Website

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

Thanks a lot for all your help.

I think I will leave the calendar as it is. I will show article ids in lists of events for each day so if users see two conflicting reservations they will know which was made first and is therefore valid. The site administrator will sort out overlapping reservations manually. It would have been a much bigger problem for the client if they didn’t know in what order reservations were made.

Offline

#741 2011-08-01 21:02:54

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

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

Hi Stef.

I am working a new site, very similar to this link

I have found a strange issue. I created an event, for example 4th of August of 2011. And on the front end, the event is assigned to 4th of July?
I have checked my date settings on my mac, date formatting in my mamp, everything. Cant seem to find anything wrong.

Am I missing something.

Thanx

EDIT
===

I added the select button, I noticed December was the first month. So I added this
monthformat="{January,Feburary,March,April,May,June,July,August,September,October,November,December}"

Last edited by Dimitri (2011-08-01 21:15:40)


<txp:way_too_cool />

Offline

#742 2011-08-13 13:15:59

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

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

Txp prefs: GMT +10:00
URL in the address bar: /events/?d=30&m=10&y=2011
Code: <txp:smd_cal_now now="?day ?month ?year" format="%A %e %B %Y" gmt="1" />
Result shown on page: Saturday 29 October 2011

the local time when getting this error: 22:30pm … and tried with GMT attribute set to 0 or 1 … same result

any clues?

—-

question 2: for a fixed series of events, want to handcode calendar with links containing URL variable and date … and the page to display only events that fall on that date (both single day events and events with a start on/before the date and a finish in the future … I’m having issues using the smd_article_event tag with ‘from’ and ‘to’ attributes … as above, the days are one day out

thanks

Offline

#743 2011-08-29 18:19:08

pafruu
Member
From: New Brunswick, Canada
Registered: 2010-01-14
Posts: 65

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

alanfluff wrote:


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.

When you say date-picker, are you talking about the lower right side of the article entry screen or the custom field called Event Date?

Because I tried your code and it does not work for me.
Please help

here is what I have for code:

<div id="boxes">
<div id="oneText"><h3><txp:smd_cal_now now="?day ?month" format="%A %e %B" lang="fr" /></h3><br><txp:smd_article_event form="eventsfr" section="calendrier" time="today" limit="2" category="event" allspanned="1" stepfield="custom_1"  />
</div>
</div>
<div id="boxes"><txp:smd_article_event form="Gamesfr" section="calendrier" time="today,future" limit="4" category="event" allspanned="1" stepfield="custom_1" />
<a href="<txp:site_url />calendrier"><img src="<txp:site_url />images/voircalendrier_22.jpg"></a></div>
</div>

I have 2 issues with this:

1: I need todays date to show up in french, which it doesn’t, and I can’t see why.
2: I need to show a message saying that there are no events for today, when no events are scheduled.

I know that I need a <txp:if…> for that but what you did doesnt seem to work for me

Last edited by pafruu (2011-08-29 18:38:41)


I try, and I try, and I try…. and sometimes I achieve

Offline

#744 2011-08-30 17:51:19

pafruu
Member
From: New Brunswick, Canada
Registered: 2010-01-14
Posts: 65

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

ok I solved the french for <Txp:smd_cal_now /> By doing this:

<h3><txp:smd_cal_now now="?day ?month" format="<txp:php> setlocale(LC_ALL, "fr_FR");$header = strftime("%A %e %B"); $header = htmlentities($header); echo ($header);</txp:php>" lang="fr_FR" /></h3>

all I need to figure out now is the displaying of a no-events message when no-event are planned during the present day.
Any suggestions? Ideas?


I try, and I try, and I try…. and sometimes I achieve

Offline

Board footer

Powered by FluxBB