Topic: Latest doc from multiple subfolders without using a date field  (Read 2353 times)

Pages: [1]   Go Down

#1: 24-Feb-2008, 11:21 PM

Testers

ZAP
Posts: 1,619

I'm having a hard time getting just the latest document from a series of folders... The documents are news articles, and they're organized in subfolders by year. Unfortunately, instead of creating them from oldest to newest, we started with the new ones and worked back, so we can't use createdon usefully (note to self: from now on always add dated material beginning with the oldest!).

The folders are like so:
  • 2008 (68)
  • 2007 (67)
  • 2006 (65)
  • 2005 (64)
  • 2004 (63)
  • 2003 (62)
  • ...and on back to 1998, but that doesn't much matter
and each article within these subfolders has an alias based on its date (e.g., "10-03" or "02-12").

So I thought I could just grab all of the docs in each of these folders and sort them first by parent id and then by alias, and that would always give me the latest article (matching a tag, etc.). But it's not working as I expect. I'm getting documents from the oldest folders first.

This is my Ditto call:
Code:
[[Ditto? &parents=`68,67,65,64,63,62` &summarize=`1` &total=`1` &tpl=`newsblurb` &paginate=`0` &alwaysshow=`1` &sortBy=`parent,alias` &sortDir=`DESC` &displayArchive=`0` &depth=`1` &trunc=`0` &tagDelimiter=`,` &tagData=`tvtags` &tagMode=`onlyTags` &tags=`[*menutitle*]`]]

Anyone understand why this is happening (and even better how to resolve it or get the results that I need using some other method)? I guess I could go back through them all and add  published dates and sort by those, but I'd really rather not have to do that. There's gotta be a way to make this work!
"Things are not what they appear to be; nor are they otherwise." - Buddha

"Well, gee, Buddha - that wasn't very helpful..." - ZAP

Useful MODx links: documentation | wiki  | forum guidelines  | bugs & requests  | info you should include with your post | commercial support options

#2: 24-Feb-2008, 11:45 PM

Moderator
Mark
Posts: 3,250

Ditto Developer

WWW
In Ditto 2.1, you need to use the &orderBy field to sort by mutliple parameters. So, you should remove &sortBy and &sortDir and use &orderBy=`parent DESC,alias DESC`. Then it should sort first by parent id and then by alias.
« Last Edit: 25-Feb-2008, 02:51 AM by Mark »

#3: 25-Feb-2008, 02:45 AM

Testers

ganeshXL
Posts: 2,015

true is true

WWW
Maybe you could also use this query http://modxcms.com/lastUpdate-1558.html and add a WHERE clause (WHERE parent=n1 OR n2 OR n3).

Installing the latest Ditto version is certainly a better idea though Smiley

#4: 25-Feb-2008, 10:27 AM

Testers

ZAP
Posts: 1,619

In Ditto 2.1, you need to use the &orderBy field to sort by mutliple parameters. So, you should remove &sortBy and &sortDir and use &orderBy=`parent DESC,alias DESC`. Then it should sort first by parent id and then by alias.
Sweet! I was just using the old parameters (even though I have the latest Ditto). Thanks as always for the quick help!
"Things are not what they appear to be; nor are they otherwise." - Buddha

"Well, gee, Buddha - that wasn't very helpful..." - ZAP

Useful MODx links: documentation | wiki  | forum guidelines  | bugs & requests  | info you should include with your post | commercial support options

#5: 27-Feb-2008, 08:42 PM

Testers

ZAP
Posts: 1,619

Rats! It's still not working for me. I have Ditto 2.1 (latest from the repositories), and my call is the following:
Code:
[[Ditto? &parents=`68,67,65,64,63` &summarize=`2` &total=`2` &tpl=`newsheadline` &paginate=`0` &alwaysshow=`1` &orderBy=`parent DESC,alias DESC` &displayArchive=`0` &depth=`1` &trunc=`0` &tagDelimiter=`,` &tagData=`tvtags` &tagMode=`onlyTags` &tags=`[*menutitle*]`]]
What's odd is I'm getting exactly the opposite of what I'd expect: The oldest articles instead of the latest (it does seem to be ordering by both parent and alias, but not the way I want it to). I tried changing DESC to ASC to see if that helped, but it didn't make any difference. Could there be a bug in the way that the sort order is parsed out of the orderBy parameter?
"Things are not what they appear to be; nor are they otherwise." - Buddha

"Well, gee, Buddha - that wasn't very helpful..." - ZAP

Useful MODx links: documentation | wiki  | forum guidelines  | bugs & requests  | info you should include with your post | commercial support options

#6: 27-Feb-2008, 10:40 PM

Moderator
Mark
Posts: 3,250

Ditto Developer

WWW
Could you please provide the Ditto debug data?

#7: 27-Feb-2008, 10:57 PM

Testers

ZAP
Posts: 1,619

How do I get the debug console to work? I set debug to 1 and I get Open Debug Console and Save Debug Console links where my Ditto call is, but the open link just shows the same page in a pop-up and I can't figure out where the save link saves anything. What am I missing?
"Things are not what they appear to be; nor are they otherwise." - Buddha

"Well, gee, Buddha - that wasn't very helpful..." - ZAP

Useful MODx links: documentation | wiki  | forum guidelines  | bugs & requests  | info you should include with your post | commercial support options

#8: 28-Feb-2008, 09:36 PM

Moderator
Mark
Posts: 3,250

Ditto Developer

WWW
Give an uncached call a try.

#9: 28-Feb-2008, 09:48 PM

Testers

ZAP
Posts: 1,619

Can I just say how incredibly slick that debug console is? Dang! The data is attached.

EDIT: Original attachment had an incorrect parameter that I was using temporarily.

