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.

View Count - my solution.

peregrineperegrine MVP
edited April 2012 in Vanilla 2.0 - 2.8

I noticed there was a change to vanilla/controllers/class.discussioncontroller.php
around line 90 and 91 these line have been commented out.

  // NOTE: This has been moved to an event fired from analyticstick.
      //    if ($Offset == '')
     //       $this->DiscussionModel->AddView($DiscussionID,$this->Discussion->CountViews);

I modified it to this and got my view count back

      if ($Offset == '')
          $this->DiscussionModel->AddView($DiscussionID,$this->Discussion->CountViews);

unfortunately analyticstick does not seem to get updated. if anyone want to provide a clue on why analyticstick table is not updated I will re-comment.

so I just uncommented them out and got my view count back.

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

Best Answers

  • 422422 Developer MVP
    edited August 2012 Answer ✓

    I thinks its bigbrother vanilla analytics

    There was an error rendering this rich post.

Answers

  • I probably won't get any likes here - but it does bring back things to the way they were.

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

  • peregrine said:
    I probably won't get any likes here - but it does bring back things to the way they were.

    What do you mean? What things

  • you said you wanted your view count to be incremented.

    if it is only being incremented when a user from a different ip address views the discussion
    (this may or may not be the case). The change makes every view no matter what ip address the user is coming from to be incremented, which I believe was the way it worked in previous versions of vanilla. Personally, I don't care what you choose, i was just trying to provide you a solution.

    From now on, if a user does not do one of two things
    provide documentation on the wiki
    or click the like button,
    that is the end of my attempts to help that particular user.

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

  • 422422 Developer MVP
    edited August 2012 Answer ✓

    I thinks its bigbrother vanilla analytics

    There was an error rendering this rich post.

  • my workaround for 2.1 until it is modified.

    create a folder under plugins called IncrementView

    create a file called plugins/IncrementView/classincrementview.plugin.php

    add the following

    <?php if (!defined('APPLICATION')) exit();
    
    $PluginInfo['IncrementView'] = array(
       'Name' => 'IncrementView',
       'Description' => 'Increment view count by 1 when statistics not enabled',
       'Version' => '1.0',
       'Author' => "Peregrine",
    
    );
    
    class IncrementViewPlugin extends Gdn_Plugin {
    
       public function DiscussionController_BeforeDiscussionDisplay_Handler($Sender) {
       $MyDiscussion = $Sender->EventArguments['Discussion'];
    
        $DiscussionID = $MyDiscussion->DiscussionID;
        $DiscussionView = $MyDiscussion->CountViews  +1 ;
    
        $SQL = Gdn::SQL();
           $SQL->Update('Discussion')
           ->Set('CountViews',$DiscussionView )
           ->Where('DiscussionID', $DiscussionID)
           ->Put();
       }
    
       public function Setup() {
       }
    
    }
    

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

  • I've tried like that :) it's working great... with "my" v2.1a33, thank you @peregrine

  • darbeeydarbeey New
    edited February 2013

    @peregrine Thanks for the plugin, but when i enable it on Version 2.1a35 i get the following error in a red box:

    There was an error getting the class methods.

    Edit: For some reason i was fiddling about with the code and i caused and error when i reloaded the plugin page in the dashboard. I reverted my code fiddles to the original code and it was enabled when i reloaded the plugin page in the dash. Tested the view count on the forum and it works fine :D. I probably should of tried enabling it in the config now that i think of it.

    Thanks for a great fix @peregrine :)

Sign In or Register to comment.