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
    Hey quick update:

    I asked on stackoverflow and got some general feedback, here is the link http://stackoverflow.com/questions/24228302/modx-tool-to-access-proper-data-from-db:

    Take a look at the database model, if there is a field in another table that flags posts as private, you should be able to filter them out by using getCollectionGraph and another little parameter to your code.
    
    I'm not familiar with the database schema, so the following code will not work [it's not even related], but gives you an idea of what you should be looking for and how to join the related tables:
    
    if($queryFilters['status_id'] == '' ){$queryFilters['status_id'] = 2;} 
    
    $mygroups = $this->getGroupMemberships(); // an array of group ids
    
    $criteria = $this->modx->newQuery('FundRequest');
    
    $criteria->leftJoin('Program','Program');
    
    $criteria->where($queryFilters); // an array('id' => 2, 'uid' => 3) etc..
    
    $criteria->andCondition(array('Program.location_id:IN' => $mygroups));
    
    $criteria->sortby('`FundRequest`.`request_date`','desc');
    
    $fundRequests = $this->modx->getCollectionGraph('FundRequest', '{ "StatusFlag":{}, "PaymentMethod":{}, "Contract":{ "Client": {}, }, "Program": { "Location": {}, "ProgramName": {}, } }', $criteria);


    Still multiple issues. One example doesn't work while logged in, only while logged out. And another issue is it cant grab the author's username, only the ID number of the writer of the post.

    Slow now, but progress will come. smiley
      • 46886
      • 1,154 Posts
      Ok, and you had already seen this, right? I assume this tool could work very nicely. I need to track stats like clicks and page-views religiously.

      There is a plugin for pageviews, I will find the link and post it. That tool was just made last year, I think its called "Hits". Made by JP. But clicks I didn't research yet.

      http://random.markhamstra.com/modxstats/
        • 46220
        • 66 Posts
        I tried "Hits" and "HitPage" a few weeks ago and that didn't work for me then. However, now that I have a little bit more knowledge of things, I want to give it a go again.

        EDIT:
        So I have tried both again, and I think HitsPage would be best to use for me. I can get the amount of hits, now working on the output. I've tried http://www.sepiariver.ca/blog/modx-web/modx-popular-posts-plugin-hit-counter-getresources and not there yet as the output is not there yet, but I have to figure it out some more.

        I have a chunk:
        [[!getResources?
          &parents=`[[*id]]` 
          &limit=`5` 
          &tpl=`HitsPageTpl`
          &heading=`h5` 
          &sortbyTV=`HitsPage`
          &tvFilters=`HitsPage<<500` 
          &sortbyTVType=`integer`
        ]]


        A HitsPageTpl:
        [[+heading]]>[[+pagetitle]]</[[+heading]]


        And a call in the side bar:
        [[!Forumposts.Hits]]


        And a place where to get the numbers:
        <h4>This thread has been viewed [[!HitsPage?&saveTv=`true`]] times.</h4>


        As far as I can see, the last one works.... now for the sidebar to work smiley. [ed. note: gormytorysh last edited this post 9 years, 10 months ago.]
          • 46886
          • 1,154 Posts
          Ok I will give Hits a try, its newer and more official, so it would be a better (in my view) solution going forward. And looks like it can provide a list of more popular (by views of course) threads or posts?? That would be nice, obviously that's just what we want and need.

          Gotta look into clicks, any idea about it? I suspect the answer is google analytics...I noticed Discuss seems to track downloads of attachments and display the info on that page.

          Oh, this discussion def should not be kept here in the discuss section, Hits and Hitpage are both general tools. If we have troubles getting things to work at least.
            • 46220
            • 66 Posts
            You're right. Should open a discussion as they are both tools. Meanwhile, I have been working on mintnl's code and at least I know why it wont link correctly, now checking what piece of code makes it disappear from non-Discuss pages and what piece of code "breaks" the link.

            EDIT: I found some things though it does not make any sense to me yet.

            Changing the snippet from $modx->addPackage('discuss', $package_path); to $modx->getService('discuss', 'Discuss', $package_path); causes it to disappear from non-Discuss pages. Also changing $vraag->sortby('id','DESC'); to $vraag->sortby('replies','ASC'); causes this to happen.

            Also I noticed why links are not working correctly. When you use mintnl's original code, you see the link http://gc.haulehuisje.nl/forums/thread/3/test-popularity#dis-post-12, while in "our" popular link, it results in http://gc.haulehuisje.nl/forums/thread//test-popularity. See the number 3 in the first link and not in the second one? Somehow, the code will not make a correct [[+thread]] call. Not sure why.

            I also tried out Hits and Hitspage again and while I was working, I realized that both only show a sorted list based on views instead of posts, so not entirely something I want.

            And finally, the featured threads I can do manually for now and sort it when I have more knowledge of it all. Or someone made such a tool of course. [ed. note: gormytorysh last edited this post 9 years, 10 months ago.]
              • 46886
              • 1,154 Posts
              Right now, going from the front page, both links seem to be fine.

              Latest sends me right to the discussion, but Featured sends me to login, that must be mintnl's code I guess, as I remember that behavior.

              If you need checking let me know.

              Remember pls to do all checking from a different browser which is not logged in. [ed. note: nuan88 last edited this post 9 years, 10 months ago.]
                • 46220
                • 66 Posts
                The second link is not fine as it sends me to the main forum while it should send me to the topic. I have to check it from different browsers when it is working correctly in my "normal" browser (Modzilla).

                It still leaves my puzzled in this bit:
                Also I noticed why links are not working correctly. When you use mintnl's original code, you see the link http://gc.haulehuisje.nl/forums/thread/3/test-popularity#dis-post-12, while in "our" popular link, it results in http://gc.haulehuisje.nl/forums/thread//test-popularity. See the number 3 in the first link and not in the second one? Somehow, the code will not make a correct [[+thread]] call. Not sure why.
                  • 46220
                  • 66 Posts
                  I am close to the end of phase 1 I just have just one more issue and I hope someone has the solution.

                  If you look at http://gc.haulehuisje.nl/ one the sidebar, popular threads, it does not show anything. However, if you look at http://gc.haulehuisje.nl/forums/ it does show it there, though my [OL] is not working correctly and the link is not showing properly and therefor not working. Anyone that has a suggestion?

                  The code I used was taken from mintnl's latest post with some adjustments already provided by others.

                  The snippet I use:
                  <?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;


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


                  Chunk 2 (the call):
                  <h3>Popular Threads</h3>
                  <p>[[!Discuss.Popular]]</p>


                  It would help me greatly if someone has a solution as I have been trying to get it to work for almost a week now and no results.
                    • 46886
                    • 1,154 Posts
                    Pls take this line out, it might affect things:

                    $naam[0] = 'Anoniem';

                    That's mintnl's way to take his own posts out of the array.
                      • 46220
                      • 66 Posts
                      Done, but did not change anything.