Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2021-05-12 14:45:08

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

Yep %A works fine.
Sorry, wasn´t checking right. Got the wrong function

Thanks again for your help and thinking this through with me.
The ticket link will be a third party link from the ticketing service, yes.
Apart from that there will be “Venue” and “Additonal info” (e.g. Premier etc.) associated with each date.
I will read your post more carefully and also check back with the responsible people on how this data can or needs to be handled (Premier could be set autmatically for example – but venue, if really needed on a per date basis cannot). Also the unique ticket link only makes sense if the third party service offers a straight way to book exactly the date and time and no decision is addiotnaly to be made on the third party side.

Offline

#14 2021-05-13 07:54:28

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

Sleeping over it gave me another idea on how to handle that.

Maybe it is easier to have an article that represents all the major data of an event that is not date-critical. And then additionally you have articles that are connected with that main article that represent the different dates with their different ticket links etc. The multi-lingual setup makes it a bit harder here but sounds to me like a considerable alternative if everything else fails.

I prefer to try your idea of assigning additional code with a delimiter to the dates first.

2021-05-14 18:00 {ab16da0f472b},
2021-06-03 12:00 {8419de8a55},
2021-06-22 12:00 {9b064721aa7}

If you’re going to do that I’d recommend wrapping it in a delimiter so it’s easy to filter out before you pass the date list to smd_calendar.

When and where would that be filtered out best? And where would it be stored? Because when passing it to smd_calender I can only pass it by giving the custom-field´s name and not a set of dates. Which would make it easier. Maybe tweaking smd_calender to my needs would be better in the long run?

If not, would you kind of duplicate this into another custom-field and clearing off the {additional stuff} and then give this extra clean custom-field to smd_calendar? The original custom-field then still holds the dates+additional info and I would need to find a way to display each line when the <txp:posted/> matches the line. Does this make sense?

Offline

#15 2021-05-13 09:17:16

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

Re: Sort articles based on multiple dates defined in one custom_field

demoncleaner wrote #330131:

Maybe it is easier to have an article that represents all the major data of an event that is not date-critical. And then additionally you have articles that are connected with that main article that represent the different dates with their different ticket links etc.

Yep. It all depends on the workflow and how comfortable people are with using the back end of Textpattern. If someone has all the event info available to them when they set up the article event, you can either elect to:

  1. Have them type/paste it all into dedicated fields in one article (which kind of makes sense to encapsulate it all – and may be simpler to maintain and to teach someone new to do it).
  2. Put the info in two linked articles and show them how to link them.
  3. Write a little companion dashboard plugin.
  4. Add a button that allows them to fetch the data from a remote source (if it has an API).
  5. Something else…

When and where would that be filtered out best? And where would it be stored?

If you store it in your extrafield custom field you would need to filter it out every time you pass it to one of the plugin’s tags.

Thinking about it further, if you don’t mind having a tag in your data, it makes it a cinch to strip out the ‘info’ tag when you want to pass it to smd_calendar’s tags…

2021-05-20 19:00 <info link="https://example.org/whatever/72321902192" premier venue="Golden Globe" />,
2021-06-18 <info link="https://example.org/whatever?date=20210618" venue="Super Theatre" />,
2021-07-15 19:00 <info link="https://example.org/whatever/92poiw9ee" venue="Golden Globe" />
<txp:custom_field name="dates" escape="info" />

Done.

To go the other way around and get just the HTML tags left behind you could use a regex to ‘trim’ the date portion. The regex is a bit scary because there are various optional components but it’s not hard to tweak for your setup. This one is based on the YYYY-MM-DD HH:MM:SS format:

<txp:custom_field name="dates" trim="/(\d\d\d\d\-\d\d\-\d\d\s?)*(\d\d\:\d\d)*?(\:\d\d)*?/" />

(there’s probably a neater regex than that, and it might not work in all cases as I’ve not tested it thoroughly). In this case you don’t need the replace="" because trim removes the content by default.

If you don’t like having XML-style tags in your storage and wanted to use the {} system instead then you could use a regex to strip those out instead of escape="info" in the first example.

Another option (although you might not need it) is to register a PHP function in Advanced Prefs for use with <txp:evaluate>. That gives you the power of any PHP tag there (and maybe even in the evaluate attribute – not tried it) and you can also alias them to simplify things.

Lots of stuff you can do to manipulate content in Txp these days :)


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

#16 2021-05-13 09:20:16

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

Re: Sort articles based on multiple dates defined in one custom_field

Oh, one other thing. smd_calendar does not (at present) factor in times in the extrafield. Only dates. At the moment it assumes that any date you specify has the same time as the article’s posted date and will ignore any time you add to the datestamp in your custom field.

This is a deficiency in the system that I’ll try and fix. If I get a chance today I’ll look at it but I have a file due at the printers for a book, so I need to get that done first.


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

#17 2021-05-13 09:58:35

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

Meanwhile I tried having the additional info that I need in an extra custom-field leading the info with the date it is ment for. This is not ideal because people will have to put in the date twice (or more) but it is the best solution I can think of at the moment.

It might be best to have one custom_field for each type of additional info so that it will not get too complicated in splitting and not too messy for the admin.

So for the “ticketlink” customfield it could look like:

2021-05-14#https://www.ticketseller.com/12345
2021-05-16#https://www.ticketseller.com/67890

Then I change the linebreak to a comma separated list with this:

<txp:variable name="additional_info">
		<txp:pax_grep delimiter="|" from="/<\/?p>/|/\t/|/<br\s*\/?>/" to=","><txp:custom_field name="ticketlink" escape="textile"/></txp:pax_grep>
	</txp:variable>

