Website design: how to reward users for achievements?

So, I want to set up an achievement system on my site. People perform tasks and download this information, which is then stored in a database (think "time", "date", "task", etc.). What would be the best way to verify their information and reward achievements? Will it be just as achievement .php for me, that after downloading the information, it will run this document to check all the checks to determine if the user needs to receive the achievement? Or is there some kind of server side that I have to configure to reward the user?

Thanks for any help or suggestions, comments, etc .: D

EDIT: I currently have achievements listed in the database, ( id , name, class)

Tasks are saved as ('date_time', 'time', 'device', 'user_id [fk]')

EDIT 2: Also, many achievements will be calculated based not only on the tasks that the user is currently presenting, but also taking into account previous tasks in addition to the recently added task. EX: If the user completed 3 tasks in 3 consecutive days, they will be awarded for it.

+3
source share
3 answers

, -, , . - sql, , php , , .

. , php cli cron, .

:

, , ( / / , ) AwardRunner , IAward IAward , . :

<?php
    class AwardRunner {
        var $UserId = 0;

        function AwardRunner($userId) {
            $this->UserId = $userId;

            $dir = "/path/to/your/folder/full/of/IAwards/";
            $includes = read_dir($dir);

            //include all files that exist
            foreach($includes as $include)
            {
                if (is_file($include))
                {
                  require($include);
                }
            }
        }

        public function Run() {
            $classList = get_declared_classes();

            foreach($classList as $key => $className)
            {
                if (in_array('IAward', class_implements($className))) {
                    $award = $className();
                    $award->UserId = $this->UserId; 
                    $award->GrantIfUserQualifies();
                }
            }

        }

        //function for reading all files in a directory.
        //this is recursive, so any files in subfolders will also make it in
        function read_dir($dir) 
        {
            $array = array();
            $d = dir($dir); 
            while (false !== ($entry = $d->read())) {
                if($entry!='.' && $entry!='..') {
                    $entry = $dir.'/'.$entry;
                    if(is_dir($entry)) {
                        $array = array_merge($array, read_dir($entry));
                    } else {
                        $array[] = $entry;
                    }
                }
            }
            $d->close();
            return $array;
        }   
}
?>

, , IAward, , , , Id , , AwardRunner.

, -, .

+1

, , . , - .

+2

(, , , ), , , , .

, , , / , (, , ).

+1

All Articles