We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    This code fails for me in Revolution:

    $this->allGroups = array ();  // Create an array of group names from the MODx db
                $tableName = $modx->getFullTableName('webgroup_names`);
                echo "Full Table Name: ".$tableName;  // I get the correct table name here
    
                $sql = "SELECT name FROM $tableName";
                if ($rs = $modx->db->query($sql)) {
                    while ($row = $modx->db->getRow($rs)) {
                        $this->allGroups[] = stripslashes($row['name']);
                    }
                } else {
                    echo "Query Failed\n"; // this is all I get
                    print_r($rs);   // prints nothing.
              
                }


    I haven’t been able to figure out how to make a Revolution version of this. I need an array of all the webgroup names. I guessed that $modx-getObject() might do it, but haven’t been able to find any docs that would tell me how to call it.
      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
      • 22303 MODX Staff
      • 10,725 Posts
      First of all, there is no webgroup_names table in Revolution. But if there were:

      if ($rs = $modx->query("SELECT name FROM {$modx->getTableName('modWebGroup')}")) {
          $allGroups= $rs->fetchAll(PDO_FETCH_COLUMN);
      }


      OR

      $webgroups= $modx->getCollection('modWebGroup');
      foreach ($webgroups as $group) {
          $allGroups[]= $group->get('name');
      }
        • 3749
        • 24,544 Posts
        Quote from: OpenGeek at Jul 24, 2008, 09:38 AM

        First of all, there is no webgroup_names table in Revolution. But if there were:

        Thanks. I meant to write membergroup_names
          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
          • 7923
          • 4,213 Posts
          Could someone move this thread to the Revolution subforums..


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 3749
            • 24,544 Posts
            Jason, I couldn’t get your code to execute either, but I found that my original worked once I corrected the obvious flaw in this line:

             $sql = "SELECT name FROM $tableName";


            to

             $sql = "SELECT name FROM ". $tableName;



            The first one worked in 0.9.6, so I guess Revolution has less tolerance for sloppy coding of queries. 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
              • 22303 MODX Staff
              • 10,725 Posts
              It won’t run cause it was theoretical, if web groups still existed. What you want is modUserGroup. Exchange modUserGroup in those queries below and you should get the information. The entire user system was consolidated, so the old table names are no longer valid and the classes for those old tables are there only to help in the migration process that will be added to upgrade installs from legacy MODx releases when we get to beta.

                • 3749
                • 24,544 Posts
                Quote from: OpenGeek at Jul 25, 2008, 12:51 PM

                It won’t run cause it was theoretical, if web groups still existed.  What you want is modUserGroup.  Exchange modUserGroup in those queries below and you should get the information.  The entire user system was consolidated, so the old table names are no longer valid and the classes for those old tables are there only to help in the migration process that will be added to upgrade installs from legacy MODx releases when we get to beta.

                I got that. I had assumed that your first example would run if I used ’membergroup_names’ since it exists and has the information I want.

                On second thought, maybe it would have if I had used getFullTableName() instead of getTableName().
                  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
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: BobRay at Jul 25, 2008, 02:07 PM

                  Quote from: OpenGeek at Jul 25, 2008, 12:51 PM

                  It won’t run cause it was theoretical, if web groups still existed. What you want is modUserGroup. Exchange modUserGroup in those queries below and you should get the information. The entire user system was consolidated, so the old table names are no longer valid and the classes for those old tables are there only to help in the migration process that will be added to upgrade installs from legacy MODx releases when we get to beta.

                  I got that. I had assumed that your first example would run if I used ’membergroup_names’ since it exists and has the information I want.

                  On second thought, maybe it would have if I had used getFullTableName() instead of getTableName().

                  getFullTableName is the deprecated legacy function (as is the entire DBAPI) -- you now want getTableName(), which is an xPDO function inherited by the modX class. And you refer to the name of the class to get the table name. Thus, modUserGroup, not membergroup_names.
                    • 3749
                    • 24,544 Posts
                    An itnteresting case of what we were recently discussing about add-ons.

                    I was able to make the enhanced extMemberCheck snippet work in both 0.9.6 and Revolution by just setting the $tableName with getFullTableName() based on the version (with either webgroup_names or membergroup_names) and using this code:

                                $sql = "SELECT name FROM ".$tableName;
                                if ($rs = $modx->db->query($sql)) {
                                    while ($row = $modx->db->getRow($rs)) {
                                        $this->allGroups[] = stripslashes($row['name']);
                                    }
                                } else {
                                    echo "Query Failed\n";
                                    return '';
                                }


                    It’s definitely not the "Revolution" way to do things and may come back to bite me later. I’m now trying to weigh that against the pain of maintaining two completely different versions of the same snippet.

                      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
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Couldn’t a snippet do a check on the version, and execute different functions depending on the version? Even break the functions out into two separate include files, and include the appropriate one?
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org