public function getScores() { $scores = Scores::find(); $results = array(); foreach ($scores as $s) { if ($s->played_game_id == $this->id) { $results[] = $s; } } return !empty($results) ? $results : false; }
public static function _getScores($id) { $res = array(); foreach (static::_getGames($id) as $g) { foreach (Scores::find() as $s) { if ($s->played_game_id == $g->id) { $res[] = $s; } } } return $res; }
$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(); foreach ($scores as $s) { echo '<pre>'; print_r(json_encode($s)); echo '</pre>'; if ((int) $s->id === (int) $app->getDI()->getShared('session')->get('score')) { $app['view']->score = $s; //json_encode($s); $app['view']->wins = $s->wins; //json_encode($s); $app['view']->losses = $s->losses; //json_encode($s); $app['view']->ties = $s->ties; //json_encode($s); } }