HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Suggested Hook.

Is it possible to get a FireEvent('View') inside the AddView() function of the DiscussionModel? A requirement of our use of the Forum is for statistics for the "distinct" number of views of a discussion (indivdual user views). I will be adding this in our version of the code to then hook in stats which be stored in an extra column added to the UserDiscussion table, however it would be nice to see it in a future Vanilla release!



  • That is a different meta though, and as you say you re storing them separately. It would not make sense to conflate these to different things.

    grep is your friend.

  • what you want to do is use a hook like this (copied from /applications/vanilla/settings/class.hooks.php) in your plugin

    public function Gdn_Statistics_Tick_Handler($Sender, $Args) {
          $Path = GetValue('Path', $Args);
          if (preg_match('`discussion\/(\d+)`i', $Path, $Matches)) {
             $DiscussionID = $Matches[1];
          } elseif(preg_match('`discussion\/comment\/(\d+)`i', $Path, $Matches)) {
             $CommentID = $Matches[1];
             $CommentModel = new CommentModel();
             $Comment = $CommentModel->GetID($CommentID);
             $DiscussionID = GetValue('DiscussionID', $Comment);
          if (isset($DiscussionID)) {
             //do stuff here

    You can extend the DiscussionModel

    public function DiscussionModel_AddUniqueViews_Create($DiscussionID, $Views = 0){
         //do stuff here

    grep is your friend.

Sign In or Register to comment.