Oct 15, 2008, 03:10 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Donate to MODx: Donations
Pages: [1] 2   Go Down
  Print  
Author Topic: [Tutorial] Sort by a user defined date  (Read 11001 times)
0 Members and 1 Guest are viewing this topic.
Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« on: Aug 07, 2006, 07:46 PM »

The major limitation in sorting by a user defined date until this point has been that MODx does not store date TV's in UNIXTIME (it stores them in MySQL Timestamps). I found a simple and clever workaround that maintains backawards compatibility. Just create a widget that takes whatever value in the database (can even be a text field), and turn it into a UNIXTIME stamp that Ditto can use to sort. You now have the ability to enter dates both in text format or using the date chooser. The UNIXTIME Widget has been included in MODx 0.9.5 and later. Then, just append &sortBy=`tvnameofyourtemplatevariable` to your Ditto call and you are done!
« Last Edit: Feb 26, 2007, 07:11 PM by Mark » Logged

yentsun
MODx Russia
Moderators
*
Posts: 514



WWW
« Reply #1 on: Aug 08, 2006, 03:53 PM »

Thanks for your work Mark! But unfortunately this only make a UNIXTIME output for a tv, still Ditto isn't sorting by it Sad
Look what I have:
the call
Code:
[!Ditto? &startID=`17` &sortBy=`tvdate` &sortDir=`ASC` &tpl=`ditto_works` &summarize=`5`!]

output with data formatter widget:
Quote
Веб-сайт компании «Венте» («Ватель-Фестен») (Tuesday 27, December 2005)
Веб-сайт компании «Примавель» (Thursday 30, March 2006)
Веб-сайт компании «Astelcom» (Wednesday 15, March 2006)
Дизайн веб-сайта компании «FastHelix» (Monday 28, November 2005)

and output with the unixtime widget:
Quote
Веб-сайт компании «Венте» («Ватель-Фестен») (1135640114)
Веб-сайт компании «Примавель» (1143671995)
Веб-сайт компании «Astelcom» (1142379790)
Дизайн веб-сайта компании «FastHelix» (1133134700)

the order keeps the same - by createdon.
« Last Edit: Aug 08, 2006, 03:57 PM by yentsun » Logged

http://modx.ru - российская поддержка MODx
http://modxnotes.blogspot.com/ - личный блог по MODx
Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #2 on: Aug 08, 2006, 10:20 PM »

And you are using Ditto 1.0.2 right?
Logged

protocol0
Jr. Member
*
Posts: 15


« Reply #3 on: Sep 14, 2006, 07:11 PM »

i am using 1.02 and this doesn't work for me either.

instead of your approach, I hacked the date formatter to use the php date() function instead of strfrmtime or whatever it is.  Using 'U' as the parameter, so the end result is the same.  when you output the TVs there are in unixtime.

Code:
[[Ditto? &tpl=`EventsMoreEvents` &startID=`41` &truncLen=`30` &displayArchive=`0` &summarize=`10` &paginate=`1` &sortBy=`tvGGEShowDate1`]]

that's my ditto call.  but sadly, no sorting.

« Last Edit: Sep 14, 2006, 07:15 PM by protocol0 » Logged
protocol0
Jr. Member
*
Posts: 15


« Reply #4 on: Sep 14, 2006, 07:56 PM »

hi,

changing

Code:
if ($advSort == $sortBy){
$ditto->customSort($resource, $advSort, $sortDir);
}

to

Code:
$ditto->customSort($resource, $advSort, $sortDir);

gets it working!  at this point I know enough about your code to really start breaking things.  Grin  but not enough to find the real source of the bug.  i do know however, that this code:
Code:
$sortBy = isset($sortBy) ? $ditto->checkSort($sortBy, $dateFormatType, $mode) : "createdon";
    // get sortBy

sets $sortBy to "id", when before this validation routine its the name of the template variable.  is this right?

thanks mark!  i'm content with my ugly hack for now but I'd sure like to help you with the real solution.
« Last Edit: Sep 14, 2006, 10:18 PM by protocol0 » Logged
byword
Jr. Member
*
Posts: 1


« Reply #5 on: Oct 21, 2006, 05:46 PM »

Hi Mark
I tried your solution but alas it still is ordered by ID, it returns a timestamp like this (1060235247) - I also tried protocol0's hack - the debug mode had listed it as (sortBy): pub_date, when I set it to pub_date - but it didn't actually follow the order properly.

Has anyone else found a way of sorting the Ditto list or have I missed something

I have missed something - I didn't format the date correctly - I used the calendar module and it all worked fine!

Thanks
by
« Last Edit: Oct 25, 2006, 05:22 PM by byword » Logged
mediced
Jr. Member
*
Posts: 33


« Reply #6 on: Dec 06, 2006, 08:52 AM »

Hmm.  Well, I haven't tried any of the hacks above, but the reason for that is that (besides not knowing how to add a widget) shifting the date widget to a unix time means that I'll be trading a sorting problem for a display problem.  I need my dates displaying in a "November 08, 2006" format at the same time as sorting on that date.

Is there a way to do this?
Logged
lw-d
Sr. Member
****
Posts: 433


