Dec 04, 2008, 01:31 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Ditto Filter Question  (Read 3271 times)
0 Members and 1 Guest are viewing this topic.
bmcneill
Member
**
Posts: 64


interactive design and communications


« on: Jul 04, 2007, 12:47 PM »

Can someone help me out here.  i am sure i am overlooking something very obvious, but i am trying to do a filter on a TV date field in the ditto call and cannot get it to work right.  i want all docs that have an artcle_date (tvarticle_date to ditto) that are greater than now() to appear in this particular section - but continue to get no results.  here is the call:

[!Ditto? &display=`all` &tpl=`article_dittoTpl` &dateSource=`tvarticle_date` &dateFormat=`%A %B %d, %Y %r` &filter=`tvarticle_date, UNIX_TIMESTAMP(), 4` &sortBy=`tvarticle_date` &sortDir=`desc` &debug=`1`!]

I have tried the non-UNIX timestamp (CURRENT_TIMESTAMP()) as well and still get no results.

thanks in advance for any help on this.
Logged
rthrash
Foundation
*
Posts: 9,577



WWW
« Reply #1 on: Jul 04, 2007, 12:56 PM »

Is unix_timestamp() or current_timestamp() a PHP function? I can't find a reference to those, and if they are I believe the syntax is @CODE:unix_timestamp(); ... but I'm probably wrong there... Mark?

There is time() available: http://www.php.net/manual/en/function.time.php
Logged

MODx is a framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Community participation and questions are encouraged, especially when you help us help you, read the wiki, and review snippet parameters – even if you have to look at the source. Searching the forums helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
bmcneill
Member
**
Posts: 64


interactive design and communications


« Reply #2 on: Jul 04, 2007, 02:18 PM »

they are mysql syntax.  i was thinking it wanted that for the sql statement.  however, i did also try php syntax and could not get date() or time() to work either.
Logged
heliotrope
Coding Team
*
Posts: 2,447


WWW
« Reply #3 on: Jul 04, 2007, 03:40 PM »

Hi,

php functions cannot be used as snippet params.
Create a new snippet with this code for instance

return time();

and then use it within your ditto call.

To embed a snippet inside another one you must use this syntax

[!Ditto? &filter=`tvarticle_date,[[myTimeSnippet]],3` => which means in ditto language Remove all documents from results where tvarticle_date is less than now.

:-)
Logged

bmcneill
Member
**
Posts: 64


interactive design and communications


« Reply #4 on: Jul 04, 2007, 05:03 PM »

ah yeah.  thanks for the BGO.  it works perfectly now. 

thanks all.
Logged
Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #5 on: Jul 04, 2007, 05:22 PM »

Ditto supports the @EVAL binding to evaluate php expressions in filter clauses. Thus, @EVAL time(); is the correct syntax to get the current unix timestamp ala http://modxcms.com/eval-binding.html. Here is a working example which will retrieve all documents in the last year.

Code:
[!Ditto?parents=`2`&debug=`1`&display=`all`&filter=`createdon,@EVAL return strtotime('-1 year');,6`!]

Also, here is a related thread:
http://modxcms.com/forums/index.php/topic,16012.0.html
« Last Edit: Jul 04, 2007, 05:25 PM by Mark » Logged

rthrash
Foundation
*
Posts: 9,577



WWW
« Reply #6 on: Jul 05, 2007, 08:17 AM »

Great pointers Mark. Thanks Smiley
Logged

MODx is a framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Community participation and questions are encouraged, especially when you help us help you, read the wiki, and review snippet parameters – even if you have to look at the source. Searching the forums helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
bmcneill
Member
**
Posts: 64


interactive design and communications


« Reply #7 on: Jul 05, 2007, 11:49 AM »

on a somewhat related note, if i wanted to add a default date to this TV (so a date is submitted even if the user does not actually select a date), can I use @EVAL return time() as the expression in the Default value of the TV?  I am using this right now and it is not writing a value to the database.  It may be that '@EVAL return time()' produces a UNIXTIME and I think the TV dates are saved to mysql in non-UNIX time format.  do i need to be formatting the 'time()' value to a non-UNIX date format for the default value?
Logged
Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #8 on: Jul 05, 2007, 12:11 PM »

The default value will be executed when the TV is loaded, not when saved. Thus, the default value would be the current time the tv is loaded.
Logged

sal
Member
**
Posts: 76



WWW
« Reply #9 on: Oct 02, 2007, 06:03 AM »

I was wondering on this point actually. I hoped the @EVAL thing would work to set the default date TV value to the current date but realised this probably wouldn't since the field is handled by Tigra so isn't an actual form field. Anyone know a quick way round this?
Logged
FuryDE
Full Member
***
Posts: 172



« Reply #10 on: Nov 05, 2008, 08:05 AM »

Ditto supports the @EVAL binding to evaluate php expressions in filter clauses. Thus, @EVAL time(); is the correct syntax to get the current unix timestamp ala http://modxcms.com/eval-binding.html. Here is a working example which will retrieve all documents in the last year.

Code:
[!Ditto?parents=`2`&debug=`1`&display=`all`&filter=`createdon,@EVAL return strtotime('-1 year');,6`!]
Hi, I wonder if this is correct ... The &filter EXCLUDES documents from the results. So, if you filter documents created on a date greater or equal (6) to "now minus one year", you EXCLUDE all the docs from last year, not include.

Also, I wonder why you first say @EVAL time(); is correct, but in your example you write @EVAL return strtotime(); (the difference is the "return").

I ask, because I am having massive problems with date filtering.

I also have a TV with unixtimestamp. Sorting works fine, but filtering doesn't work at all. i have &filter=`VAStart,@EVAL return time();,3` to filter out all events from the past. I get all docs. And, if i use 6 instead of 3, I also get all the docs.

Debugging shows me that the filter is recognized corretly and that the values of the VAStart TV are correct too. I don't know what the problem is.

BTW: I used Ditto 2.0.2, but I have just upgraded to 2.1. But I still run into the same problems.

Thanks
Martin
« Last Edit: Nov 07, 2008, 02:49 AM by FuryDE » Logged
Pages: [1]   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!