We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25663 MODX Staff
    • 12,272 Posts
    Ah yes... Nice little bit that phpMyAdmin uses in fact or emulates at least I think... did that  just the other night when playing with SlimStats from wettone.com. Nice stuff that stats package.

    Danke Trav!
      Ryan Thrash, MODX Co-Founder
      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Wrote a module to include the manage_termbase.dynamic.action.php file and the mutate_termbase.dynamic.action.php files. Simple, really. I had originally hacked the menu frame (2.php? I forget exactly now) to provide the links, and the /manager/index.php file to include the files. Now the module code acts as the "switchboard" for the module. I mostly cut/pasted from the QuickEdit module for the general outline of a module.

      /*
       *  Written by: Susan Ottwell
       *  Contact: [email protected]
       *  Created: 10/11/2005
       *  For: MODx cms (modxcms.com)
       *  Name: Glossary
       *  Description: Manage termbase glossary 
       *  Parameters: &mod_path=Module Path (from site root);string;assets/modules/glossary
       *  Parameter sharing: not enabled
       *  Dependencies: none
       */
      
      /*
                                   License
      
      Glossary - A MODx module which allows the management of the termbase glossary in the database
      Copyright (C) 2005  Susan Ottwell
      
      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      (at your option) any later version.
      
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.
      
      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      
      */
      
      $basePath = $modx->config['base_path'];
      
      // If we cant't find the module files...
      if(!file_exists($basePath.$mod_path)) {
      
       // Log an error
       $error_message = '<strong>Glossary module not found!</strong></p><p>Edit the Glossary module, click the Configuration tab and change the Module Path to point to the module.</p>';
       $modx->Event->alert($error_message);
       $modx->logEvent(0, 3, $error_message, 'Glossary');
      
      } else {
        $GLOBALS['glossary_path'] = $mod_path;
        // include the language file
        include($basePath.$mod_path.'/langs/en.php');
        // if Browse or Search
        if(!empty($_POST) && isset($_POST['browse']) || isset($_POST['search'])) {
          include($basePath.$mod_path.'/mutate_termbase.dynamic.action.php');
        } else {
          include($basePath.$mod_path.'/manage_termbase.dynamic.action.php');
        }
      }
      
        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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Quote from: infoclipper at Nov 30, 2005, 11:59 PM

        Note that this won’t work on most hosted environments as they tend to not grant the LOAD DATA permission. If you run your own box, however, it’s trivial.

        Maybe that’s why I rolled my own...I’ve really forgotten a lot of the details. As they say in Texas, "I’ve slept since then!"
          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
          • 6726
          • 7,075 Posts
          Down to planet newbie here wink I have been fiddling with the DataGrid widget myself, with an @SELECT binding but I did not manage to have it work as I would have wanted to. My goal was to get information stored in my TVs, and display it in a table with the caption and value of the TVs.

          Problem is, the way TVs tables are built I have to retrieve information from 2 tables : modx_site_tmplvar_contentvalues to extract the values and modx_site_tmplvars to get the caption, and sort it by contentid.

          Of course it couldn’t work with datagrid. I started experimenting widgets and @bindings, to get a grasp on them. Most of them are rather straightforward and work as I expected them to, but I fail to understand properly the Datagrid widget. Remember the only thing I know about is bits of php, basics of SQL... I don’t even know if what I did makes sense (the way I go about learning is trial and error)

          The thing that I found interessting in Widgets and @bindings was to be able to offer non-savvy people ways to do complex things. Might be so, but as Ryan said examples will probably help smiley
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l&#39;outil id
            • 32963
            • 1,732 Posts
            Quote from: davidm at Dec 01, 2005, 03:37 AM

            The thing that I found interessting in Widgets and @bindings was to be able to offer non-savvy people ways to do complex things. Might be so, but as Ryan said examples will probably help smiley

            You’re correct David. We indeed need some examples of the DataGrid widget but that’s going to take some planing and time.

            Can you guys wait until TV2? The whole widgets thingy is being revised so it will be much easier to use.



              xWisdom
              www.xwisdomhtml.com
              The fear of the Lord is the beginning of wisdom:
              MODx Co-Founder - Create and do more with less.
              • 6726
              • 7,075 Posts
              Of course I can wait, there is still things I did not catchup with, TV2 was one of them (a rough estimate of when those will come out ?). It only makes senses to devote resources toward building TV2 rather than explaining TV1 if they are very different smiley

              If I do get my head around @bindings and widgets I’ll gladly help write some examples or doc about it.

              Quote from: Raymond
              You’re correct David. We indeed need some examples of the DataGrid widget but that’s going to take some planing and time.

              Can you guys wait until TV2? The whole widgets thingy is being revised so it will be much easier to use.




                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l&#39;outil id
                • 25663 MODX Staff
                • 12,272 Posts
                OK... Now I’m stuck again... with some assistance from Jason, here’s what I’ve got:

                the csv file located in assets/files/board.csv:
                DATE,EQ,FROM - ST,FROM CITY,TO CITY,TO ST
                10/17/05,FDT,AL,MONTEVALLO,PIGGOTT,AR
                10/20/05,FDT,AL,PINE APPLE ,PIGGOTT,AR
                10/18/05,S/D ONLY,CA,SAN DIEGO,CORTEZ,CO
                10/14/05,F,GA,MONROE,BATON ROUGE,LA
                10/18/05,FD,IL,CHICAGO,CARROLLTON,TX
                10/17/05,FD,IL,FRANKLIN PARK,MISHAWAKA,IN
                10/10/05,FD,IL,FRANKLIN PARK,PORTSMOUTH,OH


                The LoadBoard TV Default Content:
                @EVAL
                
                $CSVf = "assets/files/board.csv";
                
                if (file_exists($modx->config['base_path'].$CSVf)) { 
                   $csvlines = file($modx->config['base_path'].$CSVf); 
                } else 
                   return "Please wait while we update the load board file $modx->config['base_path'].$CSVf"; 
                 
                $lineNo= 1; 
                foreach ($csvlines as $line) { 
                   if ($lineNo==1) $csvKeys= explode(',', $line); 
                   else $csv = explode(',', $line); 
                   $lineNo++; 
                } 
                
                $csvResult = array(); 
                foreach($csvKeys as $indexnum => $key)
                   $csvResult[$key] = $csv[$indexnum];
                
                return $csvResult;


                The datagrid config for LoadBoard:
                Column Names: DATE,EQ,FROM - ST,FROM CITY,TO CITY,TO ST
                Field Names: DATE,EQ,FROM - ST,FROM CITY,TO CITY,TO ST
                Page Size: 5
                Pager Location: both-right
                Empty Message: No records found

                (and just noticed an extra empty row with a "0" in it at the bottom fo the config)

                "backup" CSV processing snippet code:
                $csvlines = file($modx->config['base_path'].'assets/files/base.csv'); } 
                
                $csvout = '<table border=1 cellspacing=0 cellpadding=3>';
                foreach ( $csvlines as $line ) 
                {
                  $csv=explode(',',$line); $line='<tr><td>'.implode('</td><td>',$csv).'</td></tr>';
                  $csvout=$csvout.$line;
                }
                return $csvout.'</table>';


                And the result:
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 25663 MODX Staff
                  • 12,272 Posts
                  BTW, if I increase the paging size to 50, the paging parts don’t render as expected. Therefore, I tend to think that maybe it’s not supposed to be an associative array after all, but as Jason mentioned the @SELECT dumps it into an associative array and seems to work...

                  hrm...
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 18397
                    • 3,250 Posts
                    Try using the raw code (not the API function).
                    I’ll send it to you when I get home. If you can’t wait a good example is the one on the modules page.
                      • 25663 MODX Staff
                      • 12,272 Posts
                      And finally got it to work thanks to Greg who used the über-hand PHP command fgetcsv:

                      @EVAL 
                      $handle = fopen("/server/path/to/file/htdocs/assets/files/board.csv", "r");
                      $row = 0;
                      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                         if($row) {
                         	$results[] = $data;
                         }
                         $row++;
                      }
                      fclose($handle);
                      return $results;


                      Works like a charm!
                        Ryan Thrash, MODX Co-Founder
                        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me