We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22213
    • 52 Posts
    i have a newslisting on my home page that looks like this:
    [[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?
      Web Designer
      PHP Programmer
      Cocoa Developer
      Boulevardier & Arriviste
      • 6726
      • 7,075 Posts
      Sorry for the dumb question but is the ">" supposed to be here in the call ? e.g ">[[unixtime]]" huh
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
        • 18397
        • 3,250 Posts
        MARKSVIRTUALDESK Reply #3, 18 years ago
        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]).
          • 22213
          • 52 Posts
          Quote from: Mark at Apr 07, 2006, 07: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]).

          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
            Web Designer
            PHP Programmer
            Cocoa Developer
            Boulevardier & Arriviste
            • 22213
            • 52 Posts
            I think that this is the solution. In the area of the NewsListing code, at line 400, you find this loop:

            		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

            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.
              Web Designer
              PHP Programmer
              Cocoa Developer
              Boulevardier & Arriviste
              • 18397
              • 3,250 Posts
              MARKSVIRTUALDESK Reply #6, 18 years ago
              Perfect!
                • 18397
                • 3,250 Posts
                MARKSVIRTUALDESK Reply #7, 18 years ago
                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!
                  • 18397
                  • 3,250 Posts
                  MARKSVIRTUALDESK Reply #8, 18 years ago
                  Added and released in NewsListing 6.4
                    • 22213
                    • 52 Posts
                    Quote from: Mark at Apr 08, 2006, 03:23 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...

                      Web Designer
                      PHP Programmer
                      Cocoa Developer
                      Boulevardier & Arriviste
                      • 18397
                      • 3,250 Posts
                      MARKSVIRTUALDESK Reply #10, 18 years ago
                      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.