public function create_object($data) { if (empty($data['victor'])) { $data['victor'] = 0; } else { $data['victor'] = Agent::mapper()->create_object(array('id' => $data['victor'], 'alias' => $data['victor_agent_alias'])); unset($data['victor_alias']); } $game = Game::create($data, True); $game->attach_mapper('Kill', Kill::mapper()->attach_storage(\Core\Storage::container()->get_storage('Kill'))); $game->attach_mapper('Agent', Agent::mapper()->attach_storage(\Core\Storage::container()->get_storage('Agent'))); foreach (array('start_date', 'end_date') as $f) { $game[$f] = new \DateTime($game[$f]); } $game->invite_only = (int) $data['invite_only']; $now = new \DateTime(); if ($game->start_date > $now) { $game['joinable'] = True; $game['active'] = False; $game['state'] = 0; } else { if ($game->start_date < $now && $now < $game->end_date) { $game['joinable'] = False; $game['active'] = True; $game['state'] = 1; } else { $game['joinable'] = False; $game['active'] = False; $game['state'] = 2; } } return $game; }
public function find_by_game(\Trouble\Game $game, $limit = 20) { $items = \Core\Storage::container()->get_storage('Kill')->fetch(array("joins" => KillContainer::_standard_joins(), "filter" => new \Core\Filter("game", $game['id']))); $kills = Kill::mapper()->get_list($items); return $kills; }