Created
November 12, 2014 17:51
-
-
Save jschroed91/6f55c632590e1d97ace8 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* @param Request $request | |
* @param AbstractProposal $proposal | |
* @param string $type | |
* | |
* @return Response | |
* | |
* @Route("/{id}/import/{type}", requirements={"id" = "\d+"}, name="import_proposal_object", options={"expose":true}) | |
*/ | |
public function importAction(Request $request, AbstractProposal $proposal, $type) | |
{ | |
if (!$this->checkPrivilege(Privilege::EDIT_PROPOSAL, $proposal)){ | |
return $this->createJsonResponse(false, 'proposal.permission.edit_proposal', 403); | |
} | |
$proposalObjectsManager = $this->container->get('proposal_objects.manager'); | |
$ids = $request->get('ids', array()); | |
$return = array(); | |
foreach ($ids as $id) { | |
$importedObject = $proposalObjectsManager->import($type, $proposal, array('id' => $id)); | |
if (!$importedObject instanceof AbstractProposalObject) { | |
return $this->createJsonResponse(false, "Unable to import " . $type, 500); | |
} | |
$return[] = $importedObject; | |
} | |
$this->getEm()->flush(); | |
return new \Symfony\Component\HttpFoundation\JsonResponse($this->serializeProposalObject($return)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment