Skip to content

Instantly share code, notes, and snippets.

@jmagnuss
Created August 4, 2015 19:54
Show Gist options
  • Select an option

  • Save jmagnuss/91260113ad948b06d8d8 to your computer and use it in GitHub Desktop.

Select an option

Save jmagnuss/91260113ad948b06d8d8 to your computer and use it in GitHub Desktop.
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