public static function create($user) { $player = new \Own\Bus\Player\Model(); $player->setId($user->getId()); $player->save(); return $player; }
public static function removeAndAddPlayer() { $options = []; $options['clearSelect'] = true; $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username']); $options['where'][] = 'player.user_id = 0'; $options['where'][] = 'player.active = 1'; $players = \Own\Bus\Player\Data::loadAll($options); if (count($players) > 0) { $db = new Util\Data(); $pick = \Own\Bus\Engine::dice(0, count($players) - 1); $remove = 'UPDATE bus_player SET active = 0 WHERE id = ' . $players[$pick]->getId(); $db->execute($remove); Util\Log::log(Util\Code::CRON, 'player retired: ' . $players[$pick]->getUsername() . ' (' . $players[$pick]->getId() . ')', __FILE__, __LINE__); $leagues = \Own\Bus\League\Data::loadAll(); $player = new \Own\Bus\Player\Model(); $player->setRandom(1); $player->setActive(true); if (count($leagues) > 0) { $player->setLeagueId(\Own\Bus\Engine::findLeague($leagues, 1)); } $player->save(); Util\Log::log(Util\Code::CRON, 'new player: ' . $player->getUsername() . ' (' . $player->getId() . ')', __FILE__, __LINE__); } }