We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9995
    • 1,613 Posts
    How can I chance the sortingorder done by sorting number and not the ID?
      Evolution user, I like the back-end speed and simplicity smiley
      • 36404
      • 307 Posts
      hi,

      euh, i must say that i do not understand exactly what you mean by sorting tvs with yams... the only thing i can say for the moment is that YAMS "says" that custom tvs (for YAMS, it means all your tvs except for those it "knows" natively as longtitle, content, description and so on) are expected to be displayed in the manager in a not really... managed order smiley

      - from YAMS yams.mm_rules.inc.php source code
      // Loop over the multilingual tvs and sort into custom and standard.
      // The standard ones are ordered in the normal order.
      // The custom ones are ordered as is (by probably should respect the
      // tv order specified in the database...)
      // For each tv, calculate the name required by ManagerManager

      is it what you’re speaking about ? if yes, you’ll have to hack YAMS mm_rules a little to have them displayed in a specific order

      have swing
        réfléchir avant d'agir
        • 9995
        • 1,613 Posts
        ##EDIT###hmm i dont get it, now i have set all sort order number the same as the id of the tv and its ok again.##



        Well, i’d like to have an sort order on my custom TV’s.

        When i set sort order (sorteer volgorde) nothing happens. (attachment 1)
        When i look at the order on my page i thought it sorts on ID number of the TV, but this doesn’t do that aswell..
        So i wonder how does it sort?

        If it sorts on ID then it has to be (see attachment 2) in order of 22, 23, 24 etc.

        I want to sort these TV’s somehow, i can’t figur out how it sorts at the moment.
          Evolution user, I like the back-end speed and simplicity smiley
          • 36404
          • 307 Posts
          yes,
          that’s what i suggested above, according to the comment, it may be a bit randomly... actually, not that random if i have a look at one of my pages with a lot of tvs, they seem to be in an alpha order... but i haven’t set any rank...
          now for what i can see in yams source
                // Get the names and ids of all the multilingual template variables
                // ending in _{langid}
                $result = $modx->db->select(
                  'id,name,rank'
                  , $modx->getFullTableName('site_tmplvars')
                  , 'name LIKE \'%\_' . $modx->db->escape( $langId ) . '\''
                  );
                $nRows = $modx->db->getRecordCount( $result );
                
                // Loop over the multilingual tvs and sort into custom and standard.
                // The standard ones are ordered in the normal order.
                // The custom ones are ordered as is (by probably should respect the
                // tv order specified in the database...)
                // For each tv, calculate the name required by ManagerManager
                $standardTVs = array();
                $customTVs = array();
                for ( $i = 0; $i < $nRows; $i++ )
                {
                  $idNameArray = $modx->db->getRow( $result );
                  $name = $idNameArray['name'];
                  $id = $idNameArray['id'];
                  $rank = intval( $idNameArray['rank'] );
                  switch ( $name )
                  {
                    case 'pagetitle_' . $langId:
                      $standardTVs['1'] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
                      break;
                    case 'longtitle_' . $langId:
                      $standardTVs['2'] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
                      break;
                    case 'description_' . $langId:
                      $standardTVs['3'] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
                      break;
                    case 'alias_' . $langId:
                      if ( $useMultilingualAliases )
                      {
                        $standardTVs['4'] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
                      }
                      break;
                    case 'introtext_' . $langId:
                      $standardTVs['5'] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
                      break;
                    case 'menutitle_' . $langId:
                      $standardTVs['6'] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
                      break;
                    case 'content_' . $langId:
                      $standardTVs['7'] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
                      break;
                    default:
                      if ( array_key_exists( $rank, $customTVs) )
                      {
                        $customTVs[] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
                      }
                      else
                      {
                        $customTVs[$rank] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
                      }
                  }
                }
                // sort the standard tvs
                ksort( $standardTVs );
                ksort( $customTVs );
          
                $nStandardTVs = count( $standardTVs );
                $nCustomTVs = count( $customTVs );

          and, a little further

          as you can see, yams retreives id, name and rank for a tv and, later, tries to order them by rank, but if the rank already exists, will put the tv in the array as it comes...
          if ( array_key_exists( $rank, $customTVs) )
          {
            $customTVs[] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
          }
          else
          {
              $customTVs[$rank] = YAMSTVDataToMMName( $name, $id, 'tv', $mm_version );
          }

          that means that if you want your tvs to be ordered by rank, you may try to start with a rank higher than YAMS and MODx "native" tv higher one (well, let’s say, try starting ordering your tv with 20 or so, it should avoid your tvs falling into the
          if ( array_key_exists( $rank, $customTVs) )
          condition

          hope it helps

          Have swing
            réfléchir avant d'agir
            • 9995
            • 1,613 Posts
            Well it looks like indeed i need to put the Rank (didn’t know it was named so in English) pritty high to get a correct rank/sort order. I gave the TV’s rank 100 and above and it looks like this is working.

            Thank u very very much to look into this and explaining what was going on.
              Evolution user, I like the back-end speed and simplicity smiley
              • 36404
              • 307 Posts
              my pleasure smiley
                réfléchir avant d'agir