Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace LDMR\FormBundle\Controller;
- use LDMR\CommonBundle\Controller\AbstractBaseController;
- use LDMR\FormBundle\Repository\LuluFormRepository;
- use Nelmio\ApiDocBundle\Annotation\ApiDoc;
- use \Exception;
- class LuluFormController extends AbstractBaseController
- {
- /**
- * {@inheritdoc}
- *
- * @ApiDoc(
- * section="LuluForm",
- * description="Get a filled form from unique form id and lulu id",
- * statusCodes={
- * 401="Returned when the User is not authenticated",
- * 200="Returned when successful",
- * 404="Returned when the form is not found",
- * },
- * )
- *
- */
- public function getAction(string $uniqueId, int $id)
- {
- // check logged employee exists
- try {
- $currentUserEmployee = $this->getEmployeeRepository()->getOneByCriteria(['userId' => $this->getUser()->getId()]);
- if (!$currentUserEmployee) {
- throw new Exception(sprintf('Employee %s not found', $this->getUser()->getId()));
- }
- }
- catch(Exception $e) {
- return $this->getClientErrorResponseBuilder()->forbidden();
- }
- // check lulu exists
- try {
- $lulu = $this->getLuluRepository()->getOneByCriteria(['id' => $id]);
- if (!$lulu) {
- throw new Exception(sprintf('Lulu %s not found', $this->getUser()->getId()));
- }
- }
- catch(Exception $e) {
- return $this->getClientErrorResponseBuilder()->notFound();
- }
- /** @var LuluFormRepository $luluFormRepo **/
- $luluFormRepo = $this->getDoctrine()->getRepository('LDMRFormBundle:LuluForm');
- try {
- $luluForm = $luluFormRepo->getFormattedLuluFormAnswers($uniqueId, $id);
- if (!$luluForm) {
- throw new Exception(sprintf('LuluForm %s not found', $uniqueId));
- }
- }
- catch(Exception $e) {
- return $this->getClientErrorResponseBuilder()->notFound();
- }
- return $this->getSuccessResponseBuilder()->buildSingleObjectResponse(
- $luluForm,
- [
- 'luluFormForm',
- 'formDownwards',
- 'topicDownwards',
- 'questionLuluAnswers',
- ]
- );
- }
- /**
- * {@inheritdoc}
- *
- * @ApiDoc(
- * section="LuluForm",
- * description="Get the list of forms for a lulu",
- * statusCodes={
- * 401="Returned when the User is not authenticated",
- * 200="Returned when successful",
- * 404="Returned when the form is not found"
- * },
- * )
- *
- */
- public function listAction(int $id)
- {
- // check logged employee exists
- try {
- $currentUserEmployee = $this->getEmployeeRepository()->getOneByCriteria(['userId' => $this->getUser()->getId()]);
- if (!$currentUserEmployee) {
- throw new Exception(sprintf('Employee %s not found', $this->getUser()->getId()));
- }
- }
- catch(Exception $e) {
- return $this->getClientErrorResponseBuilder()->forbidden();
- }
- // check lulu exists
- try {
- $lulu = $this->getLuluRepository()->getOneByCriteria(['id' => $id]);
- if (!$lulu) {
- throw new Exception(sprintf('Lulu %s not found', $this->getUser()->getId()));
- }
- }
- catch(Exception $e) {
- return $this->getClientErrorResponseBuilder()->notFound();
- }
- try {
- /** @var LuluFormRepository $luluFormRepo **/
- $luluFormRepo = $this->getDoctrine()->getRepository('LDMRFormBundle:LuluForm');
- $forms = $luluFormRepo->findObjectsBy(
- ['lulu' => $lulu],
- ['form', 'followupEmployee']
- );
- }
- catch (Exception $e) {
- $forms = [];
- }
- return $this->getSuccessResponseBuilder()->buildPaginationListResponse(
- $forms,
- [
- 'luluFormForm',
- 'luluFormFollowupEmployee',
- ]
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement