1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to extend user criteria (for use in trophies, upgrades and notices/notifications) 1.0

Extend the standard user criteria used in trophies, upgrades and notices/notifications

  1. Chris D

    Chris D XenForo Developer Staff Member

    Chris Deeming submitted a new resource:

    How to extend user criteria (for use in trophies, upgrades and notices/notifications) (version 1.0) - Extend the standard user criteria used in trophies, upgrades and notices/notifications

    Read more about this resource...
     
    Steve F, Brad L, Sage Knight and 4 others like this.
  2. vVv

    vVv Guest

    nice one chris! :) so this basically can made for whatever you'd like.. "user needs avatar" ..."user needs to select gender".. etc etc and gain trophy points or whatever, with alerts...? I wanted something like this for longest time now... I'll have to try this. :)
     
  3. Chris D

    Chris D XenForo Developer Staff Member

    Well yeah you will get alerts if the trophy is issued.

    So if you're comfortable altering PHP code then you will get the result you need.
     
    vVv likes this.
  4. vVv

    vVv Guest

    Nice, I'm not a professional coder/PHP coder like you and most here, but if I'm shown what to do, the code, etc.. I don't mind working with it. lol.
     
  5. Bob

    Bob Well-Known Member

    Wonder who that was :whistle:
     
    Chris D likes this.
  6. vVv

    vVv Guest

    ? that directed to...Me? or.. Chris? confused lol
     
  7. Bob

    Bob Well-Known Member

    lol Chris.. it was me that asked him if he'd messed around with it at all.
     
    Chris D and vVv like this.
  8. vVv

    vVv Guest

    Oh, okay.. lol. :)
     
  9. vVv

    vVv Guest

    Did this guide but just made the mistake of naming the file in the library/UserCriteriaUploadAvatar/ to Library.php, when it should have been Listener.php (silly me, lacking coffee / dumb blond moment I guess lmao) but it's working like charm now though. Now, need to make few more events/alerts .. then I'll be set. :D
     
  10. borbole

    borbole Well-Known Member

    Chris, I have noticed that you have created some very useful and handy mods. Keep up the great work :)
     
    Rob Fritz, Chris D and vVv like this.
  11. Chris D

    Chris D XenForo Developer Staff Member

    Thank you :)
     
    borbole and vVv like this.
  12. borbole

    borbole Well-Known Member

    You are very welcome :)
     
    Chris D likes this.
  13. ArnyVee

    ArnyVee Well-Known Member

    Chris, in this example, will it award a trophy each time a user has uploaded an avatar? Or, only upon their first instance of uploading an avatar?
     
  14. Chris D

    Chris D XenForo Developer Staff Member

    Well you can only be awarded a trophy once. So the question is if the trophy is taken away if you remove your avatar, I guess.

    The way to test this, is if you set up a trophy for the existing "user has no avatar" criteria and remove your avatar, run the cron, then add your avatar back and run the cron again, do you lose the trophy? if you remove the avatar and then run the cron again do you get the trophy back?

    If so, then the same will happen with this criteria.
     
    ArnyVee likes this.
  15. Hardcore

    Hardcore Active Member

    As mentioned above, the file you need to create is: "Listener.php" ... otherwise this works great as a workaround for that damn "Award this Trophy if ... user has no avatar" wackiness. ;) Thanks!

    Curious: Has anyone used this tutorial to create other trophies?
     
  16. Bob

    Bob Well-Known Member

    yes

    v2_trophy.png
     
    DaniD, AntonioC and Chris D like this.
  17. tyteen4a03

    tyteen4a03 Well-Known Member

    Here are some takeaway codes for people that need extra usergroup matching. This is originally written for my addon [3.studIo] Usergroup Ranks and is released under the BSD 2-Clause modified license, but if you need this code in paid products just ask me and I'll give you permission. (Come to think of it, I might as well release this code as an independent addon. More on that later.)

    The templates required is in the Usergroup Ranks XML. Too lazy to add in here.

    The extra criteria covered are:
    • Usergroup matching (is/is not Primary/Display/Secondary (any)/Secondary (all)/in All usergroup(s))
    • Display Usergroup is Primary/in Secondary Usergroup(s)
    • Display Style Priority of user's Primary/Display/Secondary (any)/Secondary (all)/All usergroup(s) is higher/lower than set value
    https://github.com/tyteen4a03/3ps_u...ntStudio/UsergroupRanks/Listener/Criteria.php
     
  18. MattW

    MattW Well-Known Member

    I've got this working where I can create trophies for the number of resources submitted, but is anyone able to suggest a better/cleaner way of doing this?

    PHP:
    <?php
     
    class CustomTrophies_Listener
    {
        public static function 
    templateHook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            if (
    $hookName == 'user_criteria_content')
            {
                    
    $userCriteria $template->getParam('userCriteria');
                    
    $checked1 $userCriteria['has_resource'] ? 'checked' '';
                    
    $checked2 $userCriteria['resource_5'] ? 'checked' '';
                    
    $checked3 $userCriteria['resource_10'] ? 'checked' '';
                    
    $checked4 $userCriteria['resource_25'] ? 'checked' '';
                    
    $checked5 $userCriteria['resource_50'] ? 'checked' '';
                    
    $contents .= '<li><label><input type="checkbox" name="user_criteria[has_resource][rule]" value="has_resource"' $checked1 .' /> User has a Resource</label></li>
                    <li><label><input type="checkbox" name="user_criteria[resource_5][rule]" value="resource_5"' 
    $checked2 .' /> User has 5 Resources</label></li>
                    <li><label><input type="checkbox" name="user_criteria[resource_10][rule]" value="resource_10"' 
    $checked3 .' /> User has 10 Resources</label></li>
                    <li><label><input type="checkbox" name="user_criteria[resource_25][rule]" value="resource_25"' 
    $checked4 .' /> User has 25 Resources</label></li>
                    <li><label><input type="checkbox" name="user_criteria[resource_50][rule]" value="resource_50"' 
    $checked5 .' /> User has 50 Resources</label></li>';
            }
        }
     
        public static function 
    criteriaUser($rule, array $data, array $user, &$returnValue)
        {
            switch (
    $rule)
            {
                    case 
    'has_resource':
                            if (!empty(
    $user['resource_count']))
                            {
                            
    $returnValue true;
                            }
                    break;
     
                    case 
    'resource_5':
                            if (!empty(
    $user['resource_count']) && ($user['resource_count'] >= 5))
                            {
                            
    $returnValue true;
                            }
                    break;
     
                    case 
    'resource_10':
                            if (!empty(
    $user['resource_count']) && ($user['resource_count'] >= 10))
                            {
                            
    $returnValue true;
                            }
                    break;
     
                    case 
    'resource_25':
                            if (!empty(
    $user['resource_count']) && ($user['resource_count'] >= 25))
                            {
                            
    $returnValue true;
                            }
                    break;
     
                    case 
    'resource_50':
                            if (!empty(
    $user['resource_count']) && ($user['resource_count'] >= 50))
                            {
                            
    $returnValue true;
                            }
                    break;
     
           
            }
        }
    }
     
  19. Stuart Wright

    Stuart Wright Well-Known Member

    Failed trying to follow your tutorial Chris. I want to give people a trophy point or two for adding an avatar.
    So I followed your instructions.
    temp1.jpg
    Created the Listener.php and saved it in library/AVForums/UserCriteriaHasAvatar/Listener.php
    And Listener.php looks like this:
    PHP:
    <?php

    class UserCriteriaHasAvatar_Listener
    {
        public static function 
    templateHook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            if (
    $hookName == 'user_criteria_profile')
          {
                
    $userCriteria $template->getParam('userCriteria');
                
    $checked $userCriteria['has_avatar'] ? 'checked' '';
                
    $contents .= '<li><label><input type="checkbox" name="user_criteria[has_avatar][rule]" value="has_avatar"' $checked .' /> User has an avatar</label></li>';
            }
        }
    }

    ?>
    Uploaded the file to the sandbox.

    When I try to add the event listener, I get this error:
    temp2.jpg
    What am I doing wrong?
     
  20. Chris D

    Chris D XenForo Developer Staff Member

    Your callback class needs to be named the same as your Listener PHP class:

    UserCriteriaHasAvatar_Listener
     
    MattW likes this.

Share This Page