<![CDATA[ Sorting TV done by ID not sorting number :( - My Forums]]> https://forums.modx.com/thread/?thread=45629 <![CDATA[Re: Sorting TV done by ID not sorting number :(]]> https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263944
]]>
virtualbear Jun 24, 2011, 08:23 AM https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263944
<![CDATA[Re: Sorting TV done by ID not sorting number :(]]> https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263943
Thank u very very much to look into this and explaining what was going on.]]>
fourroses666 Jun 24, 2011, 07:06 AM https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263943
<![CDATA[Re: Sorting TV done by ID not sorting number :(]]> https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263942 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]]>
virtualbear Jun 24, 2011, 06:25 AM https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263942
<![CDATA[Re: Sorting TV done by ID not sorting number :(]]> https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263941


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.]]>
fourroses666 Jun 24, 2011, 05:38 AM https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263941
<![CDATA[Re: Sorting TV done by ID not sorting number :(]]> https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263940
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]]>
virtualbear Jun 24, 2011, 04:46 AM https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263940
<![CDATA[Sorting TV done by ID not sorting number :(]]> https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263939 fourroses666 Jun 24, 2011, 04:07 AM https://forums.modx.com/thread/45629/sorting-tv-done-by-id-not-sorting-number#dis-post-263939