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.
Options

Awarding points for other actions

Hi, i would like to award points for other actions such as every time they visit the forum, or every comment they make, discussion they start, etc.

I have Yaga installed, but can't see how to do it with this.

I also tried Karma, but thought that having points as well as Karma coins was too much, so i'd just like to keep it as points.

Is there something which allows this easily? Or will I have to create a plugin?

Comments

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    You have to create a custom rule. Look here (or at your own installation) to see examples: https://github.com/hgtonight/Application-Yaga/tree/master/library/rules

    Here's an example of how you can get help, once you have started ;)
    http://vanillaforums.org/discussion/28754/help-with-new-discussionwordmention-custom-rule#latest

  • Options

    Oh I see, brilliant, thank you :+1:

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    And maybe hard boiled developers can use that: http://hgtonight.github.io/Application-Yaga/en/class-YagaRule.html

  • Options

    Hmm actually, i'm not sure this will work - as doesn't the custom rule apply to badges? I don't want to award a badge necessarily, just award points

  • Options
    hgtonighthgtonight ∞ · New Moderator

    Thanks for trying my addon!

    I have added the ability to award Yaga Points arbitrarily in the development version over on GitHub. It will be part of Yaga 1.1 once I get around to releasing it. You can award points with the following code snippet:

    Yaga::GivePoints($UserID, $PointValue, 'Point_Type');
    

    You have to specify an actual user, $PointValue must be an integer, and the last argument is a string that can't be longer than 10 characters.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    Thanks @hgtonight - is there much difference between that method and UserModel::GivePoints?

    For now i've simply put the following in my ThemeHooks class:

    public function DiscussionModel_AfterSaveDiscussion_Handler($Sender) { if($Sender->EventArguments['Insert']>0) { $Session = Gdn::Session(); UserModel::GivePoints($Session->UserID, 1, 'Discussion'); } }

    .. and then intend on doing something similar for the UpdateVisit event.

    Is your implementation in Yaga 1.1 a better way of doing it?

  • Options
    hgtonighthgtonight ∞ · New Moderator

    @pavsid said:
    Thanks hgtonight - is there much difference between that method and UserModel::GivePoints?

    For now i've simply put the following in my ThemeHooks class:

    public function DiscussionModel_AfterSaveDiscussion_Handler($Sender) { if($Sender->EventArguments['Insert']>0) { $Session = Gdn::Session(); UserModel::GivePoints($Session->UserID, 1, 'Discussion'); } }

    .. and then intend on doing something similar for the UpdateVisit event.

    Is your implementation in Yaga 1.1 a better way of doing it?

    It is almost identical. Yaga::GivePoints is currently just a wrapper for UserModel::GivePoints. I have a few future plans that may change how points are awarded and using Yaga::GivePoints will ensure any addons/modifications are not left in the dust, so to speak.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    Cool thanks, so what's different in Yaga 1.1 then? Is the dev version on Github the master branch?

  • Options
    hgtonighthgtonight ∞ · New Moderator
    edited April 2015

    @pavsid said:
    Cool thanks, so what's different in Yaga 1.1 then? Is the dev version on Github the master branch?

    Yes. There are a few things. Mostly they are improvements for developing Yaga addons. Full changelist here: https://github.com/hgtonight/Application-Yaga/compare/666fafe50cade7bcef58da7bd219a3c2730336e8...master

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    @hgtonight Great addon btw! The gamification element was the only reason I decided to go with Vanilla Forums, and I didn't realise it wasn't included by default in the Open Source version! Thank YOU, for this!

  • Options
    pavsidpavsid New
    edited April 2015

    Having a slight issue, and can't figure it out for the life of me!

    I've created a hook:

        public function UserModel_UpdateVisit_Handler($Sender)
        {
    
            if($Sender->EventArguments['User']['UserID'] != Gdn::Session()->UserID){
                return;
            }
    
            if(!empty($Sender->EventArguments['Fields']['CountVisits'])
                && ($Sender->EventArguments['Fields']['CountVisits'] > $Sender->EventArguments['User']['CountVisits'])){
                UserModel::GivePoints(Gdn::Session()->UserID, 1, 'NewVisit');
            }
        }
    
    

    Except that whatever the $Set variable in the sending method UserModel::UpdateVisit should be, is getting overwritten by the UserModel::GivePoints call in my hook.

    I understand that $Set is passed by reference, and that the UserModel::GivePoints call is overwriting this, but i've even tried instantiating a new UserModel object in my hook, which still gives the same result.

    Does that make sense? Any ideas?

  • Options
    hgtonighthgtonight ∞ · New Moderator

    What $Set variable?

    UserModel::GivePoints is a static function and will always execute the same regardless of what object calls it.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    The $Set variable in UserModel::UpdateVisit, which contains the fields to update against the user:

        if (!empty($Set)) {
             $this->EventArguments['Fields'] =& $Set;
             $this->FireEvent('UpdateVisit');
             $this->SetField($UserID, $Set);
          }
    

    I need those fields to remain the same.

    @hgtonight said:
    What $Set variable?

    UserModel::GivePoints is a static function and will always execute the same regardless of what object calls it.

    Ah yes, of course. So how do I give the user some points, without affecting the original fields in $Set?

  • Options
    hgtonighthgtonight ∞ · New Moderator

    You are handling an event that eventually fires the same event?

    I would add a property onto the sending object and check for that existence at the very beginning of your handling function. If it exists, jump ship.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    @hgtonight said:
    You are handling an event that eventually fires the same event?

    No, i'm handling the UpdateVisit event, and then firing the GivePoints event.

  • Options
    hgtonighthgtonight ∞ · New Moderator

    Ah... I see what is happening. The $Sender->EventArguments['Fields'] element is being used in two different events on the same object.

    Store it before calling the give points then restore it after.

    $Fields = $Sender->EventArguments['Fields'];
    Yaga::GivePoints(Gdn::Session()->UserID, 1, 'NewVisit');
    $Sender->EventArguments['Fields'] = $Fields;
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    pavsidpavsid New
    edited April 2015

    Doh! Great idea. thanks :+1:

Sign In or Register to comment.