Created
August 4, 2015 19:54
-
-
Save jmagnuss/91260113ad948b06d8d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private $_uid; | |
| private $_rows = []; | |
| public function __constructor($uid) { | |
| $_uid = $uid; | |
| } | |
| public function load() { | |
| $records = DB::table("user_stats")->where("uid",$this->_uid)->getAll() | |
| foreach ($records as $rec) { | |
| $class = "UserStatGeneric"; | |
| switch ($rec->name) { | |
| case "stamina": | |
| $class = "UserStatStamina"; | |
| break; | |
| } | |
| $obj = new $class($rec); | |
| $this->_rows[$rec->name] = $obj; | |
| } | |
| } | |
| public function save() { | |
| $values = []; | |
| foreach ($this->_rows as $name => $obj) { | |
| $queryValue = "(1001, 123456, 'stamina', 100)"; // generate mysql-safe CSV update block, this is an example | |
| } | |
| $query = "replace into user_stats values ".implode(',', $values).";"; | |
| DB::doMeRaw($query); | |
| } | |
| public function add($name, $amount) { | |
| if (isset($this->_rows[$name])) { | |
| $this->_rows[$name]->add($amount); | |
| } | |
| } | |
| // run every N minutes for automatically modified items | |
| public function updatePoll() { | |
| foreach ($this->_rows as $name => $obj) { | |
| $obj->updatePoll(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment