We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15921
    • 8 Posts
    I needed to list specific documents for ditto to process, and I wanted them in the order I listed them in the &documents parameter. Unfortunately, Ditto 2.1.0 only processes these documents in the order they are given back from the database. So here’s how to change that default. Someone could probably take this and make it a selectable option.

    In the ditto snippet code, change the following line

    $resource = array_values($resource);
    


    to

    $resource = array_values($resource);
    if($idType == "documents") {
    	$doc_ids = explode(",",$documents);
    	$new_resource = array();
    	$doc_order=array();
    
    	// map document id => sort order
    	for($x=0;$x<count($doc_ids);$x++) {
    		$doc_order[$doc_ids[$x]] = $x;
    	}
    	// put resource items into array in proper order
    	for($x=0;$x<count($resource);$x++) {
    		// put each document into the array in the right spot (determined by the $doc_order array)
    		$new_resource[ $doc_order[ $resource[$x]["id"] ] ] = $resource[$x];
    	}
    	// return the array in the correct order
    	$resource = $new_resource;
    }
    


    I hope someone finds this helpful.
      • 4172
      • 5,888 Posts
      or use this as ditto-extender:

      <?php
      
      if (!function_exists('customsort'))
      {
      function customsort($a, $b)
      {
      $pos_a=array_search($a['id'],$GLOBALS['documents']);
      $pos_b=array_search($b['id'],$GLOBALS['documents']);
      
      if ($pos_a == $pos_b)
      {
      return 0;
      }
      return ($pos_a < $pos_b)?-1:1;
      }
      }
      
      $GLOBALS['documents']=explode(',',$documents);
      $orderBy["custom"][] = array ("id", "customsort");
      $ditto->advSort = true;
      
      ?>
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 15921
        • 8 Posts
        I haven’t tried that, but it looks much more elegant and future-proof than my solution. Thanks!