php - Site Design: How to award users tasks with achievements? -


so i'm wanting setup achievements system on site. people perform tasks , upload information stored in database (think 'time', 'date', 'task', etc.). best method of checking information , awarding achievements? have achievement.php once information uploaded trigger document run through checks determine if user needs awarded achievement? or there server side should set award user?

thanks or suggestions, comments, etc. :d

edit: have achievements listed in database, (id, name, class)

tasks stored ('date_time','time','device','user_id[fk]')

edit 2: many achievements calculated based on not tasks user submitting takes account previous tasks in addition newly added task. ex: if user has completed 3 tasks within 3 consecutive days, awarded it

it depends on preference business logic placement lies, , how real time want acheivements be. if you're looking offload bunch of business logic on sql server, put in stored procedure, otherwise, class out calculations class in php, , use class determine new achievements have been.

i suggest doing processing outside of normal page response. perhaps kick off server-side call php cli, or set cron job run individuals through check achievements @ interval.

edit:

as actual methods of awarding achievements, think you're flexible , simple implementation (you find more simple/less flexible , more flexible/less simple options i'm sure) create awardrunner class, iaward interface , bunch of individual implementations of iaward each award have. basic idea like:

<?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 files exist             foreach($includes $include)             {                 if (is_file($include))                 {                   require($include);                 }             }         }          public function run() {             $classlist = get_declared_classes();              foreach($classlist $key => $classname)             {                 if (in_array('iaward', class_implements($classname))) {                     $award = $classname();                     $award->userid = $this->userid;                      $award->grantifuserqualifies();                 }             }          }          //function reading files in directory.         //this recursive, files in subfolders make 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;         }    } ?> 

i think idea of iaward interface pretty clear usage, though you'd add id field table able insert database, way call awardrunner class.

this idea should work whether have batching awards process looping through users, or fire off after every task submission.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -