We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30884
    • 142 Posts
    Hi there,
    I’m using a ditto call to list all my news items and show their appearance ranking tv values but I need to get an array which exists outside of the ditto call so I can then tell it to alter the sorting order by updating the ranking TV on the articles.

    The ditto call is:
    [!Ditto? &startID=`2,25` &summarize=`50` &sortBy=`ArticleRating` &sortDir=`DESC` &tpl=`Home_Page_Image_Rank_01` &debug=`1` !]
    


    eg: snippet call in the chunk is :
    [[rating_list? &pageid=`[+id+]`]]
    


    and the rating_list snippet is this:

    <?php
    //$article_count=0;
    global $modx;
    global $sort_list;
    global $article_count;
    //$ditto_sort = int;
    $gti_page_id= isset($pageid) ? $pageid : $modx->documentIdentifier;
    $rating = "[+ArticleRating+]";
    $page_id = $gti_page_id;
    $rating= $modx->getTemplateVar('ArticleRating', "", $page_id);
    echo"<br>ID:".$page_id." Rating:".$rating[value]."<br>";
    /*
    $ditto_sort_array = $modx->getPlaceholder('ditto_sort');
    echo "<pre>***";
    print_r($ditto_sort_array);
    echo "***</pre>";
    */
    //$previous_entry="[+rating_above+]";
    $ditto_sort = "[+ditto_sort+]";
    $sort_list[$ditto_sort][id]=$page_id;
    $sort_list[$ditto_sort][rating]=$rating[value];
    $modx->setPlaceholder('rating_number',"<br>PageID:".$ditto_sort."-".$sort_list[$ditto_sort][id]."-".$sort_list[$ditto_sort][rating]);
    echo "<PRE>";
    print_r($sort_list);
    echo "END";
    echo "</PRE>";
    ?>


    I’m wanting to have the array in the form of:

    Array
    (
        [0] => Array
            (
                [id] => 565
                [rating] => 991170288001
            )
    
        [1] => Array
            (
                [id] => 452
                [rating] => 991170288000
            )
    
        [2] => Array
            (
                [id] => 644
                [rating] => 991170287999
    }
    


    To use in another php snippet which then looks up the array and makes the adjustments depending on which article link with the &moveup=644 (for eg) var being passed to it.

    Where the array key id is the var from the ditto_sort placeholder.

    The chunk only let’s the array exist in it’s one instance and it doesn’t let me use it outside of that chunk which is driving me slowly mad.

    Any help/pointing out the clearly obvious most welcome!!

    Many thanks

    Jamie
      p i x e l p u s h e r e x t r o d i n a i r e
      A x i s A n i m a t i o n . c o m
      • 30884
      • 142 Posts
      Hi there,

      I ditched using Ditto and cobbled together a script to do what I wanted. The text TV ArticleRating is needed to run this. ArticleRating is a reversed date (20080129 for eg) and it’s got a pre-fix of either 9 or 1 to dictate if it’s a higher ranked article on the front page or not.

      Not the tidiest of solutions and I must get into the habit of being more modular. As you can see I’ve echo’d out the results till I get creating placeholders. At least now I’ll be able to alter the ranking since I’ve got an intact array with loads of lovely data to work with! laugh

      Any comments/feedback/pointing out the problems most welcome!
      Cheers

      Jamie


      Snippet call
      [!axis_article_ranking? &folder=`2,25`!]
      


      Snippet code
      <?php
      global $modx;
      $AXIS_SYSTEM_PATH = "assets/snippets/AxisCustom/";
      include($modx->config['base_path'].$AXIS_SYSTEM_PATH.'axis_article_ranking.php');
      ?>
      


      Snippet include file:
      <?php
      
      /**
       * @author Jamie Murray
       * @copyright 2008
       * This script gets and writes out all the articles and their ratings into
       * an array called $complete_list.
       * Pass the folders in the snippet by using 
       * [!axis_article_ranking? &folder=`2,25`!] 
       * for example.     
       */
      
      global $child_pages;
      global $modx;
      global $complete_list;
      $complete_list = array();
      $child_pages = array();
      $folders = isset($folder) ? $folder : '25,2';
      $containers = explode(",", $folders);
      
      foreach ($containers as $v) {
          list_child_placeholder($v, $v, "");
          //echo "[+" . $v . "+]";
      }
      
      usort($complete_list, "cmp_rating");
      $counted = 0;
      while ($complete_list[$counted][pagetitle] <> "") {
          $art_id = $complete_list[$counted][id];
          $pub_check = $modx->getPageInfo($art_id, '', 'published');
          if ($pub_check[published] == 1) {
              echo '<li><h3 style="color: #d4cec5;">' . $complete_list[$counted][pagetitle] .
                  '<a href="index.php?id=832&moveup=[+id+]&sortid=[+ditto_sort+]&ratingabove=[+rating_above+]">^^</a></h3>';
              $modx->setPlaceholder('art_id', $id);
              echo '<div>[[Axis_Home_News_Mini_Thumb? &id=`' . $complete_list[$counted][id] .
                  '` ]]</div>';
              $intro_text = $modx->getPageInfo($art_id, '', 'introtext');
              echo '<p style="color: #433c32;">' . $intro_text[introtext] . '</p></li>';
              $counted++;
          } else {
              $counted++;
          }
      }
      
      
      function list_child_placeholder($parent_id, $placeholder_name, $not_first_list)
      {
          global $modx;
          global $child_pages;
          global $complete_list;
          $complete_list = $child_pages;
          $start_page = $parent_id;
          $depth = 0;
          $parent_title = $modx->getPageinfo($parent_id, 1, 'pagetitle');
          $child_pages = $modx->getAllChildren($start_page);
          $count = 0;
         // This adds the array item 'article_rating' to the end of the get child array
          while ($child_pages[$count][pagetitle] <> "") {
              $id = $child_pages[$count][id];
              //$pub_check = $modx->getPageInfo($id, '', 'published');
              $article_rating = $modx->getTemplateVar('ArticleRating', "*", $id);
              $child_pages[$count][article_rating] = $article_rating[value];
              $count++;
          }
          //merge array with previous function results.
          $complete_list = array_merge($complete_list, $child_pages);
          return $complete_list;
      }
      
      // SORT ARRAY FUNCTION
      
      function cmp_rating($b, $a)
      {
          return strcmp($a[article_rating], $b[article_rating]);
      }
      
      
      ?>
      
        p i x e l p u s h e r e x t r o d i n a i r e
        A x i s A n i m a t i o n . c o m