I am using then rah_repeat to do all the splitting and a trim regex at the end to “hide” the date and the #. Pretty ugly but it works. I am wondering if there is a cleaner/cleverer way? Any simplifying is welcome!

<txp:rah_repeat value='<txp:variable name="additional_info"/>'>		
			<txp:rah_repeat value='<txp:rah_repeat_value/>'>
				<txp:variable name="test" value='<txp:rah_repeat_value/>'/>
				<txp:if_variable name="test" value='<txp:posted format="%Y-%m-%d"/>' match="any">					
							<txp:variable name="output" trim='/\d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])*[#]/' replace="" output><txp:rah_repeat_value/></txp:variable>					
				</txp:if_variable>
			</txp:rah_repeat>				
		</txp:rah_repeat>

Then I´ll put all that into an output form called “eventinfo”.
Of course the appearance of custom_field has to be replaced with a yield.
I will then be able to create an individual ticketlink that reacts on the given date like this:

<a href='<txp::eventinfo customfield="ticketlink"/>'>Book now!</a>

One additional question:
I am wondering if performance-wise it would make a difference if I check at the beginning in my output-form if the variable additional_info has a value at all. Or if it makes sense to check up front if in the custom-field the current date is matched at all like:

<txp:if_custom_field name='<txp:yield name="ticketlink"/>' value='<txp:posted format="%Y-%m-%d"/>' match="any">

Last edited by demoncleaner (2021-05-13 11:57:21)

Offline

#18 2021-05-13 10:16:12

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

I think we are getting closer to an acceptable solution.
I did not see your previous post when I posted my last setup.
The only thing I do not understand with your last example is: How would I feed smd_calender with <txp:custom_field name="dates" escape="info" />

It only allows me to feed it like <txp:smd_article_event extrafield='custom_3'> right ?

So only the custom-field name can be set and no way to escape things there. Am I missing something again? That was the reason why I chose extra fields with the repetition of the date followed by the info/link needed.

Last edited by demoncleaner (2021-05-13 10:17:40)

Offline

#19 2021-05-13 10:24:26

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

Re: Sort articles based on multiple dates defined in one custom_field

demoncleaner wrote #330136:

It only allows me to feed it like <txp:smd_article_event extrafield='custom_3'> right ?

Drat, you’re right. I’ll need to allow you to pass in custom content somehow so you can filter it. Leave that with me.


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

#20 2021-05-13 10:59:51

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Sort articles based on multiple dates defined in one custom_field

I would suggest that you ask your clients to structure the data a bit better. For example, some events custom field could contain it in ini format:

[Day 05]
title=Title of event A
link=https://www.ticketseller.com/67890
[Day 08]
title=Title of event A
link=https://www.ticketseller.com/67890
...

This is not too much effort and is more robust. Then you could use etc_query to construct and reorder your output. Let me know if interested.

Offline

#21 2021-05-13 11:50:50

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

That looks interesting. If with this I can allow a more user and reader friendly input of the data I am more than happy. The client does not have an exact idea of how the input should be. So the more structured and logical it can be and at the same time easily feed smd_calendar the better.
Would it be too much asked if you could give an example on how exactly you would output the date (YYYY-mm-dd) on one hand and the title, link, whatever on the other? And maybe even keep the relation to the given date?

In my example earlier I just output the whole thing and hide the date to get the info needed. How would that work here?

Offline

#22 2021-05-13 12:07:17

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

Re: Sort articles based on multiple dates defined in one custom_field

The ini format is a great idea IF it can handle multiple events per day. The proposed structure by etc wouldn’t allow that unless ini sections with the same name are structured as arrays, which is extra burden on the inputter:

[2021-06-18]
event[1][time] = "18:00"
event[1][title] = "Title of event A"
event[1][link] = "https://example.com/67890"
event[2][time] = "12:00"
event[2][title] = "Title of matinee"
event[2][link] = "https://example.com/12354"
[2021-06-20]
event[1][time] = "14:00"
event[1][title] = "Some title"
event[1][link] = "https://example.com/abcdef"
...

Not even sure that works. Untested.

Keying off the date and time is possible but still has the same problem if two events are in different areas at the same time (e.g. a cinema multiplex with 10 screens).


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

#23 2021-05-13 12:42:21

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Sort articles based on multiple dates defined in one custom_field

demoncleaner wrote #330139:

Would it be too much asked if you could give an example on how exactly you would output the date (YYYY-mm-dd) on one hand and the title, link, whatever on the other? And maybe even keep the relation to the given date?

In my example earlier I just output the whole thing and hide the date to get the info needed. How would that work here?

Sorry, I have not followed the entire thread and don’t know how smd_calendar works. The point is: the more the data is structured, the easier is the extraction. With etc_query it could be (you can try sorry, I must release the ini-version first)

<!-- data would come from a cf here -->
<txp:etc_query markup="ini" data="[Day 05]
title=Title of event A
link=https://www.ticketseller.com/67890
[Day 08]
title=Title of event A
link=https://www.ticketseller.com/67890">
    <h4>{#}</h4><!-- date -->
    <a href="{link?}">{title?}</a>
</txp:etc_query>
Bloke wrote #330140:

The ini format is a great idea IF it can handle multiple events per day.

It can not, the latest event takes it all. But I thought from the OP that events were unique per day? Otherwise you’d need more complex [sections] or switch to XML (but this would be too much to ask).

Another point to keep in mind is that it is possible to reorder HTML output (provided you get it somehow) with XSLT.

Offline

#24 2021-05-13 12:50:10

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Sort articles based on multiple dates defined in one custom_field

Sorry, I did not want to overcomplicate things at the beginning and was struggeling to find a good title for this thread anyway. In my specific case I would need to handle multiple events at a day, yes. But this still looks very interesting.

Offline

Board footer

Powered by FluxBB