<![CDATA[ Sorting getResources result by TV - My Forums]]> https://forums.modx.com/thread/?thread=43575 <![CDATA[Re: Sorting getResources result by TV]]> https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-553761 https://forums.modx.com/thread/102804/get-resources-sorted-by-last-updated#dis-post-553753]]> BobRay Sep 08, 2017, 02:53 AM https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-553761 <![CDATA[Re: Sorting getResources result by TV]]> https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-553735 I was wondering if there's a way to use getResources sortby option to sort all of the latest updated resources?]]> kingveljko Sep 07, 2017, 12:45 PM https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-553735 <![CDATA[Re: Sorting getResources result by TV]]> https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-553147 dylanwood Aug 11, 2017, 09:09 PM https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-553147 <![CDATA[Re: Sorting getResources result by TV]]> https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-450894 Quote from: opengeek at Jan 11, 2013, 09:11 PM
Quote from: jamesb at Jan 11, 2013, 09:06 PM

opengeek, another question for you - when getting and then outputting a TV that is a delimited list, the delimiter changes to || rather than the comma that I have set in the TV output options. The delimiter displays correctly as a comma on pages that are not a result of using getresources to get and display the TVs. Code hasn't changed from above aside from correcting my link to the resource id.

Thanks for your time.
-Jamie
You need to have the TV's processed. See the &processTVs and &processTVList properties in the documentation.

wonderful. thank you.]]>
jamesb Jan 17, 2013, 11:06 AM https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-450894
<![CDATA[Re: Sorting getResources result by TV]]> https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-450128 Quote from: jamesb at Jan 11, 2013, 09:06 PM

opengeek, another question for you - when getting and then outputting a TV that is a delimited list, the delimiter changes to || rather than the comma that I have set in the TV output options. The delimiter displays correctly as a comma on pages that are not a result of using getresources to get and display the TVs. Code hasn't changed from above aside from correcting my link to the resource id.

Thanks for your time.
-Jamie
You need to have the TV's processed. See the &processTVs and &processTVList properties in the documentation.]]>
opengeek Jan 11, 2013, 03:11 PM https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-450128
<![CDATA[Re: Sorting getResources result by TV]]> https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-450125 Quote from: opengeek at Jan 10, 2013, 07:56 PM
The href to the Resource should be:
[[~[[+id]]]]

opengeek, another question for you - when getting and then outputting a TV that is a delimited list, the delimiter changes to || rather than the comma that I have set in the TV output options. The delimiter displays correctly as a comma on pages that are not a result of using getresources to get and display the TVs. Code hasn't changed from above aside from correcting my link to the resource id.

Thanks for your time.
-Jamie]]>
jamesb Jan 11, 2013, 03:06 PM https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-450125
<![CDATA[Re: Sorting getResources result by TV]]> https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-450007 Quote from: opengeek at Jan 10, 2013, 07:56 PM
The href to the Resource should be:
[[~[[+id]]]]

Ah, thank you! You're my new hero.]]>
jamesb Jan 10, 2013, 03:28 PM https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-450007
<![CDATA[Re: Sorting getResources result by TV]]> https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-450003
[[~[[+id]]]]
]]>
opengeek Jan 10, 2013, 01:56 PM https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=3#dis-post-450003
<![CDATA[Re: Sorting getResources result by TV]]> https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=2#dis-post-449989
I have the following:

directory-thumb chunk:
[[!getResources?&parents=`66` &tvFilters=`topposition==attorney` &limit=`100`&includeTVs=`1`&includeContent=`1` &sortbyTV=`lastname` &sortdirTV=`ASC` &tpl=`directory-tpl`]]


directory-tpl chunk:
  <tr>
    <td bgcolor="#F4F5F7"><a href="[[*parent]]">[[+tv.FirstName]] [[+tv.LastName]]</a></td>
    <td bgcolor="#F4F5F7">[[+tv.Position]]</td>
    <td bgcolor="#F4F5F7">[[+tv.PracticeAreas]]</td>
    <td bgcolor="#F4F5F7">[[+tv.Locations]]</td>
    <td bgcolor="#F4F5F7">[[+tv.Phone]]</td>
    <td bgcolor="#F4F5F7"><a href="mailto:[[+tv.Email]]"><img src="assets/img/email_icon.gif"></a></td>
  </tr>



I am using Revo 2.2.6

Thanks a million.
-Jamie]]>
jamesb Jan 10, 2013, 10:59 AM https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=2#dis-post-449989
<![CDATA[Re: Sorting getResources result by TV]]> https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=2#dis-post-432450
First, why sort on date? Well, because presentations such as calendars and lists of events are naturally date-ordered. I almost gave up on sorting by date TV, since the built-in unpub_date resource field offers semantically ALMOST the same thing: It's usually fine to unpublish a notice once an event is underway. Sorting by a resource field in getResources is straightforward. Sorting by TV involves fiddling with several substitute or additional getResources properties and options. Failure to provide getResources with exactly what it needs / wants results in puzzling output, without error messages or other hints.

So, if you can get by without sorting on a date TV, I recommend you do that.

However, "semantically almost the same" isn't always enough. The date upon which some event is to commence is not quite the same as the date upon which to stop publicizing it. How about events that run across multiple days, for example?

