We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30310
    • 6 Posts
    [[getResources? &parents=`[[*id]]` &tpl=`event_blog` &includeTVs=`1` &sortbyTV=`eventDate` &sortdirTV=`ASC` &sortby=``]]

    This is my get resourses call, the chunk I used is complete, really the EventFilter snippet should call another chunk to format the data, but this is a quick and dirty way of doing it.

    I am looking at trying to modify getResources to do this properly as this method doesn’t allow you to limit the number of items you get, as you can only limit before you filter. I will post when I have finished that method, but it could be some time before I get chance.

    Tom
      • 25141
      • 49 Posts
      that’s weird, even using your exact code I can’t get it to work ... thanks anyway, maybe I can figure it out sometime soon ...
        • 30310
        • 6 Posts
        The key bits are the
        &date=`[[+tv.eventDate:strtotime]]`

        in the chunk which takes the eventDate TV passed in and changes it to a linux timestamp

        This is then used for the filter in the snippet EventFilter:
        if ($date >= time())


        Just to check, my page calls getResources which in turn gets the chunk which calls the EventFilter snippet which decides whether or not to output. The only other thing I can think of is what is the output format of your TV? If you add something like
        echo $date;
        echo time();

        to the EventFilter snippet you should get an idea what it is doing.

        Tom
          • 30310
          • 6 Posts
          This is a very specific fix, but I added this to the getResources snippet (actually I made a copy and added this to the copy).

          if (!empty($filterTVDate))
          {
              $tmplVarTbl = $modx->getTableName('modTemplateVar');
              $tmplVarResourceTbl = $modx->getTableName('modTemplateVarResource');
              $condition = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tv`.`name` = \"{$filterTVDate}\" AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`value` > '" . date("Y-m-d H:i:s") . "' AND `tvr`.`contentid` = `modResource`.`id`)";
              $criteria->andCondition($condition);
          }
          


          This way if you set the filterTVDate to the name of your template variable it will return all dates after the current time. (Just change the > if you want to change to dates in the past for example. You can also change the test date from now by adding a parameter to the date function, have a look on php.net for the documentation.

          Tom
            • 25141
            • 49 Posts
            Woo-hoo, I got it to work: I had to call the snippet uncached, as my page is cacheable ...

            As in (my adapted version):
            [[!EventFilter? &date=`[[+tv.eventDate:strtotime]]`
            &content=`<p class="event">[[+tv.eventPicture]]<a href="[[~[[+id]]]]" class="loud">[[+pagetitle]]</a> / [[+tv.eventDate:strtotime:date=`%d %b %Y`]] - [[+tv.eventEndDate:strtotime:date=`%d %b %Y`]]
            [[+tv.eventSummary]] <hr class="clearer"/></p>`]]

            btw my TV output is set to default.

            Thanks for your help Tom! I didn’t try your specific fix yet - but I don’t really need it anymore, do I?

            *EDIT*
            oh that was a bit too early - all my current events are now shown twice -- when I eliminate the &sortby=`` in my call even three times ... - anybody happen to have an idea why that?


            **SECOND EDIT**
            ’twas a bug, the getresources Update 1.2.2. fixed it!