We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21703
    • 28 Posts
    Have:
    1. Revolution.
    2. List of documents with TV (date).

    Need:
    1. Select documents with TV value less than now()
    2. Sort these documents by this TV

    This did not work:
     $query = $modx->newQuery('modResource');  
    $query->where(array(  
      'parent:IN' => array(2),  
      'deleted' => false,  
      'hidemenu' => false,  
      'published' => true
    ));  
    $query->sortby('eventDateStart','ASC');
    


    eventDateStart is TV type `date`
      • 28215
      • 4,149 Posts
      $now = strftime('%Y-%m-%d %H:%M:%S',time());
      $c = $modx->newQuery('modResource');
      $c->innerJoin('modTemplateVarResource','TemplateVarResources');
      $c->innerJoin('modTemplateVar','TemplateVar','`TemplateVar`.`id` = `TemplateVarResources`.`tmplvarid` AND `TemplateVar`.`name` = "eventDateStart"');
      $c->where(array(
          'parent:IN' => array(2),
          'deleted' => false,
          'hidemenu' => false,
          'published' => true,
          'TemplateVarResources.value:<' => $now,
      ));
      $c->sortby('`TemplateVarResources`.`value`','ASC');
      $resources = $modx->getCollection('modResource',$c);
      

        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 21703
        • 28 Posts
        Thank you.

        And can you show how to do this with snippet [[!getResource? ]] or [[!Ditto? ]] (in Revolution) ?
          • 21703
          • 28 Posts
          Another question.

          How can I do same thing, but include in collection objects with (eventDateStart IS NULL). Something like this:

          'published' => true,
          'TemplateVarResources.value:<' => $now,
          /* Here add TemplateVarResources.value IS NULL (or TemplateVarResources.value == '') */
          

            • 11031
            • 11 Posts
            Quote from: noff at Jul 31, 2010, 01:39 PM

            And can you show how to do this with snippet [[!getResource? ]] or [[!Ditto? ]] (in Revolution) ?

            I’m need to do same thing with [[!getResource? ]]
              • 3749
              • 24,544 Posts
              The current version of getResources has a &where parameter. It takes its info in JSON format. Here’s an example from the code:
              &where=`{{"alias:LIKE":"foo%", "OR:alias:LIKE":"%bar"},{"OR:pagetitle:=":"foobar", "AND:description:=":"raboof"}}`
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 11031
                • 11 Posts
                Quote from: BobRay at Aug 02, 2010, 04:35 PM

                The current version of getResources has a &where parameter. It takes its info in JSON format. Here’s an example from the code:
                &where=`{{"alias:LIKE":"foo%", "OR:alias:LIKE":"%bar"},{"OR:pagetitle:=":"foobar", "AND:description:=":"raboof"}}`


                That’s cool, but i dont understand how to use this to get TV parameters and filter on results?
                I cant filter only folowing parameters:
                [tt]id
                type
                contentType
                pagetitle
                longtitle
                description
                alias
                link_attributes
                published
                pub_date
                unpub_date
                parent
                isfolder
                introtext
                content
                richtext
                template
                menuindex
                searchable
                cacheable
                createdby
                createdon
                editedby
                editedon
                deleted
                deletedon
                deletedby
                publishedon
                publishedby
                menutitle
                donthit
                haskeywords
                hasmetatags
                privateweb
                privatemgr
                content_dispo
                hidemenu
                class_key
                context_key
                content_type[/tt]

                i see the code of function &tvFilters
                [tt]$conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` LIKE {$tvValue} AND `tv`.`name` = {$tvName} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";[/tt]

                but i cant reproduce this SELECT in &where fonction
                  • 30025
                  • 32 Posts
                  While using getResources with &where I cannot use template variables. Below is the code I am using. artistName is the template variable.

                  &where=`{{"artistName:=":"Travis"}}`


                  With this command I get the following error:

                  [2010-09-14 23:53:18] (ERROR @ /index.php) Error 42S22 executing statement: Array ( [0] => 42S22 [1] => 1054 [2] => Unknown column 'modResource.artistName' in 'where clause' )



                  Someone help me please!
                    • 30310
                    • 6 Posts
                    This isn’t the nicest way ever, but a very simple way of getting what you want:

                    I made a new snippet which is really simple:
                    <?php
                    if ($date >= time())
                    {
                      echo "<h3>$title</h3>";
                      echo "<p>$content</p>";
                    }
                    ?>
                    


                    and then used that snippet as part of the template chunk I gave to getResources, so this is my chunk:

                    [[EventFilter? &date=`[[+tv.eventDate:strtotime]]`
                    &title=`[[+tv.eventDate:strtotime:date=`%d %b %Y`]] - [[+pagetitle]] - [[+tv.eventDate:strtotime:date=`%H:%M`]]`
                    &content=`[[+introtext]] <a href="[[~[[+id]]]]">More >></a>`]]
                    


                    You can change the way I have used content and title to something more suitable for yourself or something a bit more flexible but the basic concept it there.

                    I am new to modx but the simple concept of snippets and chunks is so powerful and flexible, I love it.

                    Tom
                      • 25141
                      • 49 Posts
                      Hi Tom,

                      I tried making your snippet, but all I get are the arrays (not filtered by date) - do you have anything else in your chunk? And would you mind posting your getResources call?

                      Thanks for your help,
                      Rixe