PHP Criteria

PHP Criteria 1.0.0

No permission to download
Compatible XF 2.x versions
2.0
License
GPLv3
Visible branding
No
logo.png

This addon allows you to create complex criteria for advanced trophies or user group promotions with custom PHP code.

For example, you can use:
  • Count the number of threads the user has created in specific forum
  • Analyze users signatures
  • Count the number of likes on single messages
  • Retreive data from addons (like Resource Manager or Question Threads)
  • See how many times (and when) user has edited his post
  • ...
In other words, this addon gives you a full access to xenForo engine and database when creating trophies/promotions.

Moreover you can even combine default xenForo criteria and your custom PHP code!

Your possibilities are limited only by your imagination!

All my addons are free...

But if you want to
  • Be informed of all news about developing new addons
  • Suggest and vote for new addons
  • Try beta versions
  • Receive 24-hour early access to new addons
Then you can support me on my Patreon!
patreon_support.png
Installation
  1. Download an addon archive and unpack it somewhere
  2. Open upload folder and move src folder to your forum root directory
  3. In admin panel go to "Add-ons" section and install "PHP Criteria" addon
Thats it!
You can now create advanced trophies/promotions!

How to use
When creating a new trophy/promotion you can see a new tab called "PHP Callback":
php_callback_tab.png


This tab opens a pane where you can set a path to .php class and an exact method to be executed:
php_callback_pane.png


For example, according to the image above we need to create a file Criteria.php at src/addons with the following content:
PHP:
<?php

class Criteria
{
    public static function trophy_AllForOne(\XF\App $app, \XF\Entity\User $user)
    {
        //
        // YOU CUSTOM CRITERIA CODE GOES BELOW
        //

        // Getting the database
        $db = $app->db();

        // Database query for selecting the maximum number of likes for single user post
        $query = "SELECT `likes` FROM `xf_post` WHERE `user_id` = ? ORDER BY `likes` DESC LIMIT 1";

        // Retrieving the maximum number of likes
        $likes = $db->fetchOne($query, [$user->user_id]);

        // Checking that we have a result from database (we do expect a number)
        if(is_int($likes))
        {
            // Returning true if user has a message with 5 or more likes or false if he has not
            return ($likes >= 5);
        }
        else
        {
            return false;
        }
    }
}
Make sure you receive both \XF\App $app and \XF\Entity\User $user arguments in your method.

Keep in mind that you can combine default xenForo criteria with your code so do not write redundant code!

Examples
After installing addon you will find a file called PHPCriteria.examples.php at src/addons.
It contains three examples of PHP callbacks with detailed explanations!
Feel free to build your own callbacks based on the exapmles.

You can also keep all your callbacks in PHPCriteria.php which will be created automatically after installing the addon.

All my addons are free...

But if you want to
  • Be informed of all news about developing new addons
  • Suggest and vote for new addons
  • Try beta versions
  • Receive 24-hour early access to new addons
Then you can support me on my Patreon!
patreon_support.png
Author
CMTV
Downloads
54
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from CMTV

  • Username change
    Username change
    Ultimate username change functionality: managable history, criteria, widget, permissions and more!
  • Google Search
    Google Search
    Seamless integration of Google Search Engine with your forum search system
  • Code
    Code
    Improving [code] bbcode and code editor. A must have addon if you share code on your forum!
  • Math
    Math
    Math support and a handy button to insert it all rolled into one addon!
  • Question Threads
    Question Threads
    Create questions and mark best answers
Top