We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46886
    • 1,154 Posts
    Hello:

    Dunnock kindly made a tool a long time ago to grab data from the Discuss component and provide it on other pages, however no one stepped up at that time to try it out and give feedback, so it never debugged and still doesn't work. :-(

    Its a very useful tool to make Discuss a viable forum solution, so I hope some people can jump in here and help us get this thing working, it would allow us to then make tons of db calls and grab all sorts of useful data. Just like MarkH did the other day with his new tool to grab forum data! That tool will help a lot of people (thanks Mark!), and this tool below will do even more.

    Dunnock's work is now nearly 1 year old, and the effort is wasted if we don't get this thing going? Could anyone back him up with some support pls? Thanks in advance all kind peoples!

    Here is the error: Fatal error: Call to undefined method xPDOQuery_mysql::orderby() in /var/www/gcmodx/core/cache/includes/elements/modsnippet/92.include.cache.php on line 13

    <?php
    $discuss = $modx->getService('discuss','Discuss',$modx->getOption('discuss.core_path',null,$modx->getOption('core_path').'components/discuss/').'model/discuss/');
    if (!($discuss instanceof Discuss)) return true;
      
    $c = $modx->newQuery('disPost');
    $c->where(array('private' => 0));
    $c->limit(10);
    $c->orderby('createdon', 'DESC');
      
    $posts = $modx->getCollection('disPost', $c);
      
    foreach ($posts as $post) {
        $temp = $post->toArray();
        $temp['url'] = $post->getUrl();
        // call chunks or what you want
        $out[] = $modx->getChunk('rowTpl', $temp);
    }
    return implode("\n", $out);

    This question has been answered by sottwell. See the first response.

    • discuss.answer
      • 28042 ☆ A M B ☆
      • 24,524 Posts
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 46886
        • 1,154 Posts
        Ok that stops the error, but now nothing is coming out at all. There is no output.

        I made a chunk called "rowTpl", but the code is not accessing it at all.
          • 4172
          • 5,888 Posts
          you can try to debug that script:

          <?php
          $discuss = $modx->getService('discuss','Discuss',$modx->getOption('discuss.core_path',null,$modx->getOption('core_path').'components/discuss/').'model/discuss/');
          if (!($discuss instanceof Discuss)) return true;
             
          $c = $modx->newQuery('disPost');
          $c->where(array('private' => 0));
          $c->limit(10);
          $c->sortby('createdon', 'DESC');
          
          //echo the generated sql
          $c->prepare();echo $c->toSql();
             
          if ($posts = $modx->getCollection('disPost', $c)){
              foreach ($posts as $post) {
                  $temp = $post->toArray();
             
                  // print the row-array
                  print_r($temp);
          
                  $temp['url'] = $post->getUrl();
                  // call chunks or what you want
                  $out[] = $modx->getChunk('rowTpl', $temp);
              }
              return implode("\n", $out);
          }
            
          return 'nothing was found'; 



          do you get anything?
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 46886
            • 1,154 Posts
            Wow good strategy, now gives me the following:

            SELECT `disPost`.`id` AS `disPost_id`, `disPost`.`board` AS `disPost_board`, `disPost`.`thread` AS `disPost_thread`, `disPost`.`parent` AS `disPost_parent`, `disPost`.`title` AS `disPost_title`, `disPost`.`message` AS `disPost_message`, `disPost`.`author` AS `disPost_author`, `disPost`.`createdon` AS `disPost_createdon`, `disPost`.`editedby` AS `disPost_editedby`, `disPost`.`editedon` AS `disPost_editedon`, `disPost`.`icon` AS `disPost_icon`, `disPost`.`allow_replies` AS `disPost_allow_replies`, `disPost`.`rank` AS `disPost_rank`, `disPost`.`ip` AS `disPost_ip`, `disPost`.`integrated_id` AS `disPost_integrated_id`, `disPost`.`depth` AS `disPost_depth`, `disPost`.`answer` AS `disPost_answer` FROM `modx_discuss_posts` AS `disPost` WHERE `disPost`.`private` = '0' ORDER BY createdon DESC LIMIT 10 nothing was found 
              • 46886
              • 1,154 Posts
              Ok, I just pulled out the $c->where(array('private' => 0)); term, and now I get results!

              However, when I am logged out I get the results, but when I am logged in I can't open that page, it must be an error because it throws me to the front page. But nothing in the logs.

              An additional issue is to keep private stuff private, this term was a problem as it seems to rule every post out. But it still will be necessary to limit access somehow. I notice in the db schema it doesn't seem to have a private flag for posts, only for threads...

              I want to make clear to anyone who tries this out, you have to have the template chunk and it has to tell what to put there, otherwise nothing will appear. That's me being obtuse yet again.
                • 46886
                • 1,154 Posts
                Hmm this seems quite problematic. Private isn't a flag in the post grouping, so we will need to take the threads first I guess and then sort according to private or not, then take the posts from that array and sort according to whatever terms we have.