Oct 07, 2008, 02:58 AM *
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:Read what MODx Developers say: MODx Dev. Blogs
Pages: [1]   Go Down
  Print  
Author Topic: NewsListing filtering - not working as expected  (Read 3681 times)
0 Members and 1 Guest are viewing this topic.
omnivore
Jr. Member
*
Posts: 46

Can this be real?


WWW
« on: Apr 07, 2006, 01:47 PM »

i have a newslisting on my home page that looks like this:
Code:
[[NewsListing? &startID=`47` &summarize=`6` &total=`6` &tpl=`eventListingHome`  &sortby=`tvtestSort` &sortdir=`asc` &truncText=`More` &filter=`tvtestSort,>[[unixtime]],1`]]

But I'm not getting the results I expected. [[unixtime]] is a snippet that does that, returns the unixtime. So the idea is that this would show items after (or before) the current unixtime. I can compare the value of the tv, testSort, and the unixtime returned by the snippet, and it isn't working. Depending on the last argument to filter, it either turns up all or none of the items, but there are values stored that are both higher and lower.

It occured to me that the NewsListing might not be able to parse the embedded snippet, although i wasn't sure why, but in any case, wrote another snippet that outputs the same text to the page, but substitutes mktime() for the [[unixtime]], and concatenates the whole together before writing it to the page, but that doesn't work either.

Any ideas why?
Logged

Web Designer
PHP Programmer
Cocoa Developer
Boulevardier & Arriviste
davidm
Marketing & Design Team
*
Posts: 6,651


The best way to predict the future is to invent it


WWW
« Reply #1 on: Apr 07, 2006, 02:06 PM »

Sorry for the dumb question but is the ">" supposed to be here in the call ?  e.g ">[[unixtime]]"  Huh
Logged

blog.nodeo.net : Pour un web libre, moderne et ouvert! :: | ! Nouveau ! Les forums modxcms.fr : Participez à l'élaboration du site MODx francophone ! ! Nouveau ! :.

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.45 - PHP 5.2.6 | Debian 4.0 (Etch)

Réalisations sous MODx : nodeo.net | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | sworld.com | soleil.info
 et 3 autres en cours de réalisation Smiley
Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #2 on: Apr 07, 2006, 02:10 PM »

I believe he wants it to be less than the current date and so he put that there. Omnivore, NewsListing does not yet support that because PHP doesn't execute if($var1 $sign $var 2) correctly and until I can find a workaround you'll have to swap the = in the code with the > (should be a piece of cake, if you need specific lines to change let me know [I don't have access to my code here]).
Logged

omnivore
Jr. Member
*
Posts: 46

Can this be real?


WWW
« Reply #3 on: Apr 07, 2006, 02:42 PM »

I believe he wants it to be less than the current date and so he put that there. Omnivore, NewsListing does not yet support that because PHP doesn't execute if($var1 $sign $var 2) correctly and until I can find a workaround you'll have to swap the = in the code with the > (should be a piece of cake, if you need specific lines to change let me know [I don't have access to my code here]).

Thanks for the quick replies...

yes, that's what I want, for the test to be that the current time is less than the time recorded in the tv.

Okay... so what this means is that I need to hack NewsListing to work this way? Not quite sure what Mark is pointing at, but I haven't gone through the code yet. What comparisons can be in that middle argument? equality only? When you say that its a PHP thing, does that mean that the expression gets evaluated by PHP wrongly/unreliably?

Also - is there documentation for this somewhere, beyond the comments in the snippet? The stuff on the modxcms site seems to be out of date for 6.3.3
Logged

Web Designer
PHP Programmer
Cocoa Developer
Boulevardier & Arriviste
omnivore
Jr. Member
*
Posts: 46

Can this be real?


WWW
« Reply #4 on: Apr 07, 2006, 03:37 PM »

I think that this is the solution. In the area of the NewsListing code, at line 400, you find this loop:

Code:
foreach ($resources as $k=> $r) {
if( $filtertype == 1 && (!isset ($r[$filterKey]) || $r[$filterKey]!=$filterName) ) {
unset($resource[$k]);
} else if ( $filtertype == 2 && $r[$filterKey]==$filterName ) {
unset($resource[$k]);
}

}


I substituted this switch statement for the above. It gives six modes:

1 not equal
2 equal
3 less than
4 greater than
5 less than or equal
6 greater than or equal

Code:
foreach ($resources as $k=> $r) {
$unset = false;
switch ($filtertype){
case "!=" :
case 1 :
if (!isset ($r[$filterKey]) || $r[$filterKey]!=$filterName) $unset=true;
break;
case "=" :
case 2 :
if ($r[$filterKey]==$filterName)  $unset=true;
break;
case "<" :
case 3 :
if ($r[$filterKey]<$filterName)  $unset=true;
break;
case ">" :
case 4 :
if ($r[$filterKey]>$filterName)  $unset=true;
break;
case "<=" :
case 5 :
if (!($r[$filterKey]<$filterName))  $unset=true;
break;
case ">=" :
case 6 :
if (!($r[$filterKey]>$filterName))  $unset=true;
break;
}
if ($unset) unset($resource[$k]);

}

in fact, the mode argument could just as easily be the operator sign, so I added those to the switch statement to make things a little less cryptic.

Haven't tested extensively, but seems to work.

Hope that's useful to someone.
Logged

Web Designer
PHP Programmer
Cocoa Developer
Boulevardier & Arriviste
Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #5 on: Apr 07, 2006, 05:52 PM »

Perfect!
Logged

Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #6 on: Apr 08, 2006, 10:23 AM »

Sorry about the brief response earlier, I was on my PSP and could only type out one word! That code is great! With a few modifications to allow both mode 1 and 2 for each of the sign versions I'll put that in the next release. Could you file that in the NewsListing BugTracker please? Thanks!
Logged

Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #7 on: Apr 09, 2006, 11:19 AM »

Added and released in NewsListing 6.4
Logged

omnivore
Jr. Member
*
Posts: 46

Can this be real?


WWW
« Reply #8 on: Apr 11, 2006, 04:02 PM »

Sorry about the brief response earlier, I was on my PSP and could only type out one word! That code is great! With a few modifications to allow both mode 1 and 2 for each of the sign versions I'll put that in the next release. Could you file that in the NewsListing BugTracker please? Thanks!

Too kind.

I went away for a few days - since its in the 6.4, I'll assume that you don't need the bugtracker entry...

Logged

Web Designer
PHP Programmer
Cocoa Developer
Boulevardier & Arriviste
Mark
Moderator
*
Posts: 3,247


Ditto Developer


WWW
« Reply #9 on: Apr 11, 2006, 04:04 PM »

I believe I already closed the entry, marking it as complete. BTW, 6.4 actually has the ability to have the entire NL template change and not just a class so you have alot more power.
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!