We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28883
    • 35 Posts
    migx is great!;) It's really been a lifesaver for me!

    I've just built a thumbnail gallery using migx, but in a rather unorthodox manner. I'm using the jQuery cycle plugin to page through the various thumbnails. In order to do this, I've had to group the thumbnails in batches of 5 images (i.e. slides of 5 thumbs).

    To my knowledge migx doesn't support what I'm doing - hence I've had to write my own hack to accomplish this. I'm basically reading the image urls out of the TV into an array, then iterating over the array and putting every set of 5 in a new div.

    My clients are of course uploading massive images so I'd like to use phpthumbof - which I can't with my solution...

    Does anyone have an thoughts on a better solution or an idea on how I can still use phpthumbof?

    Bit of a wild question, I know;)

    This question has been answered by supanick. See the first response.

      • 28883
      • 35 Posts
      Has anyone else tried something similar? I would have thought scrolling through sets of thumbs is quite common.

      Any thought or insight would be appreciated;)

      Thanks
        • 4172
        • 5,888 Posts
        you can use either some math-output-filters to create the divs arround, or you can try to use a wrapper-snippet like that(untested):

        <?php
        
        $tvname = $modx->getOption('tvname', $scriptProperties, '');
        $groupLimit = $modx->getOption('groupLimit', $scriptProperties, '0');
        $outputvalue = $modx->getOption('value', $scriptProperties, '');
        $docid = $modx->getOption('docid', $scriptProperties, (isset($modx->resource) ? $modx->resource->get('id') : 1));
        
        if (!empty($tvname)) {
            if ($tv = $modx->getObject('modTemplateVar', array('name' => $tvname))) {
                $outputvalue = empty($outputvalue) ? $tv->renderOutput($docid) : $outputvalue;
            }
        }
        
        $items = $modx->fromJSON($outputvalue);
        $output = array();
        $groupidx = 1;
        $count = 1;
        $total = count($items);
        foreach($items as $item){
            $item['_groupidx'] = $groupidx;
            $item['_groupopen'] = $groupidx==1? '1' : '0';
            $item['_groupclose'] = $count==$total ? '1' : '0';
                
            if (!empty($grouplimit) && $groupidx == $grouplimit){
                $item['_groupclose'] = '1';
                $groupidx = 0;
            }
            $output[]=$item;
            $groupidx++;
            $count++;
        }
        
        $properties = $scriptProperties;
        $properties['value'] = $modx->toJson($output);
        
        return $modx->runSnippet('getImageList',$properties);
        
        
        /*
        [[groupJson? &groupLimit=`5` &tvname=`myMigxTv` &tpl=`imageTpl`]]
        
        imageTpl:
        [[+_groupopen:is=`1`:then=`<div>`:else=``]]
        <img src="[[+image]]" />
        [[+_groupclose:is=`1`:then=`</div>`:else=``]]
        
        */
        


        another way would be to get the slide-groups by ajax and use getPage together with getImageList on the ajax-connector-resource

        [ed. note: Bruno17 last edited this post 11 years, 10 months ago.]
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 28883
          • 35 Posts
          Thanks Bruno, this is very helpful! I'll give it bash and feedback my results.
            • 28883
            • 35 Posts
            Hi Bruno,

            Just to say thanks again! It works beautifully! I've learned quite a bit more about modx and how everything stitches together (thanks for that).

            I needed to add a bit more logic which loads thumbs only if there is more than one image (used a snippet "wrapper"). I also needed another div wrapper for it all to work with my slideshow mechanism... It all works like a charm!

            Thanks again for your help!
            • discuss.answer
              • 28883
              • 35 Posts
              Just in case this might help someone...

              The code above didn't quite work - just made a couple of slight adjustments as seen below:

              <?php
              $tvname = $modx->getOption('tvname', $scriptProperties, '');
              $tvValue = $modx->getOption('value', $scriptProperties, '');
              $groupLimit = $modx->getOption('groupLimit', $scriptProperties, '');
              $docid = $modx->getOption('docid', $sciprtProperties, (isset($modx->resource) ? $modx->resource->get('id') : 1));
              
              if (!empty($tvname)) {
                  if ($tv = $modx->getObject('modTemplateVar', array('name' => $tvname))) {
                      $tvValue = empty($tvValue) ? $tv->renderOutput($docid) : $tvValue;
                  }
              }
              
              $images = $modx->fromJSON($tvValue);
              $output = array();
              $groupidx = 1;
              $count = 1;
              $total = count($images);
              
              foreach ($images as $image) {
                  $image['groupidx'] = $groupidx;
                  $image['groupopen'] = $groupidx==1 ? '1' : '0';
                  $image['groupclose'] = '0';
              
                  //groupclose value wasn't being set correctly - so this is where the main change is
                  if(!empty($groupLimit) && $groupidx == $groupLimit) {
                      $image['groupclose'] = '1';
                      $groupidx = '0';
                  } elseif ($count == $total) {
                      $image['groupclose'] = '1';
                  }
              
                  $output[] = $image;
                  $groupidx++;
                  $count++;
              }
              
              $properties = $scriptProperties;
              $properties['value'] = $modx->toJson($output);
              echo $modx->runSnippet('getImageList', $properties);
              
              ?>


              Thanks again to Bruno;) [ed. note: supanick last edited this post 11 years, 10 months ago.]
                • 4172
                • 5,888 Posts
                hmm... I can't see any functional differencies by looking to the code between

                $item['_groupclose'] = $count==$total ? '1' : '0';
                         
                    if (!empty($grouplimit) && $groupidx == $grouplimit){
                        $item['_groupclose'] = '1';
                        $groupidx = 0;
                    }


                and

                if(!empty($groupLimit) && $groupidx == $groupLimit) {
                        $image['groupclose'] = '1';
                        $groupidx = '0';
                    } elseif ($count == $total) {
                        $image['groupclose'] = '1';
                    }
                


                and you should always return snippet-results

                return $modx->runSnippet('getImageList', $properties);

                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 40045
                  • 534 Posts
                  Thanks guys, that thread pointed me to the right direction with a similar problem!

                  Scenario: I have a dynamic amount of checkboxes that should be grouped in a two column layout, but I don't know how many there will be, I just want to split them up in x columns as equally as possible (and not do it via javascript), so here is what I came up with, it's a modified version of the wrapper snippet posted before in this thread:

                  <?php
                  /**
                   * @description MODx MIGX getImageList wrapper snippet to allow grouping of output items (basically to make columns on the fly)
                   *
                   * @author exside
                   * @licence free beer or do whatever you like with it licence
                   * @credits
                   *         - Bruno Perner, the creator of the amazing MIGX addon
                   *         - http://forums.modx.com/thread/76778/migx---grouping-or-paging-results
                   *
                   * @compatibility Tested with MODx Revolution 2.2.6pl
                   * 
                   * @version 1.0.0pl
                   * @modified 06.04.2013
                   *
                   * @changelog
                   * - 1.0.0pl
                   *         - refactoring code from forum post
                   * 
                   * @todo
                   * 
                   * @param groups optional int The amount of groups that should be created from the migx grid items
                   * 
                   * @usage [[!getImageListGrouped? &tvname=`migx.tv.name` &groups=`2` &tpl=`chunk.name` &docid=`100`]]
                   * in your &tpl chunk you then will have the placeholders
                   * 		[[+groupidx]] = the group the item belongs to (int)
                   * 		[[+groupopen]] = equals 1 if the item is the first in it's group, usage like [[+groupopen:is=`1`:then=`<div class="wrapper">`:else=``]]
                   * 		[[+groupclose]] = equals 1 if the item is the last in it's group, usage like [[+groupclose:is=`1`:then=`</div>`:else=``]]
                   * 
                   * @package migx
                   **/
                  
                  // packageparams
                  $version = '1.0.0pl';
                  $packagename = 'getImageListGrouped';
                  
                  // enable debugging via &debug=`1` in the snippet params or directly by setting it to true here
                  if ( $debug = isset($debug) ? $debug : false ) { $modx->setLogLevel(modX::LOG_LEVEL_INFO); }
                  
                  // addon options/settings that can be set via snippet params and make them accessible with $settings['param']
                  $settings		=& $scriptProperties;
                  $docid			= isset($settings['docid']) ? $settings['docid'] : ( isset($modx->resource) ? $modx->resource->get('id') : 1 ); // Resource id
                  $tvname			= isset($settings['tvname']) ? $settings['tvname'] : ''; // name of the migx tv to read
                  $tvvalue		= isset($settings['value']) ? $settings['value'] : ''; // if a value is passed in the snippet params, take it
                  $groups			= isset($settings['groups']) ? $settings['groups'] : 1; // sets the amount of groups to create
                  
                  
                  if ( !empty($tvname) ) {
                  	if ( $tv = $modx->getObject('modTemplateVar', array('name' => $tvname)) ) {
                  		$tvvalue = empty($tvvalue) ? $tv->renderOutput($docid) : $tvvalue;
                  	} else {
                  		if ( $debug ) { $modx->log(modX::LOG_LEVEL_INFO, '[' . $packagename . '] The TV you specified could not be found: ' . $tvname); }
                  	}
                  }
                  
                  $items = $modx->fromJSON($tvvalue);
                  $output = array();
                  $groupidx = 1;
                  $groupcount = 1;
                  $totalcount = 1;
                  $totalitems = count($items);
                  $grouplimit = round($totalitems / $groups);
                  
                  foreach ($items as $item) {
                  	$item['groupidx'] = $groupidx;
                  	$item['groupopen'] = $groupcount == 1 ? '1' : '0';
                  	$item['groupclose'] = $groupcount == $grouplimit ? '1' : ( $totalcount == $totalitems ? '1' : '0' );
                  
                  	if ( $item['groupclose'] ) {
                  		++$groupidx;
                  		$groupcount = 1;
                  		++$totalcount;
                  	} else {
                  		++$groupcount;
                  		++$totalcount;
                  	}
                  
                  	$output[] = $item;
                  }
                  
                  $properties = $scriptProperties;
                  $properties['value'] = $modx->toJson($output);
                  
                  // disable debugging
                  if ( $debug ) { $modx->setLogLevel(modX::LOG_LEVEL_ERROR); }
                  
                  return $modx->runSnippet('getImageList', $properties);
                  
                  [ed. note: exside last edited this post 11 years ago.]
                    • 53082
                    • 1 Posts
                    Quote from: Bruno17 at Jun 13, 2012, 06:21 AM
                    hmm... I can't see any functional differencies by looking to the code between

                    $item['_groupclose'] = $count==$total ? '1' : '0';
                             
                        if (!empty($grouplimit) && $groupidx == $grouplimit){
                            $item['_groupclose'] = '1';
                            $groupidx = 0;
                        }

                    (...)

                    Just stumbled across this old post (thanks for this cool snippet!). Problem with your code is that you first used "$groupLimit" (notice the uppercase "L") and later used "$grouplimit". Therefore the grouping did not work properly. Just wanted to post this, in case anybody had the same problem.