add the possibility to add a participation of a person to an event

ref #5
This commit is contained in:
2016-03-24 01:44:32 +01:00
parent 167a147f52
commit 627b9fb08f
13 changed files with 489 additions and 5 deletions

View File

@@ -2,10 +2,14 @@
namespace Chill\EventBundle\Entity;
use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\MainBundle\Entity\HasCenterInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* Participation
*/
class Participation
class Participation implements HasCenterInterface, HasScopeInterface
{
/**
* @var integer
@@ -183,4 +187,50 @@ class Participation
{
return $this->status;
}
public function getCenter()
{
if ($this->getEvent() === NULL) {
throw new \RuntimeException('The event is not linked with this instance. '
. 'You should initialize the event with a valid center before.');
}
return $this->getEvent()->getCenter();
}
public function getScope()
{
if ($this->getEvent() === NULL) {
throw new \RuntimeException('The event is not linked with this instance. '
. 'You should initialize the event with a valid center before.');
}
return $this->getEvent()->getCircle();
}
/**
* Check that :
*
* - the role can be associated with this event type
* - the status can be associated with this event type
*
* @param ExecutionContextInterface $context
*/
public function isConsistent(ExecutionContextInterface $context)
{
if ($this->getRole()->getType()->getId() !==
$this->getEvent()->getType()->getId()) {
$context->buildViolation('The role is not allowed with this event type')
->atPath('role')
->addViolation();
}
if ($this->getStatus()->getType()->getId() !==
$this->getEvent()->getType()->getId()) {
$context->buildViolation('The status is not allowed with this event type')
->atPath('status')
->addViolation();
}
}
}