Created
August 25, 2011 18:30
-
-
Save cowlby/1171391 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use DateTime; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert; | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="challenges") | |
* @DoctrineAssert\UniqueEntity(fields="slug", message="That slug is already in use.") | |
*/ | |
class Challenge | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
protected $id; | |
/** | |
* @Assert\NotBlank() | |
* @ORM\Column(type="string") | |
*/ | |
protected $name; | |
/** | |
* @ORM\OneToOne(targetEntity="Owner", mappedBy="challenge") | |
*/ | |
protected $owner; | |
/** | |
* @ORM\OneToOne(targetEntity="Rival", mappedBy="challenge") | |
*/ | |
protected $rival; | |
public function getId() | |
{ | |
return $this->id; | |
} | |
public function getName() | |
{ | |
return $this->name; | |
} | |
public function setName($name) | |
{ | |
$this->name = $name; | |
return $this; | |
} | |
public function setOwner(Owner $owner) | |
{ | |
$this->owner = $owner; | |
$owner->setChallenge($this); | |
return $this; | |
} | |
public function getOwner() | |
{ | |
return $this->owner; | |
} | |
public function setRival(Rival $rival) | |
{ | |
$this->rival = $rival; | |
$rival->setChallenge($this); | |
return $this; | |
} | |
public function getRival() | |
{ | |
return $this->rival; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="owners") | |
*/ | |
class Owner extends Participant | |
{ | |
/** | |
* @ORM\OneToOne(targetEntity="Challenge", mappedBy="owner") | |
*/ | |
protected $challenge; | |
public function setChallenge(Challenge $challenge) | |
{ | |
$this->challenge = $challenge; | |
} | |
public function getChallenge() | |
{ | |
return $this->challenge; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use DateTime; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
/** | |
* @ORM\Entity | |
* @ORM\HasLifecycleCallbacks | |
* @ORM\InheritanceType("JOINED") | |
* @ORM\DiscriminatorColumn(name="type", type="string") | |
* @ORM\DiscriminatorMap({ | |
* "owner" = "Owner", | |
* "rival" = "Rival" | |
* }) | |
* @ORM\Table(name="participants", | |
* uniqueConstraints={ | |
* @ORM\UniqueConstraint(name="uix_participants_userId_challengeId", columns={ | |
* "userId", | |
* "challengeId" | |
* }) | |
* } | |
* ) | |
*/ | |
class Participant | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
protected $id; | |
/** | |
* @ORM\Column(type="integer") | |
*/ | |
protected $challengeId; | |
/** | |
* @ORM\Column(type="integer") | |
*/ | |
protected $userId; | |
/** | |
* @ORM\ManyToOne(targetEntity="User") | |
* @ORM\JoinColumn(name="userId", referencedColumnName="id") | |
*/ | |
protected $user; | |
public function getId() | |
{ | |
return $this->id; | |
} | |
public function setUserId($userId) | |
{ | |
$this->userId = $userId; | |
} | |
public function getUserId() | |
{ | |
return $this->userId; | |
} | |
public function setChallengeId($challengeId) | |
{ | |
$this->challengeId = $challengeId; | |
} | |
public function getChallengeId() | |
{ | |
return $this->challengeId; | |
} | |
public function setUser(User $user) | |
{ | |
$this->user = $user; | |
} | |
public function getUser() | |
{ | |
return $this->user; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="rivals") | |
*/ | |
class Rival extends Participant | |
{ | |
/** | |
* @ORM\OneToOne(targetEntity="Challenge", mappedBy="rival") | |
*/ | |
protected $challenge; | |
public function setChallenge(Challenge $challenge) | |
{ | |
$this->challenge = $challenge; | |
} | |
public function getChallenge() | |
{ | |
return $this->challenge; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use DateTime; | |
use FOS\UserBundle\Entity\User as BaseUser; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Entity | |
* @ORM\HasLifecycleCallbacks | |
* @ORM\Table(name="users") | |
*/ | |
class User extends BaseUser | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
protected $id | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment