We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11055 ☆ A M B ☆
    • 3,112 Posts
    My initial call: [[getResources]] or [[!getResources]]

    [2010-08-16 17:42:12] (ERROR @ /[myLocalhostAddress]/index.php) Error 42000 executing statement: Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’1,2,3,4,5,6,7,11,8,9,10) AND (`modResource`.`context_key` IN (’web’) OR EXISTS(S’ at line 1 )

      Rico
      Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
      MODx is great, but knowing how to use it well makes it perfect!

      www.virtudraft.com

      Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

      Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

      Maintainter/contributor of Babel

      Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
      • 25979
      • 178 Posts
      Hi, great snippet, but for me the &resources parameter doesn’t work. Tried many combinatins. None worked.

      Any ideas?


      Regards,

      Mike
        //Why use windows since there is a door?//
        • 3749
        • 24,544 Posts
        Quote from: salik at Aug 16, 2010, 05:15 PM

        Hi, great snippet, but for me the &resources parameter doesn’t work. Tried many combinatins. None worked.

        Any ideas?

        I don’t think there is a &resources parameter (at least not according to the docs): http://rtfm.modx.com//display/ADDON/getResources%3bjsessionid=5F3E995E2D41D4047621E65E4D5BE62A#getResources-AvailableProperties

        That could be why it doesn’t work. wink

          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
          • 17883
          • 1,039 Posts
          getResources 1.1.0-pl (July 30, 2010)

          * - Added &toPlaceholder property for assigning results to a placeholder
          * - Added &resources property for including/excluding specific resources
          * - Added &showDeleted property
          * - Allow multiple contexts to be passed into &context
          * - Added &showUnpublish property
          * - Added getresources.core_path reference for easier development
          * - [#ADDON-135] Make output separator configurable via outputSeparator property
          * - Add where property to allow ad hoc criteria in JSON format

          http://modxcms.com/extras/package/?package=552

          ;)
            • 11055 ☆ A M B ☆
            • 3,112 Posts
            Quote from: goldsky at Aug 16, 2010, 05:50 AM

            My initial call: [[getResources]] or [[!getResources]]
            [2010-08-16 17:42:12] (ERROR @ /[myLocalhostAddress]/index.php) Error 42000 executing statement: Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’1,2,3,4,5,6,7,11,8,9,10) AND (`modResource`.`context_key` IN (’web’) OR EXISTS(S’ at line 1 )

            I tried to debug this.
            My resource tree is like this:

            • parent (1)
            • parent (2)
            • parent (3)

            • [list]
              [li]child (11)
            [/li]
            [li]parent (4)[/li]
            [li]parent (5)[/li]
            [li]parent (6)[/li]
            [li]parent (7)[/li]
            [/list]
            Then I called [[!getResources? &parents=`3`]]
            The output was:

            [2010-08-17 10:59:18] (ERROR @ /[myLocalhostAddress]/index.php) Error 42000 executing statement: Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’3,1,2,3,4,5,6,7,11,8,9,10) AND (`modResource`.`context’ at line 1 )

            I hacked the script with this at line 79:
            <?php
            
            /********* debug *********/
            echo '<pre>';
            print_r($parents);
            echo '</pre>';
            die();
            /********* debug *********/
            
            foreach ($parents as $parent) {
                $pchildren = $modx->getChildIds($parent, $depth);
                if (!empty($pchildren)) $children = array_merge($children, $pchildren);
            }
            if (!empty($children)) $parents = array_merge($parents, $children);
            

            The result is this:
            Array
            (
                [0] => 3
            )
            


            Then I moved the debug part:
            <?php
            
            foreach ($parents as $parent) {
                $pchildren = $modx->getChildIds($parent, $depth);
                if (!empty($pchildren)) $children = array_merge($children, $pchildren);
            }
            if (!empty($children)) $parents = array_merge($parents, $children);
            
            /********* debug *********/
            echo '<pre>';
            print_r($parents);
            echo '</pre>';
            die();
            /********* debug *********/
            
            

            And the result went this:
            Array
            (
                [0] => 3
                [1] => 1
                [2] => 2
                [3] => 3
                [4] => 4
                [5] => 5
                [6] => 6
                [7] => 7
                [8] => 11
                [9] => 8
                [10] => 9
                [11] => 10
            )
            


            I haven’t have time to debug the modX::getChildIds, but that method should be re-investigated again.
              Rico
              Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
              MODx is great, but knowing how to use it well makes it perfect!

              www.virtudraft.com

              Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

              Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

              Maintainter/contributor of Babel

              Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
              • 6180
              • 31 Posts
              While I really like the functionality this snippet provides, I actually found it frustrating that the tvFilters only did "Like" filtering. I need to be able to filter for resources between values (dates in particular) as well. So, I modified the snippet a bit to allow for this. I just want to throw this out there as a worthy feature to add.

              To pass a BETWEEN set the call looks like this:
              &tvFilters=`EventStartDate><'2010-08-01'#DATETIME&'2010-10-01 23:59:59'#DATETIME`


              The string is delimited in several ways. The first delimiter is the "><" which flags this as a BETWEEN statement. The "&" distinguishes the two sides of the BETWEEN query filter, and the "#" delimits the value from a standard MySQL datatype. I am using the data type to populate a CAST statement to ensure the values are handled properly. Ultimately I plan on setting this up so that I can utilize URL passed parameters.

              I duplicated the snippet, then modified my copy to include these changes:
              if (!empty($tvFilters)) {
                  $tmplVarTbl = $modx->getTableName('modTemplateVar');
                  $tmplVarResourceTbl = $modx->getTableName('modTemplateVarResource');
                  $conditions = array();
                  foreach ($tvFilters as $fGroup => $tvFilter) {
                      $filterGroup = count($tvFilters) > 1 ? $fGroup + 1 : 0;
                      $filters = explode(',', $tvFilter);
                      foreach ($filters as $filter) {
                          if (strpos($filter, '==') !== false) {
                              $mode = 1 ;
                          } elseif (strpos($filter, '><') !== false) {
                              $mode = 2 ;
                          } else {
                              $mode = 0 ;
                          }
                          switch($mode) {
                              case 1:
                                  $f = explode('==', $filter);
                                  if (count($f) == 2) {
                                      $tvName = $modx->quote($f[0]);
                                      $tvValue = $modx->quote($f[1]);
                                      $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`)";
                                  } elseif (count($f) == 1) {
                                      $tvValue = $modx->quote($f[0]);
                                      $conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` LIKE {$tvValue} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
                                  }
                                  break ;
                              case 2:
                                  $f = explode('><', $filter);
                                  if (count($f) == 2) {
                                      $tvName = $modx->quote($f[0]);
                                      $ranges = $f[1];
                                      $d = explode('&', $ranges);
                                      if (count($d) == 2) {
                                          for ($i = 0, $size = sizeof($d); $i <= $size; ++$i) {
                                              $p = explode('#', $d[$i]);
                                              $tvValue[$i] = "CAST(".$p[0]." as ".$p[1].")" ;
                                          }
                                          $conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` BETWEEN {$tvValue[0]} AND {$tvValue[1]} AND `tv`.`name` = {$tvName} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
                                      }
                                  } elseif (count($f) == 1) {
                                      $tvValue = $modx->quote($f[0]);
                                      $conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` BETWEEN {$tvValue} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
                                  }
                          }
                      }
                  }
                  if (!empty($conditions)) {
                      foreach ($conditions as $cGroup => $c) {
                          if ($cGroup > 0) {
                              $criteria->orCondition($c, null, $cGroup);
                          } else {
                              $criteria->andCondition($c);
                          }
                      }
                  }
              }
              


              It’s not the prettiest work, and it needs some more handling to make sure it doesn’t bomb out on bad values, but it does what I need!
                • 11055 ☆ A M B ☆
                • 3,112 Posts
                have you look at http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters ?
                there is a :math modifier if you like to try.
                  Rico
                  Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                  MODx is great, but knowing how to use it well makes it perfect!

                  www.virtudraft.com

                  Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                  Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                  Maintainter/contributor of Babel

                  Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                  • 11055 ☆ A M B ☆
                  • 3,112 Posts
                  Quote from: goldsky at Aug 16, 2010, 10:55 PM

                  I haven’t have time to debug the modX::getChildIds, but that method should be re-investigated again.

                  <?php
                      public function getChildIds($id= null, $depth= 10) {
                          $children= array ();
                          if ($id !== null && intval($depth) >= 1) {
                              $id= intval($id);
                              if (isset ($this->resourceMap["{$id}"])) {
                                  if ($children= $this->resourceMap["{$id}"]) {
                                      foreach ($children as $child) {
                                          $processDepth = $depth - 1;
                                          if ($c= $this->getChildIds($child, $processDepth)) {
                                              $children= array_merge($children, $c);
                                          }
                                      }
                                  }
                              }
                          }
                          return $children;
                      }
                  

                  $id= intval($id);
                  this makes $id to 0 (zero, in MODx’s tree case= ROOT).

                  Is this a bug or on purpose?
                    Rico
                    Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                    MODx is great, but knowing how to use it well makes it perfect!

                    www.virtudraft.com

                    Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                    Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                    Maintainter/contributor of Babel

                    Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                    • 28215
                    • 4,149 Posts
                    Can you file that as a bug here: http://bugs.modx.com/ and we’ll debug it? I think intval should be ok there, but if you get it in JIRA it will be easier to track.
                      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                      • 11055 ☆ A M B ☆
                      • 3,112 Posts
                        Rico
                        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                        MODx is great, but knowing how to use it well makes it perfect!

                        www.virtudraft.com

                        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                        Maintainter/contributor of Babel

                        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.