feature/MAPG-235-basic-challenge-mode #48
@ -141,11 +141,12 @@ class GameFlowController
 | 
				
			|||||||
        return new JsonContent(['ok' => true]);
 | 
					        return new JsonContent(['ok' => true]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private function prepareChallengeResponse(int $userId, Challenge $challenge, int $currentRound): array
 | 
					    private function prepareChallengeResponse(int $userId, Challenge $challenge, int $currentRound, bool $withHistory = false): array
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $allGuessesInChallenge = iterator_to_array($this->guessRepository->getAllInChallenge($challenge));
 | 
					        $currentPlace = $this->placeRepository->getByRoundInChallenge($challenge, $currentRound);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        foreach ($allGuessesInChallenge as $guess) {
 | 
					        if (!isset($currentPlace) || $withHistory) {
 | 
				
			||||||
 | 
					            foreach ($this->guessRepository->getAllInChallenge($challenge) as $guess) {
 | 
				
			||||||
                $round = $guess->getPlaceInChallenge()->getRound();
 | 
					                $round = $guess->getPlaceInChallenge()->getRound();
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
                if ($guess->getUser()->getId() === $userId) {
 | 
					                if ($guess->getUser()->getId() === $userId) {
 | 
				
			||||||
@ -165,18 +166,29 @@ class GameFlowController
 | 
				
			|||||||
                    ];
 | 
					                    ];
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        
 | 
					        if (!isset($currentPlace)) { // game finished
 | 
				
			||||||
        $currentPlace = $this->placeRepository->getByRoundInChallenge($challenge, $currentRound);
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        if(!isset($currentPlace)) { // game finished
 | 
					 | 
				
			||||||
            $response['finished'] = true;
 | 
					            $response['finished'] = true;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } else { // continue game
 | 
					        } else { // continue game
 | 
				
			||||||
            $response['place'] = [
 | 
					            $response['place'] = [
 | 
				
			||||||
                'panoId' => $currentPlace->getPanoIdCached(),
 | 
					                'panoId' => $currentPlace->getPanoIdCached(),
 | 
				
			||||||
                'pov' => [$currentPlace->getPov()->toArray()]
 | 
					                'pov' => $currentPlace->getPov()->toArray()
 | 
				
			||||||
            ];
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $prevRound = $currentRound - 1;
 | 
				
			||||||
 | 
					            if ($prevRound >= 0) {
 | 
				
			||||||
 | 
					                foreach ($this->guessRepository->getAllInChallengeByRound($prevRound, $challenge) as $guess) {
 | 
				
			||||||
 | 
					                    if ($guess->getUser()->getId() != $userId) {
 | 
				
			||||||
 | 
					                        $response['allResults'][] = [
 | 
				
			||||||
 | 
					                            'userName' => $guess->getUser()->getDisplayName(),
 | 
				
			||||||
 | 
					                            'guessPosition' => $guess->getPosition()->toArray(),
 | 
				
			||||||
 | 
					                            'distance' => $guess->getDistance(),
 | 
				
			||||||
 | 
					                            'score' => $guess->getScore()
 | 
				
			||||||
 | 
					                        ];
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $response;
 | 
					        return $response;
 | 
				
			||||||
@ -196,7 +208,7 @@ class GameFlowController
 | 
				
			|||||||
        $challenge = $userInChallenge->getChallenge();
 | 
					        $challenge = $userInChallenge->getChallenge();
 | 
				
			||||||
        $currentRound = $userInChallenge->getCurrentRound();
 | 
					        $currentRound = $userInChallenge->getCurrentRound();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $response = $this->prepareChallengeResponse($userId, $challenge, $currentRound);
 | 
					        $response = $this->prepareChallengeResponse($userId, $challenge, $currentRound, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return new JsonContent($response);
 | 
					        return new JsonContent($response);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -84,7 +84,7 @@ class PersistentDataManager
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                next($relations);
 | 
					                next($relations);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                return;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -53,7 +53,6 @@ class GuessRepository
 | 
				
			|||||||
    public function getAllInChallenge(Challenge $challenge): Generator
 | 
					    public function getAllInChallenge(Challenge $challenge): Generator
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $select = new Select(\Container::$dbConnection);
 | 
					        $select = new Select(\Container::$dbConnection);
 | 
				
			||||||
        // $select->innerJoin('place_in_challenge', ['guesses', 'place_in_challenge_id'], '=', ['place_in_challenge', 'id']);
 | 
					 | 
				
			||||||
        $select->where('challenge_id', '=', $challenge->getId());
 | 
					        $select->where('challenge_id', '=', $challenge->getId());
 | 
				
			||||||
        $select->orderBy('round');
 | 
					        $select->orderBy('round');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -63,7 +62,6 @@ class GuessRepository
 | 
				
			|||||||
    public function getAllInChallengeByRound(int $round, Challenge $challenge): Generator
 | 
					    public function getAllInChallengeByRound(int $round, Challenge $challenge): Generator
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $select = new Select(\Container::$dbConnection);
 | 
					        $select = new Select(\Container::$dbConnection);
 | 
				
			||||||
        // $select->innerJoin('place_in_challenge', ['guesses', 'place_in_challenge_id'], '=', ['place_in_challenge', 'id']);
 | 
					 | 
				
			||||||
        $select->where('challenge_id', '=', $challenge->getId());
 | 
					        $select->where('challenge_id', '=', $challenge->getId());
 | 
				
			||||||
        $select->where('round', '=', $round);
 | 
					        $select->where('round', '=', $round);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user