<?php
namespace App\Entity\Player;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Player
*
* @ORM\Table(name="tam_players")
* @ORM\Entity(repositoryClass="App\Repository\Player\PlayerRepository")
* @ORM\HasLifecycleCallbacks
*/
class Player
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="player", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="tam_user", referencedColumnName="id", onDelete="CASCADE", nullable=false)
*/
private $user;
/**
* @var string
*
* @ORM\Column(name="gender", type="string", length=255, nullable=true)
*/
private $gender;
/**
* @var string
*
* @ORM\Column(name="gimmick", type="text", length=255, nullable=true)
*/
private $gimmick;
/**
* @var \DateTime
*
* @ORM\Column(name="birthdate", type="date", nullable=true)
*/
private $birthdate;
/**
* @var \rankingSystem
*
* @ORM\ManyToOne(targetEntity="\App\Entity\Ranking\RankingSystem", inversedBy="rankingPlayers")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="ranking_system", referencedColumnName="id", onDelete="SET NULL", nullable=true)
* })
*/
private $rankingSystem;
/**
* @var \ranking
*
* @ORM\ManyToOne(targetEntity="\App\Entity\Ranking\Ranking", inversedBy="currentRankingPlayers")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="current_ranking", referencedColumnName="id", onDelete="SET NULL", nullable=true)
* })
*/
private $currentRanking;
/**
* @var \rankingCountry
*
* @ORM\ManyToOne(targetEntity="\App\Entity\Ranking\Ranking", inversedBy="bestRankingPlayers")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="best_ranking", referencedColumnName="id", onDelete="SET NULL", nullable=true)
* })
*/
private $bestRanking;
/**
* @var \DateTime
*
* @ORM\Column(name="best_ranking_date", type="date", nullable=true)
*/
private $bestRankingDate;
/**
* @var string
*
* @ORM\Column(name="hand", type="string", length=255, nullable=true)
*/
private $hand;
/**
* @var float
*
* @ORM\Column(name="game_level", type="float", precision=10, scale=0, nullable=true)
*/
private $gameLevel;
/**
* @var \App\Entity\Player\PlayerType
*
* @ORM\ManyToOne(targetEntity="\App\Entity\Player\PlayerType", inversedBy="players")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="player_type", referencedColumnName="id", onDelete="SET NULL", nullable=true)
* })
*/
private $playerType;
/**
* @var \App\Entity\Brand\BrandRacket
*
* @ORM\ManyToOne(targetEntity="\App\Entity\Brand\BrandRacket", fetch="EAGER", inversedBy="players")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="brand_racket", referencedColumnName="id", onDelete="SET NULL", nullable=true)
* })
*/
private $brandRacket;
/**
* @var \App\Entity\Brand\BrandShoe
*
* @ORM\ManyToOne(targetEntity="\App\Entity\Brand\BrandShoe", fetch="EAGER", inversedBy="players")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="brand_shoe", referencedColumnName="id", onDelete="SET NULL", nullable=true)
* })
*/
private $brandShoe;
/**
* @var integer
*
* @ORM\Column(name="nb_play_by_week", type="integer", options={"default": 0}, nullable=true)
*/
private $nbPlayByWeek;
/**
* @var \App\Entity\Player\PlayerNbTournamentByYear
*
* @ORM\ManyToOne(targetEntity="\App\Entity\Player\PlayerNbTournamentByYear", fetch="EAGER", inversedBy="players")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="nb_tournament_by_year", referencedColumnName="id", onDelete="SET NULL", nullable=true)
* })
*/
private $nbTournamentByYear;
/**
* @var string
*
* @ORM\Column(name="favorite_player_m", type="string", length=255, nullable=true)
*/
private $favoritePlayerM;
/**
* @var string
*
* @ORM\Column(name="favorite_player_f", type="string", length=255, nullable=true)
*/
private $favoritePlayerF;
/**
* @var string
*
* @ORM\Column(name="best_performance", type="string", length=255, nullable=true)
*/
private $bestPerformance;
/**
* @var \DateTime
*
* @ORM\Column(name="best_performance_date", type="date", nullable=true)
*/
private $bestPerformanceDate;
/**
* @var string
*
* @ORM\Column(name="best_match_viewed", type="text", nullable=true)
*/
private $bestMatchViewed;
/**
* @var \App\Entity\Club\Club
*
* @ORM\ManyToOne(targetEntity="\App\Entity\Club\Club", fetch="EAGER", inversedBy="players")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="club", referencedColumnName="id", onDelete="SET NULL", nullable=true)
* })
*/
private $club;
/**
* @var string
*
* @ORM\Column(name="other_club", type="string", length=255, nullable=true)
*/
private $otherClub;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="\App\Entity\Player\PlayerWish", inversedBy="players")
* @ORM\JoinTable(name="tam_user_player_wish")
*/
private $wishes;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="\App\Entity\Player\PlayerAvailability", inversedBy="players")
* @ORM\JoinTable(name="tam_user_player_availability")
*/
private $availabilities;
public function __construct()
{
$this->wishes = new ArrayCollection();
$this->availabilities = new ArrayCollection();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set User
*
* @param \App\Entity\User $user
*
* @return Player
*/
public function setUser(\App\Entity\User $user)
{
$this->user = $user;
$user->setPlayer($this);
return $this;
}
/**
* Get user
*
* @return \App\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Set gender
*
* @param string $gender
*
* @return Player
*/
public function setGender($gender)
{
$this->gender = $gender;
return $this;
}
/**
* Get gender
*
* @return string
*/
public function getGender()
{
return $this->gender;
}
/**
* Set gimmick
*
* @param string $gimmick
*
* @return Player
*/
public function setGimmick($gimmick)
{
$this->gimmick = $gimmick;
return $this;
}
/**
* Get gimmick
*
* @return string
*/
public function getGimmick()
{
return $this->gimmick;
}
/**
* Set birthdate
*
* @param \DateTime $birthdate
*
* @return Player
*/
public function setBirthdate($birthdate)
{
$this->birthdate = $birthdate;
return $this;
}
/**
* Get birthdate
*
* @return \DateTime
*/
public function getBirthdate()
{
return $this->birthdate;
}
/**
* Set rankingSystem
*
* @param \App\Entity\Ranking\RankingSystem $rankingSystem
*
* @return Player
*/
public function setRankingSystem(\App\Entity\Ranking\RankingSystem $rankingSystem)
{
$this->rankingSystem = $rankingSystem;
return $this;
}
/**
* Get rankingSystem
*
* @return \App\Entity\Ranking\RankingSystem
*/
public function getRankingSystem()
{
return $this->rankingSystem;
}
/**
* Set currentRanking
*
* @param \App\Entity\Ranking\Ranking $currentRanking
*
* @return Player
*/
public function setCurrentRanking(\App\Entity\Ranking\Ranking $currentRanking)
{
$this->currentRanking = $currentRanking;
return $this;
}
/**
* Get currentRanking
*
* @return \App\Entity\Ranking\Ranking
*/
public function getCurrentRanking()
{
return $this->currentRanking;
}
/**
* Set bestRanking
*
* @param \App\Entity\Ranking\Ranking $bestRanking
*
* @return Player
*/
public function setBestRanking(\App\Entity\Ranking\Ranking $bestRanking)
{
$this->bestRanking = $bestRanking;
return $this;
}
/**
* Get bestRanking
*
* @return \App\Entity\Ranking\Ranking
*/
public function getBestRanking()
{
return $this->bestRanking;
}
/**
* Set bestRankingDate
*
* @param \DateTime $bestRankingDate
*
* @return Player
*/
public function setBestRankingDate($bestRankingDate)
{
$this->bestRankingDate = $bestRankingDate;
return $this;
}
/**
* Get bestRankingDate
*
* @return \DateTime
*/
public function getBestRankingDate()
{
return $this->bestRankingDate;
}
/**
* Set hand
*
* @param string $hand
*
* @return Player
*/
public function setHand($hand)
{
$this->hand = $hand;
return $this;
}
/**
* Get hand
*
* @return string
*/
public function getHand()
{
return $this->hand;
}
/**
* Set gameLevel
*
* @param float $gameLevel
*
* @return Player
*/
public function setGameLevel($gameLevel)
{
if($gameLevel == "")
$this->gameLevel = null;
else
$this->gameLevel = str_replace(",", ".", $gameLevel);
return $this;
}
/**
* Get gameLevel
*
* @return float
*/
public function getGameLevel()
{
return $this->gameLevel;
}
/**
* Set playerType
*
* @param PlayerType $playerType
*
* @return Player
*/
public function setPlayerType($playerType)
{
$this->playerType = $playerType;
return $this;
}
/**
* Get playerType
*
* @return PlayerType
*/
public function getPlayerType()
{
return $this->playerType;
}
/**
* Set brandRacket
*
* @param RankingSystem $brandRacket
*
* @return Player
*/
public function setBrandRacket($brandRacket)
{
$this->brandRacket = $brandRacket;
return $this;
}
/**
* Get brandRacket
*
* @return BrandRacket
*/
public function getBrandRacket()
{
return $this->brandRacket;
}
/**
* Set brandShoe
*
* @param RankingSystem $brandShoe
*
* @return Player
*/
public function setBrandShoe($brandShoe)
{
$this->brandShoe = $brandShoe;
return $this;
}
/**
* Get brandShoe
*
* @return BrandShoe
*/
public function getBrandShoe()
{
return $this->brandShoe;
}
/**
* Set nbPlayByWeek
*
* @param integer $nbPlayByWeek
*
* @return Player
*/
public function setNbPlayByWeek($nbPlayByWeek)
{
$this->nbPlayByWeek = $nbPlayByWeek;
return $this;
}
/**
* Get nbPlayByWeek
*
* @return integer
*/
public function getNbPlayByWeek()
{
return $this->nbPlayByWeek;
}
/**
* Set nbTournamentByYear
*
* @param PlayerNbTournamentByYear $nbTournamentByYear
*
* @return Player
*/
public function setNbTournamentByYear($nbTournamentByYear)
{
$this->nbTournamentByYear = $nbTournamentByYear;
return $this;
}
/**
* Get nbTournamentByYear
*
* @return integer
*/
public function getNbTournamentByYear()
{
return $this->nbTournamentByYear;
}
/**
* Set favoritePlayerM
*
* @param string $favoritePlayerM
*
* @return Player
*/
public function setFavoritePlayerM($favoritePlayerM)
{
$this->favoritePlayerM = $favoritePlayerM;
return $this;
}
/**
* Get favoritePlayerM
*
* @return string
*/
public function getFavoritePlayerM()
{
return $this->favoritePlayerM;
}
/**
* Set favoritePlayerF
*
* @param string $favoritePlayerF
*
* @return Player
*/
public function setFavoritePlayerF($favoritePlayerF)
{
$this->favoritePlayerF = $favoritePlayerF;
return $this;
}
/**
* Get favoritePlayerF
*
* @return string
*/
public function getFavoritePlayerF()
{
return $this->favoritePlayerF;
}
/**
* Set bestPerformance
*
* @param string $bestPerformance
*
* @return Player
*/
public function setBestPerformance($bestPerformance)
{
$this->bestPerformance = $bestPerformance;
return $this;
}
/**
* Get bestPerformance
*
* @return string
*/
public function getBestPerformance()
{
return $this->bestPerformance;
}
/**
* Set bestPerformanceDate
*
* @param \DateTime $bestPerformanceDate
*
* @return Player
*/
public function setBestPerformanceDate($bestPerformanceDate)
{
$this->bestPerformanceDate = $bestPerformanceDate;
return $this;
}
/**
* Get bestPerformanceDate
*
* @return \DateTime
*/
public function getBestPerformanceDate()
{
return $this->bestPerformanceDate;
}
/**
* Set bestMatchViewed
*
* @param string $bestMatchViewed
*
* @return Player
*/
public function setBestMatchViewed($bestMatchViewed)
{
$this->bestMatchViewed = $bestMatchViewed;
return $this;
}
/**
* Get bestMatchViewed
*
* @return string
*/
public function getBestMatchViewed()
{
return $this->bestMatchViewed;
}
/**
* Set club
*
* @param RankingSystem $club
*
* @return Player
*/
public function setClub($club)
{
$this->club = $club;
return $this;
}
/**
* Get club
*
* @return Club
*/
public function getClub()
{
return $this->club;
}
/**
* Set otherClub
*
* @param string $otherClub
*
* @return Player
*/
public function setOtherClub($otherClub)
{
$this->otherClub = $otherClub;
return $this;
}
/**
* Get otherClub
*
* @return string
*/
public function getOtherClub()
{
return $this->otherClub;
}
/**
* Add wish
*
* @param \App\Entity\Player\PlayerWish $wish
*
* @return Player
*/
public function addWish(\App\Entity\Player\PlayerWish $wish)
{
if (!$this->wishes->contains($wish)) {
$this->wishes[] = $wish;
}
return $this;
}
/**
* Remove wish
*
* @param \App\Entity\Player\PlayerWish $wish
*/
public function removeWish(\App\Entity\Player\PlayerWish $wish)
{
if ($this->wishes->contains($wish)) {
$this->wishes->removeElement($wish);
}
return $this;
}
/**
* Get wishes
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getWishes()
{
return $this->wishes;
}
/**
* Add availability
*
* @param \App\Entity\Player\PlayerAvailability $availability
*
* @return Player
*/
public function addAvailability(\App\Entity\Player\PlayerAvailability $availability)
{
if (!$this->availabilities->contains($availability)) {
$this->availabilities[] = $availability;
}
return $this;
}
/**
* Remove availability
*
* @param \App\Entity\Player\PlayerAvailability $availability
*/
public function removeAvailability(\App\Entity\Player\PlayerAvailability $availability)
{
if ($this->availabilities->contains($availability)) {
$this->availabilities->removeElement($availability);
}
return $this;
}
/**
* Get availabilities
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAvailabilities()
{
return $this->availabilities;
}
/***********************
* OTHER FUNCTION
***********************/
public function updateFromJson($jsonObject){
if(isset($jsonObject->gimmick) && $jsonObject->gimmick != ""){
$this->setGimmick($jsonObject->gimmick);
}else{
$this->setGimmick(null);
}
if(isset($jsonObject->birthdate) && $jsonObject->birthdate != ""){
$this->setBirthdate(new \Datetime($jsonObject->birthdate));
}
if(isset($jsonObject->gender) && $jsonObject->gender != ""){
if($jsonObject->gender == 'MALE'){
$this->setGender('M');
}else{
$this->setGender('F');
}
}
if(isset($jsonObject->bestRankingDate) && $jsonObject->bestRankingDate != ""){
$this->setBestRankingDate(new \Datetime($jsonObject->bestRankingDate));
}
if(isset($jsonObject->hand) && $jsonObject->hand != ""){
$this->setHand($jsonObject->hand);
}
if(isset($jsonObject->nbPlayByWeek)){
$this->setNbPlayByWeek($jsonObject->nbPlayByWeek);
}
if(isset($jsonObject->favoritePlayerM)){
$this->setFavoritePlayerM($jsonObject->favoritePlayerM);
}
if(isset($jsonObject->favoritePlayerF)){
$this->setFavoritePlayerF($jsonObject->favoritePlayerF);
}
if(isset($jsonObject->bestMatchViewed)){
$this->setBestMatchViewed($jsonObject->bestMatchViewed);
}
if(isset($jsonObject->bestPerformance)){
$this->setBestPerformance($jsonObject->bestPerformance);
}
if(isset($jsonObject->bestPerformanceDate) && $jsonObject->bestPerformanceDate != ""){
$this->setBestPerformanceDate(new \Datetime($jsonObject->bestPerformanceDate));
}
}
public function getArrayForJson($userTools = null, $currentUser = null){
$array = array();
$array['id'] = $this->getId();
$array['gender'] = ($this->getGender() == 'F') ? 'FEMALE' : 'MALE';
$array['gimmick'] = $this->getGimmick();
if($this->getBirthdate())
$array['birthdate'] = $this->getBirthdate()->format("Y-m-d\TH:i:sP"); // 2013-12-19T00:00:00+01:00
if($this->getCurrentRanking()){
$array['currentRanking'] = $this->getCurrentRanking()->getArrayForJson();
if($userTools)
$array['correspondingRanking'] = $userTools->getStringCorrespondingRanking($currentUser, $this->getUser());
}
if($this->getBestRanking()){
$array['bestRanking'] = $this->getBestRanking()->getArrayForJson();
if($this->getBestRankingDate())
$array['bestRankingDate'] = $this->getBestRankingDate()->format("Y-m-d\TH:i:sP");
}
$array['hand'] = $this->getHand();
if($this->getPlayerType()){
$array['playerType'] = $this->getPlayerType()->getArrayForJson();
}
if($this->getBrandRacket()){
$array['brandRacket'] = $this->getBrandRacket()->getArrayForJson();
}
if($this->getBrandShoe()){
$array['brandShoe'] = $this->getBrandShoe()->getArrayForJson();
}
$array['nbPlayByWeek'] = $this->getNbPlayByWeek();
if($this->getNbTournamentByYear()){
$array['nbTournamentByYear'] = $this->getNbTournamentByYear()->getArrayForJson();
}
$array['favoritePlayerM'] = $this->getFavoritePlayerM();
$array['favoritePlayerF'] = $this->getFavoritePlayerF();
$array['bestPerformance'] = $this->getBestPerformance();
if($this->getBestPerformanceDate())
$array['bestPerformanceDate'] = $this->getBestPerformanceDate()->format("Y-m-d\TH:i:sP");
$array['bestMatchViewed'] = $this->getBestMatchViewed();
if(count($this->getWishes()) > 0){
$arrayWishes = array();
foreach($this->getWishes() as $wish){
$arrayWishes[] = $wish->getArrayForJson();
}
$array['wishes'] = $arrayWishes;
}
if(count($this->getAvailabilities()) > 0){
$arrayAvailabilities = array();
foreach($this->getAvailabilities() as $availability){
$arrayAvailabilities[] = $availability->getArrayForJson();
}
$array['availabilities'] = $arrayAvailabilities;
}
return $array;
}
}