We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8790
    • 526 Posts
    Hi,

    I’m stuck with this :

    I have a TV wich represents a ’page number’, as this is a real book’s web adaptation.
    So each page actually contained into the real paper book have a tv to keep the paper page number reference.

    So, in some part of the site we have to recreate a linear navigation, but, of course, not directly based on [~id~] that could be not in the right sequence, but based from the tv that holds the page number.


    How can I get the ID of the MODx doc, Where tv_npage is equal to xx ?

    I’m quit sure I found sometime ago a snippet give the possibility to directly use SQL request..but did not found it again.
    May be there’s a very simple solution ?

    Thank you
      Schtroumpf Grognon - Grouchy Smurf
      ---------------------------------
      Faites pas attention.. - Don't pay attention
      http://www.dzi-neo.net
      • 37272
      • 216 Posts
      I’m not sure I entirely understand what you mean by a ’real book’s web application’ , but is this what you are looking for: http://modxcms.com/getField-667.html. This should allow you to return the contents of a TV.
        • 7231
        • 4,205 Posts
        I dont think that any snippet goes in that direction. The all use the doc ID as the source and not the template variable. The database table to query here is modx_site_tmplvar_contentvalues. This table make the relation between content, template variable is and the content id.
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don't know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 8790
          • 526 Posts
          Hi,

          Colin : The site I’m working on it, is the "portage" (transcription ?) of a paper book.

          Dev-cw: Yes we did it.
          I was really sad that basic snippet assembly cant do this, specific request without coding specific snippet is really missing in MODx.

          However a friend of mine did the job : may be could be added to the repo ?
          This one just does what I described, and is something likely : request ID from site_tmplvar_contentvalues WHERE tv_name equal XXX
          and adds a simple calculation with a parameter to add 1 (+1 or -1) to the ID, as we needed to create a lienar navigation.

          here it is GetDocId :

          <?php
          // snippet GetDocId retournant l'ID d'une page contenant la même TV avec une valeur décalée en + ou en - 
          // gives back a page ID WHERE one TV is EQUAL to xxx. Also, can manipulate the result: plus or minus 1
          // 2008 - Alain Castan for Eric Lacomblez, Nëo-tekk.com
          // usage : [[getDocId?tv_name=tvname]] 
          // usage : [[getDocId?tv_name=tvname&plus=1]] 
          // usage : [[getDocId?tv_name=tvname&plus=-1]] 
          
          if (!function_exists('getTvId')) {
            function getTvId($name){
                  global $modx;
                $table = $modx->getFullTableName("site_tmplvars");
                  $sql= "SELECT id from {$table} where name = '".$name."'";
                  //echo $sql;
                  $rs = $modx->db->query($sql);
                  if ($row= $modx->db->getRow($rs)){
                  return $row['id'];
                }else{
                  return $modx->documentObject['id'];
                } 
            }
          }
          if (!function_exists('getDocId')) {
            function getDocId($value,$name){
                $tvid= getTvId($name);
                if (!tvid) return null;
                global $modx;
                  $docids ="";
                $table = $modx->getFullTableName("site_tmplvar_contentvalues");
                  $sql= "SELECT contentid from {$table} where tmplvarid = ".$tvid." AND value = '".$value."'"
                ;
                  //echo $sql;
                  $rs = $modx->db->query($sql);
                if ($row= $modx->db->getRow($rs)){
                  return $row['contentid'];
                }else{
                  return $modx->documentObject['id'];
                } 
            }
          }
          //---------------------------------------------------------------------------
          
          $plus =(isset($plus))? $plus :0;
          $tv_name =(isset($tv_name))? $tv_name :"";
          
          $tv_value = $modx->getTemplateVarOutput($tv_name);
          $value =($tv_value[$tv_name] + $plus);
          
          return getDocId($value ,$tv_name);
          ?>


          Hope will be useful
            Schtroumpf Grognon - Grouchy Smurf
            ---------------------------------
            Faites pas attention.. - Don&#39;t pay attention
            http://www.dzi-neo.net