* ditto2.1.0_debug_doc15a.zip (3.99 KB - downloaded 53 times.)
"Things are not what they appear to be; nor are they otherwise." - Buddha

"Well, gee, Buddha - that wasn't very helpful..." - ZAP

Useful MODx links: documentation | wiki  | forum guidelines  | bugs & requests  | info you should include with your post | commercial support options

#10: 3-Mar-2008, 07:33 PM

Moderator
Mark
Posts: 3,250

Ditto Developer

WWW
According to your debug output, Ditto is properly sorting both in DESC order. Can you try removing the tagging parameters and see if things work?

#11: 3-Mar-2008, 09:49 PM

Testers

ZAP
Posts: 1,619

When I remove the tagging parameters, I get the latest documents from the oldest folder (year). Meaning instead of showing the last two articles from 2008, it displays the last two from 2004. And if I change the parent sort order to ascending (as in the snippet call below) I get even stranger results: the oldest two articles from the the oldest folder (as if both sorts were ascending).

[!Ditto? &parents=`68,67,65,64,63` &summarize=`2` &total=`2` &tpl=`newsheadline` &paginate=`0` &alwaysshow=`1` &orderBy=`parent ASC,alias DESC` &displayArchive=`0` &depth=`1` &trunc=`0`!]
"Things are not what they appear to be; nor are they otherwise." - Buddha

"Well, gee, Buddha - that wasn't very helpful..." - ZAP

Useful MODx links: documentation | wiki  | forum guidelines  | bugs & requests  | info you should include with your post | commercial support options

#12: 11-Mar-2008, 01:10 PM

Testers

ZAP
Posts: 1,619

*BUMP!* This still isn't working for me, and the client finally noticed. Any idea why I'm getting such wacky results?
"Things are not what they appear to be; nor are they otherwise." - Buddha

"Well, gee, Buddha - that wasn't very helpful..." - ZAP

Useful MODx links: documentation | wiki  | forum guidelines  | bugs & requests  | info you should include with your post | commercial support options

#13: 11-Mar-2008, 07:11 PM

Foundation

rthrash
Posts: 11,348

WWW
Try switching "&summarize" (deprecated) with "&display". What's &total for?
MODx is a content managmeent framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#14: 11-Mar-2008, 07:55 PM

Testers

ZAP
Posts: 1,619

Thanks for the tip. I usually just copy my old Ditto calls and modify them, and since the parameters change so often I almost always have at least one outdated variable name in there. As far as I understand it, &total sets a limit on the number of documents retrieved from the database (as an MySQL LIMIT), which I would think would just speed up the query a little bit.

When I remove &total and replace &summarize with &display, I get the latest documents matching my tags but from the oldest parent folder. I think that it's just ignoring the parent part of the orderBy value entirely, because it doesn't matter if I make it ASC or DESC (I get the same results). My snippet call is:

[!Ditto? &parents=`68,67,65,64,63` &display=`2` &tpl=`newsheadline` &paginate=`0` &alwaysshow=`1` &orderBy=`parent DESC, alias DESC` &displayArchive=`0` &depth=`1` &trunc=`0` &tagDelimiter=`,` &tagData=`tvtags` &tagMode=`onlyTags` &tags=`[*menutitle*]`!]

If I can't get this fixed soon I'm going to have to write a custom snippet to do it instead, and that would make me very sad ...
"Things are not what they appear to be; nor are they otherwise." - Buddha

"Well, gee, Buddha - that wasn't very helpful..." - ZAP

Useful MODx links: documentation | wiki  | forum guidelines  | bugs & requests  | info you should include with your post | commercial support options

#15: 11-Mar-2008, 08:19 PM

Foundation

rthrash
Posts: 11,348

WWW
You might PM Mark on this one. Not one of those MySQL 5.0.51 installs by chance is it?
MODx is a content managmeent framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#16: 11-Mar-2008, 08:36 PM

Testers

ZAP
Posts: 1,619

I'm not actually sure what version MySQL is on this server because it doesn't report the version number properly. It was 4.0.2.6 and I asked the admins to update it so that I could install Pommo. They did and Pommo let me install, but phpInfo() is still reporting 4.0.2.6.

But I assume that your basic ORDER BY syntax in queries has to be working, or I'd have all sorts of other problems...

I may bug Mark and see if he's had a chance to look at this more closely. I hate to be pushy, especially since he already answers a zillion support threads every day. I guess I should go through the Ditto code as well and see if I can figure it out.
"Things are not what they appear to be; nor are they otherwise." - Buddha

"Well, gee, Buddha - that wasn't very helpful..." - ZAP

Useful MODx links: documentation | wiki  | forum guidelines  | bugs & requests  | info you should include with your post | commercial support options

#17: 12-Mar-2008, 03:12 AM

Moderator
Mark
Posts: 3,250

Ditto Developer

WWW
Give tonight's development version a try. It should fix the issue. It seems a few lines of the orderBy parser got transposed a few commits back...

#18: 12-Mar-2008, 08:17 AM

Foundation

rthrash
Posts: 11,348

WWW
FYI, I'm committing the same changes to the SVN trunk for the release. It will be labelled something other than Ditto 2.1 I suppose...
MODx is a content managmeent framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#19: 12-Mar-2008, 12:34 PM

Testers

ZAP
Posts: 1,619

Excellent! Using the new ditto class file fixed it. The only difference between the file I had and the new one were those couple lines that were transposed, but that was the root of the problem.

Why is it always some little detail that causes most major programming problems?

THANKS for tracking it down for me!
"Things are not what they appear to be; nor are they otherwise." - Buddha

"Well, gee, Buddha - that wasn't very helpful..." - ZAP

Useful MODx links: documentation | wiki  | forum guidelines  | bugs & requests  | info you should include with your post | commercial support options
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.