We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20647
    • 5 Posts
    Hello,

    Been pulling hairs out on what should be pretty straightforward..

    Trying to simply grab all docs with a tv value == value from GET vars..

    $unix_timestamp = mktime(0,0,0, $month, $day, $year);
    print("$unix_timestamp
    ");

    where $month, $day, $year are from url params.. this part works, as I’ve verified the printed unix timestamp value that is outputted..

    $params[’startID’] = ’88’;
    $params[’sortBy’] = ’StartTime’;
    $params[’dateSource’] = ’StartTime’;
    $params[’depth’] = ’0’;
    $params[’filter’] = ’StartTime,$unix_timestamp;,3’;

    where StartTime is my UNIXTIME tv...

    i’ve tried just about every comparison mode - they either show everything or nothing... not the expected result set..

    I’ve also tried taking the direct output of the UNIXTIME and using it in place of the $unix_timestamp var - no luck..

    All I want to do is select all docs where the TV StartTime is equal to the m/d/y provided..

    Any suggestions or examples of this would be extremely helpful..

    thx
    m2





      • 16278
      • 928 Posts
      The filter is exclusive rather than inclusive, so you need to exclude documents that don’t match your requirements. The filter mode for that is "1". You should get your desired result with:
      &filter=`StartTime,$unix_timestamp,1`;

      (or equivalent in whatever your $params array is from).
      If you’re using the current version of Ditto (2.1), your parameters for starting document and sorting should read &parents and &orderBy instead of &startId and &sortBy, which are are out of date, though they still work. You always have to state the direction with &orderBy, e.g. &orderBy=`StartTime DESC`. The advantage of the newer parameters is that you can have comma-separated multiple values.
      Ditto 2.1 parameters are listed on the Ditto site at http://ditto.modxcms.com/files/snippet-ditto-php.html.
      cool KP
      [a little later:] Alternatively, you could try the tempting little dateFilter extender, which seems to have been created for your needs! (Found it while checking out some other parameter details, and poked around a little with it on a test page). The menu link from Ditto docs page is a dead end, but you can go direct to http://ditto.modxcms.com/files/assets/snippets/ditto/extenders/dateFilter-extender-inc-php.html to see the details. Not sure how it works out with getting the date specs fromt he URL, but it works well on my test data using parameters directly. :-}
        • 20647
        • 5 Posts
        thx, but....

        ok, so i made the changes and still no go... I echo’d the two time stamps and they are not the same - my guess is that my time stamp is generated from mdy, whereas the modx one, generated via widget, also contains hms - which is slightly difrnt..

        but then I also tried excluding everything greater than the several days after the desired date - returned no records - whereas it should’ve returned 1 doc.. my docs start on 4/16/2009 and go newer from there

        		$month = $monthNum;  // month = 04 
        		$day = $dayNum;    // day = 23
        		$year = $yearNum;   // year = 2009
        		$unix_timestamp = mktime(0,0,0, $month, $day, $year);
        		print("$unix_timestamp<br>");
        		$params['parents'] = '88';
        		$params['orderBy'] = 'StartTime ASC';
        		$params['depth'] = '0';
        		$params['filter'] = 'StartTime,$unix_timestamp,4';
        		$params['showInMenuOnly']='1';
        		$params['tpl']='event_view_details';
        		$params['dateFormat']='%a, %B %e @ %I:%M %p';
        		$snippet=$modx->runSnippet('Ditto', $params);
        		echo($snippet);
        


        of course, i also tried using date filter extension to no avail.. I’ve been all over looking for data filter examples - found nothing,

        any ideas? would date filter extension be a better fit? have any examples of source for said?

        thx again... MUCH APPRECIATED...

        m2
          • 20647
          • 5 Posts

          re: dateFilter extender... I still cannot it to work..

          Here is what my call looks like.. when I run it without the extender, it returns results - as soon as i add the extender it returns No Docs Found... Everything is up to date - recent install..

          [!Ditto? &parent=`88` &showInMenuOnly=`1` &orderBy=`StartTime DESC` &dateSource=`StartTime` &dateFormat=`%a, %B %e @ %I:%M %p` &summarize=`10` &depth=`0` &total=`10` &tpl=`event_summary` &extenders=`dateFilter,@FILE assets/snippets/ditto/extenders/dateFilter.extender.inc.php` &dateFilterSource=`params` &dateFilterDefault=`1` &month=`6` &day=`16` &year=`2009` !]
          



          Also, I’ve tried using GET and PARAMs options - to no avail..

          I am perplexed - do you see any red flags? Would you mind posting your code that worked?

          HELP?

            • 16278
            • 928 Posts
            I’ve explored dateFilter a bit further, and what is laid out below works for me with MODx 0.9.6.3 (and Ditto 2.1+ that comes with it), PHP 5.2.1, Apache 2.2 and MySQL 5.0.37 on my Windows PC. Be aware that the dateFilter, as far as I can make out, is intended for use together with the Reflect archive generator, rather than directly in Ditto. But it works! Beware also cache issues - Ditto is normally used [[cached]], and needs to be if you want pagination to work. But if you also have the PHx plugin installed (as I do), you have to make the document with the Ditto call "not cacheable" in the Page Settings area to avoid a conflict. [[later EDIT: Ditto may normally be cached or uncached, but if using pagination, must be uncached when except when PHx is active, when the call is cached and page non-cacheable]].

            So here it is, for what it’s worth. I have tried it on a test set of over 50 documents with random dates in my template variable pkDate, which is a straightforward date TV with the Unixtime widget.
            [[Ditto? &parents=`711` &extenders=`dateFilter` &config=`getDate` &orderBy=`pkDate ASC` &paginate=`1` &display=`5`]]
            [+pages+]
            Notes:
            &extenders: just give the name, Ditto works out the filename and location for itself.
            &display sets how many items to show per page - &summarize is another outdated parameter
            &config links to an external PHP file with further parameters and setup code, including extraction of GET variables, stored in Ditto’s config folder as getDate.config.php.
            <?php
            // config file for filtering by date in URL
            // TEST VERSION ONLY - needs some checks on the date values
            
            $dateSource='pkDate';
            $dateFilterSource='pkDate';
            
            if (isset($_REQUEST['year'])) {
            	$year = $_REQUEST['year'];
            	if (isset($_REQUEST['month'])) {
            		$month = $_REQUEST['month'];
            		if (isset($_REQUEST['day'])) {
            			$day = $_REQUEST['day'];
            		}
            	}
            }
            ?>
            

            With no template specified, this uses the built-in Ditto template and shows pkDate as the date. The filter values are passed in the URL as /server/doc.html?year=2007&month=10&day=28 etc. This is test code only - you’d want to make it a little more specific and secure for the real thing. The pagination happily attaches the page-selection query values to the date-selection ones just by sticking [+pages+] at the bottom.

            I hope this helps. Given that dateFilter doesn’t seem to be primarily intended to work this way, it might not merit too much sweat if you can’t get it going - it should be possible to take the &filter approach further, and there are bound to be other ways to attack the problem. I just happen to be working on a demo of Ditto 2.1 parameters and operation (which I’ll share if it comes to anything), and this was an interesting sideline.
            laugh KP
              • 20647
              • 5 Posts
              hey - THANX for the help..  I’ve finally come to the conclusion that A) I am not crazy and B) It really is as easy as it looks..

              I just tried the dataFilter ditto call from my local install (MacBook Pro Running MAMP (PHP v5.2.5, mySQL v5.0.41, Apache 2.0.59  ) ) and it works perfectly!  So, it appears that the server running the live production site is possibly to blame>?

              Live production site: PHP v5.2.8, mySQL v5.0.45, Apache 1.3.33 <<  dataFilter NOT working!

              both have same version of modx, everything identical..

              So, it appears that the problem may be the older version of Apache?  I will try swapping it out and see what happens..


              thx again,
              m2
                • 7810
                • 26 Posts
                Hi there,
                I’m having a very similar problem, or even more simple. I would like Ditto to show documents only for the current month. There is a date TV ("dittodata") with the Unixtime widget, the year and day can vary in it, but I need to show only this month inspite of the year it holds. I’m completely raw at PHP, so I’m stuck here. Thought this should be easy to configure simply , but dateFilter documentation is very unclear.

                Here is my Ditto call:
                [[Ditto? &parents=`[*id*]` &extenders=`dateFilter` &dateSource=`dittodata` &dateFilterSource=`dittodata` &dateFormat=`%Y %m %d` &month=`5` &tpl=`ditto_news2` &display=`10` &orderBy=`dittodata ASC` &paginate=`1` &paginateAlwaysShowLinks=`1` ]]


                Would apreciate any advice. Thankyou.
                  MODx is great! Thanks for great work!

                  Portfolio, mostly MODx: dbdizainas.lt
                  • 7810
                  • 26 Posts
                  OK, I guess there’s a more accurate to my question thread: http://modxcms.com/forums/index.php/topic,14354.0.html
                    MODx is great! Thanks for great work!

                    Portfolio, mostly MODx: dbdizainas.lt