Besides, I had already entered TV dates for over 1000 events logged into a MODX Evolution site over the previous two years. I was in the midst of porting this site over to Revolution, replacing ditto with getResources. This was a technology refresh, so I didn't want to go backward. And most certainly I didn't relish the prospect of cutting & pasting dates from the TV tab into the Settings tab for 1000+ resources!

So I updated getResources to the latest version (1.5.0-pl) on my development version of Revolution (2.2.0-pl2) and carefully followed the document at http://rtfm.modx.com/display/ADDON/getResources. I temporarily deleted the 'tpl' property reference in order to view the getResources dump.

I encountered bizarre results. After many experiments, I learned that a defective getResources call returns the first N resources ascending-ordered by ID number, where N is specified by the getResources 'limit' property. I also noted that a seemingly correct getResources call sorting on my date TV would return an unexpected set of resources, and these not even presented in correct date order! However, the call delivered the same results repeatably, and cache-clearing on host and client made no difference.

What to do?

About to lose hope, I had a breakthrough. By instrumenting the template to which my event date TV was attached, I noticed that the TV date instances were not of uniform format. It was a mixed bag:


  • YYYY-mm-dd HH:MM:SS (24-hour time format)
    Example: 2010-06-04 15:30:23

  • Month-spelled-out day-with-leading-zero-suppressed, YYYY h:m AM||PM
    Example: June 4, 2010 3:30 PM

  • M-with-leading-zero-suppressed/D-with-leading-zero-suppressed/YYYY h:m AM||PM
    Example: 6/4/2010 3:30 PM

  • M-with-leading-zero-suppressed/D-with-leading-zero-suppressed/YY h:m AM||PM
    Example: 6/4/10 3:30 PM

I confirmed this by checking the database using phpMyAdmin.

What a mess! I don't know where all of those format variations came from. I must have caused them by monkeying around with the date TV's Input and Output Options.

Apparently, ditto on Evo had no problem with the format mish mash, but GetResources on Revo doesn't like it. getResources apparently REQUIRES the first of the above four formats, which I suppose is what "&sortbyTVType= `datetime`" is all about. Of course! It's unreasonable to expect sorting to work on arbitrary date formats, and that first format is so easy and efficient to sort.

Meanwhile, the built-in resource fields, such as the 'createdon' date, are also formatted in the first way given above.

A big clue came in jrotering's forum post, http://forums.modx.com/?action=thread&thread=74320. His sole error was getting the capitalization of a getResources property wrong. Once he fixed that, he (rather amusingly) revealed that his call worked properly! Note that he carefully explained how his date TV instances were formatted.

This encouraged me to regularize my date TV instances. It wasn't so bad a chore. Database table 'modx_site_tmplvar_contentvalues' contains all of the date TV instances. I used phpMyAdmin to examine and edit the incorrectly formatted ones.

The date instances having been fixed, I'm happy to report that the following getResources call selects and sorts as desired on date TV:

[[!getResources?
  &parents= `6`
  &depth= `1`
  &showUnpublished= `1`
  &showDeleted= `0`
  &includeContent= `1`
  &tvPrefix= ``
  &includeTVs= `1`
  &processTVs= `1`
  &processTVList= `eventDate`
  &sortbyTVType= `datetime`
  &sortbyTV= `eventDate`
  &sortdirTV= `DESC`
  &limit= `5`
  &tpl= `homeMainEventsTpl`
]]

So, if you're having trouble using getResources with a date TV, work your way through this checklist:



  • Remove the 'tpl' property in order to enable the properties & options dump.

  • Ensure that you're using the back-tilted single quotes in the snippet call. I Don't mean to insult anyone's intelligence. Failing to do that is a frequent error of mine.

  • Ensure that spellings and capitalizations of property names are correct.

  • Ensure the same for template variables.

  • Using phpMyAdmin, check TV dates in the database and ensure all are of the form discussed above.

  • To avoid future format problems, ensure that the Input Options for the date TV upon which you intend to sort is specified as

    'Input Type: Date'
    'Allow Blank: No'

    and the Output Options as

    'Output Type: Date'
    'Date Format: %Y-%m-%d %H:%M:%S'

Next problem: Restricting resources to dates in the past or in the future. There is no point showing past events to users hoping to plan ahead. Likewise, there is no point in showing future events to users whose interest is historical.

A gentleman writing under the agreeably musical name debussy suggests (http://forums.modx.com/thread/43727/getresources-to-show-current-and-future-events#dis-post-419669) using a custom snippet, which I have named "currentDatetime."
<?php
return date('Y-m-d H:i:s');
?>

Use this snippet as part of yet another getResources property, "&tvFilters." This version of the property restricts getResources to reporting on the future:
  &tvFilters= `eventDate>>[[!currentDatetime]]`

and this version restricts getResources to reporting on the past:
  &tvFilters= `eventDate<<[[!currentDatetime]]`

=====================

I hope that the MODX folks add date-TV selection, sorting and filtering to http://rtfm.modx.com/display/ADDON/getResources.Examples, and that Bob Ray covers it in the next edition of his excellent book.]]>
halfnium Aug 06, 2012, 11:31 PM https://forums.modx.com/thread/43575/sorting-getresources-result-by-tv?page=2#dis-post-432450