We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13667
    • 3 Posts
    there is a ticket(http://modxcms.com/bugs/task/14) for the "Default Tree Sort order"-issue, which is in state "implemented". but as much as i can see, in 0.9.5 and 0.9.6 this behavior isn’t implemented yet. did something gone wrong here?

    I’ve provided a possible solution here: http://modxcms.com/forums/index.php/topic,12542.msg95525.html#msg95525

    greets
    JayBee
      • 27376
      • 576 Posts
      You’re certainly right! Chances are good however that this will not make it in to 0.9.6.1 release. Jason or Ryan will have to make that decision.

      Here is a patch to make it a little easier to understand where the default sort order is set:
      Index: manager/frames/nodes.php
      ===================================================================
      --- manager/frames/nodes.php	(revision 2778)
      +++ manager/frames/nodes.php	(working copy)
      @@ -71,16 +71,16 @@
                   $spacer .= "     ";
               }
       
      -        // query other documents, set default sort order
      -        $orderby = "isfolder DESC";
      -        if(isset($_SESSION['tree_sortby']) && isset($_SESSION['tree_sortdir'])) {
      -            $orderby = $_SESSION['tree_sortby']." ".$_SESSION['tree_sortdir'];
      -        } else {
      -            $_SESSION['tree_sortby'] = 'isfolder';
      -            $_SESSION['tree_sortdir'] = 'DESC';
      -        }
      -        if($_SESSION['tree_sortby'] == 'isfolder') $orderby .= ", menuindex ASC, pagetitle";
      +	if (!isset($_SESSION['tree_sortby']) && !isset($_SESSION['tree_sortdir'])) {
      +		// This is the first startup, set default sort order
      +		$_SESSION['tree_sortby'] = 'isfolder';
      +		$_SESSION['tree_sortdir'] = 'DESC';
      +	} 
      +	$orderby = $_SESSION['tree_sortby']." ".$_SESSION['tree_sortdir'];
       
      +	// Folder sorting gets special setup ;)
      +	if($_SESSION['tree_sortby'] == 'isfolder') $orderby .= ", menuindex ASC, pagetitle";
      +
               $tblsc = $dbase.".`".$table_prefix."site_content`";
               $tbldg = $dbase.".`".$table_prefix."document_groups`";
               $tbldgn = $dbase.".`".$table_prefix."documentgroup_names`";
      I cleaned up some redundant code and tried to explain a little better where the default sorting is set. In later versions this patch will make it easier to customize.

      JayBee, your solution only works around the problem code by basically overriding ANY user defined sorting. The patch above tackles the specific point to where the default is set. Nothing has changed yet to the viewer but one could change the code:
      	// This is the first startup, set default sort order
      $_SESSION[’tree_sortby’] = ’isfolder’;
      $_SESSION[’tree_sortdir’] = ’DESC’;
      to this:
      	// This is the first startup, set default sort order
      $_SESSION[’tree_sortby’] = ’menuindex’;
      $_SESSION[’tree_sortdir’] = ’ASC’;
      Since this is a change to part of the core, you will of course need to log out and back in to the manager.

      Perhaps we should re-open that ticket since it really isn’t implemented yet smiley
        • 22303 MODX Staff
        • 10,725 Posts
        If someone gets it checked into the development branch, I’ll be glad to include it in the 0.9.6.1 release.
          • 25663 MODX Staff
          • 12,272 Posts
          Please do ... that’d be awesome. smiley
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 27376
            • 576 Posts
            DO change the sort order to menuindex? or DO commit my code cleanup patch huh

            or both?
              • 25663 MODX Staff
              • 12,272 Posts
              The sort order for sure. Cleanup after vetting/testing in multiple environments also makes a lot of sense.
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 27376
                • 576 Posts
                ------------------------------------------------------------------------
                r2780 | sirlancelot | 2007-06-08 09:57:02 -0700 (Fri, 08 Jun 2007) | 2 lines
                
                * [FS#14] Changed default sort order to 'menuindex ASC' ( http://modxcms.com/forums/index.php/topic,15549.0.html )
                
                Please test and report smiley
                  • 21257 MODX Staff
                  • 730 Posts
                  Is remembering the user’s sort choice in a cookie within the scope of this discussion? Tonight I went in just to change the default and ended up storing the user’s choice in a cookie just for fun. If anyone’s interested, I can post the code. It’s obviously not terribly difficult. But I did notice that there are a billion cookies used by the manager. I’m definitely going outside the scope of this thread now.. thinking that using fewer cookies via API might be a nicer solution in the manager. Thoughts?
                    Mike Schell
                    Lead Developer, MODX Cloud
                    Email: [email protected]
                    GitHub: https://github.com/netProphET/
                    Twitter: @mkschell
                    • 25663 MODX Staff
                    • 12,272 Posts
                    So there’s a billion now ... what’s a billion and one gonna hurt?

                    Please post away. smiley
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 21257 MODX Staff
                      • 730 Posts
                      manager/frames/nodes.php

                      This modification to manager/frames/nodes.php remembers the user’s tree sorting choice in a cookie.
                      It could be done with less code, but I wanted to use a mechanism that could potentially be expanded to remember other manager settings in the same cookie - mainly to reduce cookie bloat. Mmmm... cookie bloat.

                      Sorry, I’m not terribly "diff" friendly at the moment... the following code replaces the original lines 22 to 28:

                      	// setup sorting - cookies added by netProphET ([email protected])
                      	$bUpdateCookie = false;
                      	$aManagerCookie = array();
                      	if(isset($_COOKIE['modxmanagersettings'])) {
                      		parse_str($_COOKIE['modxmanagersettings'], $aManagerCookie);
                      	}
                      	if(isset($_REQUEST['tree_sortby'])) {
                      		$_SESSION['tree_sortby'] = $_REQUEST['tree_sortby'];
                      		$aManagerCookie['tree_sortby'] = $_REQUEST['tree_sortby'];
                      		$bUpdateCookie = true;
                      	} elseif (isset($aManagerCookie['tree_sortby'])) {
                      		$_SESSION['tree_sortby'] = $aManagerCookie['tree_sortby'];
                      	}
                      	if(isset($_REQUEST['tree_sortdir'])) {
                      		$_SESSION['tree_sortdir'] = $_REQUEST['tree_sortdir'];
                      		$aManagerCookie['tree_sortdir'] = $_REQUEST['tree_sortdir'];
                      		$bUpdateCookie = true;
                      	} elseif(isset($aManagerCookie['tree_sortdir'])) {
                      		$_SESSION['tree_sortdir'] = $aManagerCookie['tree_sortdir'];
                      	}
                      	if($bUpdateCookie) {
                      		$strCookie = '';
                      		foreach($aManagerCookie as $k=>$v) {
                      			$strCookie .= "&{$k}={$v}";
                      		}
                      		if(strlen($strCookie) > 1) $strCookie = substr($strCookie, 1);
                      		setcookie('modxmanagersettings', $strCookie, time()+(3600*24*45));//45 days
                      	}
                      	unset($bUpdateCookie, $aManagerCookie, $strCookie);
                      
                        Mike Schell
                        Lead Developer, MODX Cloud
                        Email: [email protected]
                        GitHub: https://github.com/netProphET/
                        Twitter: @mkschell