WWW
« Reply #7 on: Feb 09, 2007, 09:04 AM »

I too would like to sort my news by publish date, I am not sure what a widget is in relation to modx, could you help us out here.

Thanks
Lee
Logged

http://www.blend.uk.com | Web Design by Blend
Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #8 on: Feb 10, 2007, 09:28 PM »

@mediced

Use a snippet like DateFormat


@lw-d


A widget is used to format the output of a tv
Logged

dhilden
Full Member
***
Posts: 101



WWW
« Reply #9 on: Mar 27, 2007, 09:00 PM »

Good morning Modx users,

Modx-0.9.5, Ditto 2.0.0, Reflect 1.0.0

I have a weekly newsletter that gets sent out. The menu/page of Biz Flash looks like this with multiple ditto calls:

Biz Flash page (2)
   [!Ditto? &startID=`3` &tpl=`DittoTemplate`!]
   Apples (3)   
         News1 (6)
         News2 (7)
   [!Ditto? &startID=`4` &tpl=`DittoTemplate`!]
   Oranges (4)
         News1 (8 )
         News2 (9)
   [!Ditto? &startID=`5` &tpl=`DittoTemplate`!]
   Bananas (5)
         News1 (10)
         News2 (11)
   Etc….

The newsletter gets sent out every Friday so the goal is to keep the news from Friday-Friday showing on this page.  Stories from the previous week and before would be stored in archives by reflect. 

I’m wondering if there’s a solution that can be found by using the date filter, TVs, &sortby=published_on in last 7 days,  or something along those lines…

Anyone have a suggestion?  Imagine there are a few people that may have come across this situation.

Have a good day, and thanks in advance

Derek
« Last Edit: Mar 27, 2007, 11:36 PM by dhilden » Logged

Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #10 on: Mar 28, 2007, 12:58 AM »

You can sortBy publishedon and then use a filter that compares the publishedon value to an @EVAL that returns the time - 7 days.
Your filter would look like &filter=`publishedon,@EVAL return strtotime("-1 week");,6`
Logged

dhilden
Full Member
***
Posts: 101



WWW
« Reply #11 on: Apr 02, 2007, 04:29 AM »

Thanks for the advice! I have spent a couple of days trying to figure this out and it's getting messy...

(updated to Ditto 2.0.1)
First I created the following TV:
name: [*dittoSort*]
input type: Date
Input Option Values: @EVAL return strtotime("-1 week");,6`
widget: unixtime
sortorder: 0
connected it to the necessary templates

and on the template page have the following call:
[!Ditto? &parents=`2` &display=`all` &tpl=`DittoTemplate` &dateSource=`pub_date` &sortBy=`pub_date` &depth=`2` &hideFolders=`1` &filter=`publishedon,@EVAL return strtotime("-1 week");,6`!]

[!Reflect? &parents=`2` &tpl=`DittoTemplate` &dateSource=`pub_date` &display=`all` &depth=`2` &sortBy=`pub_date` &getDocuments=`1`!]

and the TV selector at the bottom of the page says dittoSort: (not set)

So I have tried many different options and this is what I have at the moment.   If leave out the ditto call: &filter=`publishedon,@EVAL return strtotime("-1 week");,6` the news gets sorted properly.  If I put in this ditto call it returns only 5 news stories from what seems random dates.  Reflect is also not working but I'm focussed on getting ditto to work first.

Running around in circles... how can I get Ditto to display news from the last seven days and the articles older than 7 days get stored in archive by reflect?

Really would like to get something working.  Have a nice day

Derek
« Last Edit: Apr 02, 2007, 04:41 AM by dhilden » Logged

lukwe
Full Member
***
Posts: 176



WWW
« Reply #12 on: Feb 28, 2008, 10:06 AM »


I am sorting on a TV date already; and I'd like to create a calendar with DittoCal based on that date too.

is Ditto's json output aware of the dateSource thing?
it seems to output the same exact values for the "date": part inside each one of the json 'entries', with and without the $datesource parameter (and related orderBy) in the Ditto call.



CIAO
Logged

----------------------------------------------------------
http://www.linkedin.com/in/lucapost
----------------------------------------------------------
Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #13 on: Feb 28, 2008, 10:02 PM »

JSON does not currently handle dateSource. This feature is currently planned. You can use a custom JSON template in the meantime.
Logged

annet_1409
Jr. Member
*
Posts: 24


« Reply #14 on: Jun 12, 2008, 08:34 AM »

The major limitation in sorting by a user defined date until this point has been that MODx does not store date TV's in UNIXTIME (it stores them in MySQL Timestamps). I found a simple and clever workaround that maintains backawards compatibility. Just create a widget that takes whatever value in the database (can even be a text field), and turn it into a UNIXTIME stamp that Ditto can use to sort. You now have the ability to enter dates both in text format or using the date chooser. The UNIXTIME Widget has been included in MODx 0.9.5 and later. Then, just append &sortBy=`tvnameofyourtemplatevariable` to your Ditto call and you are done!
Hello,
I want to sort Ditto output by a user defined date (TV with unixtime widget), but if user forgot to set up this TV, I want to use createdon value instead.
Can you help me?
Logged
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!