Skip to content

Instantly share code, notes, and snippets.

@jschroed91
Created March 4, 2015 17:40
Show Gist options
  • Save jschroed91/82be8891204583183b50 to your computer and use it in GitHub Desktop.
Save jschroed91/82be8891204583183b50 to your computer and use it in GitHub Desktop.
canReattach
public function canReattach()
{
$filterFunction = function ($collaborator) {
return in_array($collaborator->getRole()->getName(), array(Role::PROPONENT, coproponent)) && $collaborator->getStatus()->getName() == CollaboratorStatus::ACCEPTED;
});
$parentCollaborators = $this->getParentProposal()->getCollaborators()->filter($filterFunction);
$childCollaborators = $this->getProposal()->getCollaborators()->filter($filterFunction);
if ($parentCollaborators->count() !== $childCollaborators->count()) {
return false;
}
foreach ($parentCollaborators as $collaborator) {
$found = false;
foreach ($childCollaborators as $childCollab) {
if ($childCollab->getUser()->getId() === $collaborator->getUser()->getId()) {
if ($collaborator->getRole()->getId() === $childCollab->getRole()->getId()) {
$found = true;
}
}
}
if (!$found) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment