As for the date problem you mentioned -I agree with you that using the advanced setting dropdown each time for setting a start date can be a chore.

So let us now make it easier

The plan is that we define an editable region (with the datepicker if required) for the start_date too. However, while saving the page, we insert this editable region's value into the page's publish_date automatically. This way we get the best of both the worlds - the client can set the date into a normal editable region and we can use the (much more efficient) publish date while listing the events.

This is how we do it -Please copy and paste the following PHP code in your site's (or the one found in 'couch/addons' folder) kfunctions.php.

Notice how we are associating the PHP code we pasted into kfunctions.php as step one with this editable region via its 'validator' parameter. So each time a page containing this editable region is saved, the validator code kicks in. It validates the date's format and more importantly also pushes this date into the page's system field that holds the publish_date (this is the one we access using the 'Advanced setting' dropdown).

This saves the client from having to go into the advanced setting.

Hope this helps.Do let us know.

Thanks.

EDIT:Instead of using a type 'text' editable region, as we did above, we can use a type 'datetime' editable region instead -

Great! Thank you both for the solutions. I had not run across the kfunctions file yet. I will make use of that in the future for sure! I have never really use moo tools before, and was not aware there was a conflict between the two.

Coming from years of working with Wordpress, Couch is a breath of fresh air for small sites! Yet I can't believe how powerful it is.

I'm interested in using this and indeed extending it. I was planning to post seeking to check my understanding, but as I went on I got more confused about what some of the code is doing!

I'd like to give the site manager two options for event date/time.1. A datetime field "start_date"(for occasional events)

If the datetime field is completed, then I'd like to set the publish date/time to that value.

2. A text field "regular_start" which can contain a string like 'First Thursday of the month' (for regular events)

If the date/time is not completed, then I'd like to set the publish date/time to that day of the month in August 2010

(Since that month started on a Sunday, this will mean that dates in the format 'First Wednesday', Second Thursday' etc will be in the natural order through the month)

PHP's strtotime function can handle "First Thursday of August 2010' and output a valid PHP date

This means that the site manager can enter all events using the same form, and I can output lists of regular events and occasional events, with each list logically ordered.

Given that I've got either (1) a valid datetime from a Couch editable field, or (2) a valid PHP date, can anyone help me with the code I need to get that value into the publish date field? (Part of the original code is checking for validity of a date in a text field).

Replying to my own post; I've done some work on this, and I have what seems to be working code - but also a question.

My events form has two fields for the date - a text field for the 'regular monthly' sort , which will contain something like 'Second Saturday', and a datetime field for events with actual start dates. This code will work with either - but if I attach this as a validator to both fields,

it will raise an error if the 'regular monthly' field is blank,

and (assuming it works through the fields in order) it will override any 'regular monthly' field with the default datetime content anyway

.

I can deal with the first issue by explicitly ignoring blanks, but I can't see how to deal with the second one - to validate the second field only if the first is blank. That issue wouldn't be resolved by separate validators either.

class MyEvent{ //Function to take a date and push it into the published date field of an entry //Accepts a standard date from a date picker, or a phrasing such as 'First Sunday' for monthly recurring events function start_date( $field ){ global $FUNCS;

// Get the contents of the field and clean it up a bit $start_date = trim($field->get_data());

// If it doesn't start with two digits, it's not come from a date picker, so try treating it as a regular monthly event // That is, append ' August 2010' so that strtotime will order such dates in a logical way, using a Sunday-start week, because 1 Aug 2010 was a Sunday. if ((strlen($start_date)>0) && (!is_numeric(substr($start_date, 0, 2)))){ $start_date .= " August 2010"; }

I understood the first problem from your first post: copy datetime editable to the 'publish_date'.Can I please ask something about the second problem?

daldred wrote: 2. ... 'First Thursday of the month' (for regular events)If the date/time is not completed, then I'd like to set the publish date/time to that day of the month in August 2010

A side note: regular (or recurrent) events are not yet covered by core tags, but still we can use regular cms:pages tag to find such events and embed them into calendar view (although it requires deeper knowledge how "cms:calendar, cms:week, cms:days, cms:entries" tags work).

So what I don't yet understand is if client puts "first monday of the month" (which is more advanced than just "on mondays" - how this event becomes recurrent in your plan? Suppose, you achieve what you do in php and this 'text representation' gets converted to one real date and gets pushed to 'publish_date' of the page. Then what?

I'm deeply interested in this conversation, because another friend asked me to code this "recurrent events" thing and I planned to handle it exclusively on the front-end (as in the side note above). Maybe we could move this topic to a separate thread?

I'm not actually planning to use the calendar as such with this - or at least I wasn't!

A little background: I'm making a website for the regional presence of an organisation which is organised on a local basis. Each local group will have a couple of regular meetings per month, and in addition other events are organised, either at group or regional level, which can be thought of as 'special' events. All the fields for both sorts of events are the same, with the exception of how dates are handled.

So I'm approaching this by having separate listings - one for the regular ones, and one for the special ones - and for this group that's quite a natural way of thinking of them. Each listing should being in a logical order, but they aren't shown in the same list. The fact that the supposed actual dates for the regular events listing is in 2010 doesn't matter, as long as they are in a good order - I don't expose the 'published date' anywhere, just sort by it.

It would be absolutely ideal if there was a way of handling regular events so that they organise themselves into the calendar. Though, thinking about it, if you were only showing a month of calendar at a time, PHP's relative date formats could do quite a bit of the heavy lifting; once you'd put in the actual dated events, you'd then iterate through the regular ones converting each to a date this month, and inserting the result into the calendar.

daldred wrote: I'm not actually planning to use the calendar as such with this - or at least I wasn't! ...Though, thinking about it, if you were only showing a month of calendar at a time, PHP's relative date formats could do quite a bit of the heavy lifting; once you'd put in the actual dated events, you'd then iterate through the regular ones converting each to a date this month, and inserting the result into the calendar.

What I meant about calendar system was well described in docs - http://docs.couchcms.com/concepts/events-calendar.htmlThat Concept is based exclusively on 'publish_date'. However, in the view of modern CouchCMS 2.0+ you may configure admin's list-vew as far as you'd like, including showing (and ordering by) your custom date editable in the column of publish_date. Also publish_date itself may be just placed anywhere in the form-view. This particular example was mentioned in "CouchCMS v2.0" topic. viewtopic.php?f=5&t=10241#p24680

Now, looping through all regular events and make the date converted into this month's date looks as an interesting approach.Did you happen to look at this topic with relative dates? A lot of cases in CouchCMS are perfectly covered and do not require php code at all. viewtopic.php?f=8&t=10559#p28383What I mean is that if you focus on front-end and try to use regular editables and make the heavy-lifting with core tags, it may suffice, don't you think?

Events that occur more than twice a month or week might need special attention, but hopefully nothing that could require raw php. Splitting a comma-separated string 'first monday this month, second tuesday this month' is a breeze with "cms:each sep=',' " and maybe even have repeatable regions to introduce several appearances of event as rows instead of comma-separated string...

P.S. In same Couch2 topic you may even borrow the example of setting publish_date and instead save to it your editable with date (which may also be dynamic if needed). The current thread we are in is from 2013, so it is outdated and meant for older V1.4.7 which did not support extensive customization features of modern CouchCMS..