Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

number of pages in discussion list

jackmaessenjackmaessen ✭✭✭
edited January 2014 in Vanilla 2.0 - 2.8

Another question from me: is there an easy way to set the number of pages in the discussion list?
So that you can see immediatley how many pages a discussion contains? Let's say: based on the settings of 20 posts max each page.

Something like the screenshot below:

Tagged:

Comments

  • peregrineperegrine MVP
    edited January 2014

    pick the event to post in that position. divide the

           N pages = 
           number of comments (countcomments in discussion table) per discussion   divided by      
            your comments per page (read from config.php).   
    

    Depending on your version of vanilla the event to trigger on pick may different.
    I suggest you ALWAYS post your numerical version of vanilla you are talking about when asking a question

    should be easy for you to create a plugin for this.

    although I question its importance. number of comments seems more valuable information.

        $cperpage  = C('Vanilla.Comments.PerPage', 20);
        $ccount = $Discussion->CountComments;
        $pagesperdiscussion = round($ccount/$cperpage);
        echo T("Pages:") . $pagesperdiscussion;
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Sorry peregrine, it is 2.0.18.9 ( i have to update one of these days, i know)

  • peregrineperegrine MVP
    edited January 2014
    public function DiscussionsController_DiscussionMeta_Handler($Sender) {
        $Discussion = $Sender->EventArguments['Discussion'];     
        echo T("Pages: ") . $Discussion->CountPages;
    }
    
    or
    
    public function DiscussionsController_DiscussionMeta_Handler($Sender) {
       $cperpage  = C('Vanilla.Comments.PerPage', 20);
        $ccount = $Discussion->CountComments;
        $pagesperdiscussion = ceil($ccount/$cperpage);
        echo T("Pages: ") . $pagesperdiscussion;
    }
    
    or trigger on this
    
    public function DiscussionsController_AfterCountMeta_Handler($Sender) {
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited January 2014

    @jackmaessen said:
    Sorry peregrine, it is 2.0.18.9 ( i have to update one of these days, i know)

    not to put the scare factor in you: but complacency could result in this:

    http://vanillaforums.org/discussion/25860/infected-forum-trojan-js-blacole-gen#latest

    and removal of the exploit doesn't necessarily mean private info (email addresses etc have NOT already been seen by hacker)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • jackmaessenjackmaessen ✭✭✭
    edited January 2014

    well, i tried to make a plugin with the code of peregrine, but he doesn't count; it is all 0

    I made this based on another plugin:

    <?php
    // Define the plugin:
    $PluginInfo['NumberOfPages'] = array(
       'Description' => 'Shows number of pages in discussionlist',
       'Version' => '1.0',
       'Author' => "jackmaessen",
       'Support' => "peregrine",
       'AuthorEmail' => 'admin@webprofis.nl',
       'AuthorUrl' => 'http://www.webprofis.nl'
    );
    
    
    class NumberOfPages implements Gdn_IPlugin {
    
       public function DiscussionsController_DiscussionMeta_Handler($Sender) {
       $cperpage  = C('Vanilla.Comments.PerPage', 20); // 20 comments per page
        $ccount = $Discussion->CountComments;
        $pagesperdiscussion = ceil($ccount/$cperpage);
        echo '<div class="Meta">' . T("Pagina's: ") . $pagesperdiscussion . '</div>';
    
       }
    
       public function Setup() {
          //no setup needed
       }
    
    }
    

    The echo line should be this: echo 'div class="Meta"' . T("Pagina's: ") . $pagesperdiscussion . '/div';

  • peregrineperegrine MVP
    edited January 2014

    thanks again!

    and you don't need this 'Support' => "peregrine", :)

    here are some changes.

    // you can change to this 
    class NumberOfPages extends Gdn_Plugin {
    
    public function DiscussionsController_DiscussionMeta_Handler($Sender) {
         // add line below  
         $Discussion = $Sender->EventArguments['Discussion'];    
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • It works! Thank you for support @peregrine

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Yes ,

    'The King of Kings' => "peregrine"

Sign In or Register to comment.