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
    But you say it works, as a chunk, when its in the wrapper.tpl?
      • 3749
      • 24,544 Posts
      Now i added, [[Discuss]] In the top and it loads everything fine.. ok a few things not but most.

      As I mentioned above, that tag is a placeholder tag (definitely not a System Setting). Some snippet has to set its value. When you add the Discuss tag above the placeholder, the Discuss snippet executes, and apparently sets the value of that placeholder.

      The things that don't work, probably don't work because Discuss assumes that it is running on a forum page, which in your case, it's not.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 37099
        • 338 Posts
        Quote from: BobRay at Jul 25, 2014, 03:40 AM
        I had another thought.

        You should be able to get the posts themselves with:

        $c = $modx->newQuery('disPost');
        $c->limit(20);
        $posts = $modx->getCollection('disPost', $c);


        You may have to load the discuss class first, but I don't think so.

        Once you have the posts, you should be able to do something like this:

        $output = '';
        foreach($posts as $post) {
            $url = $post->getUrl();
        
            $fields = $post->toArray();
            $fields['discuss.config.url'] = $url;
            $output .= $modx->getChunk('myTpl', $fields);
        }

        I tried this with and without loading the class file ( in a page where the discuss snippet is not called)

        if(file_exists('core/components/discuss/model/discuss/dispost.class.php')){
            
            if (!$modx->loadClass('disPost','core/components/discuss/model/discuss/',true,true)) {
            die('Could not load class disPost!');
        }
        }
        else {
            echo "Could not find class file<br>";
        }
        
        $c = $modx->newQuery('disPost');
        $c->limit(20);
        $posts = $modx->getCollection('disPost',$c);
        
        var_dump($posts);


        But it did not work, the file exists and the class loads ok but the output is NULL.

        When I add the debug code

        $c->prepare();
        print $c->toSQL();


        The $sql I get is: SELECT `` FROM AS `disPost` LIMIT 20

        Which is obviously not correct.


        Any ideas?

        Thanks
        Mike
          • 37099
          • 338 Posts
          Ok it turns out that I have to get the discuss service rather than load a class. (I looked in past posts and it has been talked about before)

          Then I can do something like this from a none discuss page:


          
          $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;
           
          $userId = $modx->user->id;
          $c = $modx->newQuery('disUser');
          $c->where(array('user' => $userId));
          
          $user = $modx->getObject('disUser', $c);
          
          $output = $user->get('name');
          
          $modx->setPlaceholder('output',$output);


          But if I replace $output = $user->get('name') with another disUser function


          $output = $user->countUnreadPosts();



          It doesn't work.

          Any ideas?

          Thanks
          Mike
            • 46886
            • 1,154 Posts
            This is clearly above my pay grade, but you might want to have a look at the tool I posted for recent posts. It gets the service and queries for threads or posts and then grabs user data too.

            While one user had trouble getting it to work, on my front page (where discuss is not called) it works perfectly.
              • 37099
              • 338 Posts
              Hi yes, thanks, I've looked at that, I thought maybe I need to add

              $package_path = $modx->getOption('core_path').'components/discuss/model/';
              $modx->addPackage('discuss', $package_path);
              


              So I did above my getService code, but it didn't help.

              What I'm confused about is that I can use one function

              $user->get('name');
              


              But not

              $user->countUnreadPosts();
              


              Which is the one I'm interested in and is there in disuser.class.php

              It *should* work but it doesn't

              ???

                • 37099
                • 338 Posts
                Quote from: nuan88 at Aug 04, 2014, 03:38 PM
                This is clearly above my pay grade, but you might want to have a look at the tool I posted for recent posts. It gets the service and queries for threads or posts and then grabs user data too.

                While one user had trouble getting it to work, on my front page (where discuss is not called) it works perfectly.

                I managed to get your snippets from http://forums.modx.com/thread/91207/popular-threads-and-featured-threads?page=4 to work. Thanks for those smiley

                But they are not what I'm after. They use the post info from disPost (the object associated with the table modx_discuss_posts), modUser, and disThread (the object associated with the table modx_discuss_threads)

                What I am after is using the function countUnreadPosts() of disUser (the object associated with the modx_discuss_users)

                I'm trying to show the user how many unread posts there are since they last logged on.

                You'd think that it just found posts that are older than the users last login. Which I can do just with my own query but that doesn't take into consideration private boards, and ignore boards options which is done in the existing Discuss code.

                I suppose I could recreate that too with my own query but that sort of defeats the object of reusable objects!
                  • 3749
                  • 24,544 Posts
                  When you call countUnreadPosts(), do you get an error, an empty value, or a 0?

                  You may also have to load the disThread class to get it to work, since countUnreadPosts() calls its fetchUnread() method.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 37099
                    • 338 Posts
                    Quote from: BobRay at Aug 05, 2014, 06:04 AM
                    When you call countUnreadPosts(), do you get an error, an empty value, or a 0?

                    You may also have to load the disThread class to get it to work, since countUnreadPosts() calls its fetchUnread() method.


                    Thanks Bob,

                    Progress, I added

                        if (!$modx->loadClass('disThread','core/components/discuss/model/discuss/',true,true)) {
                             die('Could not load class disThread!');
                        }
                    



                    I was getting an error, well just a blank screen but no errors in the error log.

                    With the class added, no error, but the function just returns 0 rather than the correct count of unread posts.

                    Maybe I need to load other classes.

                    Oh, now I do get an error:

                    disThread::fetchUnread() is not a valid static method.

                    I shall explore further....

                    Thanks
                    Mike [ed. note: thingstodo last edited this post 9 years, 9 months ago.]
                      • 3749
                      • 24,544 Posts
                      Here's something else to try (guessing wildly).

                      Instantiate a discussController and call these methods:

                      $controller->initialize();
                      $controller->discuss->setSessionPlace($sessionPlace);
                      $count = $controller->discuss->user->countUnreadPosts();
                      


                      I doubt if it will work.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting