/** * @param string $newGameName * @param int $applicationId * @return array */ static function createNewPlayer( $newGameName, $applicationId, $isLocalQuiz = true ) { $currentMMUser = MMUsers::getCurrentUserObject(); if( $currentMMUser ) { $clusterIdentifier = ($isLocalQuiz) ? ClusterTool::clusterIdentifier() : ''; $newPlayer = new QuizPlayerScoring(); // Setting up the global ranking of the new player $lowestGlobalScore = self::fetchBy( array( 'application_id' => $applicationId, 'cluster_identifier' => $clusterIdentifier ), array( 'global_ranking' => 'desc' ), array( 'length' => 1 ) ); if( $lowestGlobalScore ) $lgs = $lowestGlobalScore[0]->attribute( 'score' ) == 0 ? $lowestGlobalScore[0]->attribute( 'global_ranking' ) : ( $lowestGlobalScore[0]->attribute( 'global_ranking' ) + 1 ); else $lgs = 1; // Setting up the specialty ranking of the new player $userSpecialtyTranslations = FacetFilteringTool::getTaxoTranslationWithIDs( 'user_specialty' ); $userSpecialtyTaxonomyId = $userSpecialtyTranslations[$currentMMUser->attribute( 'user_speciality' )]['id']; $lowestSpecialtyScore = self::fetchBy( array( 'application_id' => $applicationId, 'user_specialty' => $userSpecialtyTaxonomyId ), array( 'specialty_ranking' => 'desc' ), array( 'length' => 1 ) ); if( $lowestSpecialtyScore ) $lss = $lowestSpecialtyScore[0]->attribute( 'score' ) == 0 ? $lowestSpecialtyScore[0]->attribute( 'specialty_ranking' ) : ( $lowestSpecialtyScore[0]->attribute( 'specialty_ranking' ) + 1 ); else $lss = 1; $newPlayer->setAttribute( 'game_name', $newGameName ); $newPlayer->setAttribute( 'uuid', $currentMMUser->attribute( 'uuid' ) ); $newPlayer->setAttribute( 'cluster_identifier', $clusterIdentifier); $newPlayer->setAttribute( 'application_id', $applicationId ); $newPlayer->setAttribute( 'score', 0 ); $newPlayer->setAttribute( 'user_specialty', Taxonomy::fetchObject( Taxonomy::definition(), null, array( 'code' => $currentMMUser->attribute( 'user_speciality' ) ), true)->attribute( 'id' ) ); $newPlayer->setAttribute( 'nb_correct', 0 ); $newPlayer->setAttribute( 'nb_wrong', 0 ); $newPlayer->setAttribute( 'global_ranking', $lgs ); $newPlayer->setAttribute( 'specialty_ranking', $lss ); $newPlayer->setAttribute( 'user_cluster', ClusterTool::clusterIdentifier() ); $newPlayer->store(); return array( 'lgs' => $lgs, 'lss' => $lss ); } return null; }