Allow to add multiple participation

The participationController accept a new parameter : `persons_ids`,
which must receive a comma-separated list of person ids. A participation
will be create for all those peoples.

The `new` and `create` actions does not allow to receive both
`person_id` and `persons_ids`.

Tests are added.

ref #6
This commit is contained in:
2016-04-09 23:45:07 +02:00
parent bcfa2c2131
commit 9459d7a287
9 changed files with 626 additions and 31 deletions

View File

@@ -9,7 +9,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* Participation
*/
class Participation implements HasCenterInterface, HasScopeInterface
class Participation implements HasCenterInterface, HasScopeInterface, \ArrayAccess
{
/**
* @var integer
@@ -218,6 +218,11 @@ class Participation implements HasCenterInterface, HasScopeInterface
*/
public function isConsistent(ExecutionContextInterface $context)
{
if ($this->getEvent() === NULL || $this->getRole() === NULL || $this->getStatus() === NULL) {
return;
}
if ($this->getRole()->getType()->getId() !==
$this->getEvent()->getType()->getId()) {
$context->buildViolation('The role is not allowed with this event type')
@@ -233,4 +238,52 @@ class Participation implements HasCenterInterface, HasScopeInterface
}
}
public function offsetExists($offset)
{
return in_array($offset, array(
'person', 'role', 'status', 'event'
));
}
public function offsetGet($offset)
{
switch ($offset) {
case 'person':
return $this->getPerson();
break;
case 'role':
return $this->getRole();
break;
case 'status':
return $this->getStatus();
break;
case 'event':
return $this->getEvent();
break;
}
}
public function offsetSet($offset, $value)
{
switch($offset) {
case 'person':
return $this->setPerson($value);
break;
case 'role':
return $this->setRole($value);
break;
case 'status':
return $this->setStatus($value);
break;
case 'event':
return $this->setEvent($value);
break;
}
}
public function offsetUnset($offset)
{
$this->offsetSet($offset, null);
}
}