We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46220
    • 66 Posts
    Quote from: nuan88 at Jun 12, 2014, 11:25 AM
    Also notice Petri's code used orderby while mintnl's uses sortby, wonder if that's the problem with Petri's, as both requests are basically the same.

    Just changing that does not result in an overall error. It also does not give the right outcome though. Going to try a few things and will report back later.

    This is the result:
    [2014-06-12 14:50:48] (ERROR @ /index.php) Error 42S22 executing statement: Array ( [0] => 42S22 [1] => 1054 [2] => Unknown column 'disPost.private' in 'where clause' ) [2014-06-12 14:50:48] (ERROR @ /var/www/gcmodx/core/cache/includes/elements/modsnippet/94.include.cache.php : 23) PHP warning: implode(): Invalid arguments passed

    EDIT:
    Changed Petri's bit even further, the error is gone.... but so is all information.

    <?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());
    $c->limit(6,0);
    $c->sortby('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);


    Changed $c->where(array('private' => 0)); into $c->where(array());. So getting closer (or further away) to our goal. [ed. note: gormytorysh last edited this post 9 years, 11 months ago.]
      • 46886
      • 1,154 Posts
      Oh you are getting close. But why adopt Petri's opening statement? Why not work from mintnl's working code rather than the mystery of the other?

      In my view, the working structure is fine to give us a lot of results. I don't see a huge difference between the two. Why fight a command like "implode" when we have a working sample that only needs work to detail the different db searches we want?

      There may be an overall advantage to Petri's code, but I don't see it now.
        • 46886
        • 1,154 Posts
        Its all about grabbing the db in the right way, the right part, (Discuss threads or posts or users or whatever) and then defining the precise search we want to do. Top total pages views or replies or most recent or...
          • 46220
          • 66 Posts
          It's not so much adopting anyone's idea over another, but more trying to see the similarities and differences to learn more about PHP.
            • 46886
            • 1,154 Posts
            No you are right, I wasn't thinking, its exploring and trying out different things.

            I think I will put the code which doesn't work into the Revo support section or maybe general section, maybe we can get more feedback there.

            Cheers, you are doing a great job!
              • 46886
              • 1,154 Posts
              I noticed your popular threads actually works inside the forums, but not on the front page. I can't check other sections right now, but it could be you are not getting the discuss service properly, that's why the front page can't get the data.

              At first I thought it was a tool to grab the popular posts within one area, like if you were in Best Builds it would give you the top posts *within that category*, which would be really cool and is something I hadn't thought about.

              Ha but I kind of doubt that. Probably its not grabbing the service properly.

              I like your solution of popping discuss into a bigger platform, that solves a lot of problems quickly.
                • 46886
                • 1,154 Posts
                Ok I posted in Revo support, that looked like the hottest forum to get this in front of a lot of eyeballs.

                If you have updated info (such that the orderby/sortby change stops the error), pls feel free to jump in.

                http://forums.modx.com/thread/91475/php-tool-to-access-data-in-component---fatal-error
                  • 46886
                  • 1,154 Posts
                  Ok that's interesting, the sortby and orderby issue was important, but more important is that the problem with Petri's tool is just the private=0 order, which leads to no results. Take that out, and the results are right there and are correct.

                  I have another important issue but will wait and put that into another post, as its different.
                    • 46220
                    • 66 Posts
                    Quote from: nuan88 at Jun 14, 2014, 11:13 AM
                    No you are right, I wasn't thinking, its exploring and trying out different things.
                    I think I will put the code which doesn't work into the Revo support section or maybe general section, maybe we can get more feedback there.
                    Cheers, you are doing a great job!

                    No problem, we’re in a learning curve wink. Good thinking in putting it there and as it seems there is more response there. Thanks and same to you!

                    Quote from: nuan88 at Jun 14, 2014, 11:13 AM
                    I noticed your popular threads actually works inside the forums, but not on the front page. I can't check other sections right now, but it could be you are not getting the discuss service properly, that's why the front page can't get the data.

                    At first I thought it was a tool to grab the popular posts within one area, like if you were in Best Builds it would give you the top posts *within that category*, which would be really cool and is something I hadn't thought about.

                    Ha but I kind of doubt that. Probably its not grabbing the service properly.

                    If it was only that simple. I’ve tried a couple of things but that mainly resulted in errors or not displaying things. So have to dig into it deeper to be able to obtain the correct data properly.

                    Quote from: nuan88 at Jun 14, 2014, 11:13 AM
                    I like your solution of popping discuss into a bigger platform, that solves a lot of problems quickly.

                    Thanks and to be honest, I have been struggling what would suit me best. Could be I will change some things around and use a more blog-like section for some parts of the website and members can post comments.

                    Quote from: nuan88 at Jun 14, 2014, 11:13 AM
                    Ok I posted in Revo support, that looked like the hottest forum to get this in front of a lot of eyeballs.

                    I noticed and good thinking. The forum is so big, that I assume not many take the time (or effort) to scroll down that much wink.

                    Quote from: nuan88 at Jun 14, 2014, 11:13 AM
                    Ok that's interesting, the sortby and orderby issue was important, but more important is that the problem with Petri's tool is just the private=0 order, which leads to no results. Take that out, and the results are right there and are correct.

                    I have another important issue but will wait and put that into another post, as its different.

                    But there are other issue’s as well as I understand from your last post in the main forum. Haven’t checked it out in detail, but will get to that later.
                      • 46220
                      • 66 Posts
                      Quote from: gormytorysh at Jun 02, 2014, 02:50 PM

                      I actually have 2 questions for now (see gc.haulehuisje.nl for visual support):

                      1. is it possible to get the most popular threads into the sidebar?
                      2. is it possible to mark threads as featured (and remove it when I want), and show into the sidebar?

                      Just looking at my first post, number 1 is partially solved and number 2 hasen't been answered yet (so I wonder why this thread is labeled answered wink ). To break down the issues in number 1:


                      • The output is shown in the forums page in the sidebar, but not on any non-forum page.
                      • When you click on one of the listed items, nothing happens, so there must be an error somewhere in the coding.
                      • It should be a top 5 and they are all labeled is 1. So I tried things in my CSS and looked at the code generated and as far as I can see, it is creating a new ordered list for every item in the output. So could this be in the code?

                      Just to support the above, here's the things I have right now:

                      The snippet:
                      <?php
                      $weghalen = array(",", "/", "?", "<", ">", ";", ":", "[", "]", "{", "}", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "=");
                      $vervangen = array(" ", ".");
                       
                      $c = $modx->newQuery('modUser');
                      $c->leftJoin('modUserProfile','Profile');
                      $c->sortby('id','ASC');
                      // add column names that u want to show
                      $c->select(array(
                          'modUser.*',
                          'Profile.fullname',
                          'Profile.email',
                      ));
                        
                      $users = $modx->getCollection("modUser",$c);
                      $naam[0] = 'Anoniem';
                      foreach($users as $user){
                          $usr = $user->toArray();
                       
                      $naam[$usr['id']] = $usr['username'];
                      $email[$usr['id']] = $usr['email'];
                      }
                       
                      $tpl = $modx->getOption('tpl',$scriptProperties,'Forumthreads.Popular');
                       
                      $package_path = $modx->getOption('core_path').'components/discuss/model/';
                      $modx->getService('discuss', 'Discuss', $package_path);
                      $vraag = $modx->newQuery('disThread');
                      $vraag->sortby('replies','DESC');
                      $vraag->where(array(
                      ));
                      $vraag->limit(5,0);
                       
                      $regels = $modx->getCollection('disThread',$vraag);
                      $output = '';
                       
                      foreach($regels as $regel){
                      $rglArray['post']= $regel->get('id');
                      $rglArray['thread']= $regel->get('thread');
                      $titel = strtolower($regel->get('title'));
                      if(substr($titel, 0,4)=="re: "){$titel = substr($titel,4);}
                      $titel= str_replace($vervangen, "-", str_replace($weghalen, "", $titel));
                      if(substr($titel,-1)=="-"){$titel = substr($titel,0,-1);}
                      $rglArray['threadname'] = $titel;
                      //$rglArray['threadname'] = $titel2;
                      $rglArray['title']= $regel->get('title');
                      $rglArray['message']= $regel->get('message');
                      $rglArray['author'] = $naam[$regel->get('author')];
                      $rglArray['createdon']= $regel->get('createdon');
                      $rglArray['gravatar'] = "http://www.gravatar.com/avatar/".md5(strtolower(trim($email[$regel->get('author')])))."?d=mm&s=50";
                      $rglArray['email'] = $email[$regel->get('author')];
                      $rglArray['nummer'] =$nummer;
                       
                      $output .= $modx->getChunk($tpl,$rglArray);
                      }
                      return $output;


                      The 1st chunck:
                      <div id="side-top ol">
                      <div id="side-top ol li">
                      <ol>
                      <li> 
                      <h5><a href="/forums/thread/[[+thread]]/[[+threadname]]#dis-post-[[+post]]">[[+title]]</a></h5>
                      <p style='margin-top:-15px'>[[+message:strip:stripTags:ellipsis=`50`]]</p>
                                          <div class="clear"></div>
                      </li>
                      </ol>
                      </div>
                      </div>


                      The 2nd chunk:
                      <h3>Popular Threads</h3>
                      <p>[[!Discuss.Popular]]</p>


                      And finally the CSS bit:
                      #side-top ol {padding:0 0 0 40px;list-style-type: decimal;border-bottom:1px solid #313030}
                      #side-top ol li {color: #fff;}
                      #side-top ol li a {color: #B0B0B0}


                      Any pointers would be again most welcome!!