Esempio n. 1
0
 public static function _getGames($id)
 {
     $res = array();
     foreach (PlayedGames::find() as $g) {
         if ($g->users_id == $id) {
             $res[] = $g;
         }
     }
     return $res;
 }
Esempio n. 2
0
            return $app->response->redirect('start');
        }
    }
    $u = new Users();
    $u->name = $name;
    $u->save();
    $app->getDI()->getShared('session')->flash = $app->flash->success('You added a new name');
    return $app->response->redirect('start');
};
$save = function () use($app) {
    $post = json_decode(json_encode($app->request->getPost()));
    $user_id = $post->user_id;
    $wins = $post->wins;
    $losses = $post->losses;
    $ties = $post->ties;
    $game = new PlayedGames();
    $game->user_id = $user_id;
    $game->save();
    $score = new Scores();
    $score->wins = $wins;
    $score->losses = $losses;
    $score->ties = $ties;
    $score->played_game_id = $game->id;
    $score->save();
    $app->getDI()->getShared('session')->set('score', $score->id);
    return $app->response->redirect('save_page');
};
$save_page = function () use($app) {
    $app['view']->user = $app->getDI()->get('session')->user_name;
    //$app['view']->score = array_filter(function($x) use ($app){ return $x->id === $app->getDI()->getShared('session')->get('score'); },Scores::find());
    $scores = Scores::find();
Esempio n. 3
0
    foreach ($users as $u) {
        if ($u->id == $user_id) {
            return array_map(function ($x) {
                return $x->toArray();
            }, $u->getScores());
        }
    }
    return false;
};
$game_page = function ($user_id) {
    foreach (Users::find() as $u) {
        if ($u->id == $user_id) {
            return array_map(function ($x) {
                return $x->toArray();
            }, $u->getGames());
        }
    }
};
$s = new Scores();
$g = new PlayedGames();
$u = new Users();
$u->name = 'jhhh';
$u->save();
$g->users_id = $u->id;
$g->save();
$s->wins = 4;
$s->losses = 4;
$s->ties = 4;
$s->played_game_id = $g->id;
$s->save();
print_r($s->getUser()->name);
Esempio n. 4
0
 public function getPlayedGame()
 {
     return PlayedGames::getById($this->played_game_id);
 }