mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
A first VueJS component, get api datas, a simple button add person
* !! composer require serializer !! * see: http://localhost:8001/fr/parcours/861/show
This commit is contained in:
@@ -3,10 +3,18 @@
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
/**
|
||||
* Class AccompanyingCourseController
|
||||
@@ -27,7 +35,7 @@ class AccompanyingCourseController extends Controller
|
||||
'accompanyingCourse' => $accompanyingCourse
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show page of Accompanying Course section
|
||||
*
|
||||
@@ -43,7 +51,7 @@ class AccompanyingCourseController extends Controller
|
||||
'accompanyingCourse' => $accompanyingCourse
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* History page of Accompanying Course section
|
||||
*
|
||||
@@ -58,6 +66,53 @@ class AccompanyingCourseController extends Controller
|
||||
'accompanyingCourse' => $accompanyingCourse
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sérialise temporairement quelques données pour donner à manger au composant vuejs
|
||||
* @Route(
|
||||
* "/{_locale}/api/parcours/{accompanying_period_id}/show",
|
||||
* name="chill_person_accompanying_course_api_show")
|
||||
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
|
||||
* @param SerializerInterface $serializer
|
||||
*/
|
||||
public function showAPI(AccompanyingPeriod $accompanyingCourse): Response
|
||||
{
|
||||
$persons = [];
|
||||
foreach ($accompanyingCourse->getParticipations() as $k => $participation ) {
|
||||
/**
|
||||
* @var AccompanyingPeriodParticipation $participation
|
||||
* @var Person $person
|
||||
*/
|
||||
$person = $participation->getPerson();
|
||||
$persons[$k] = [
|
||||
'firstname' => $person->getFirstName(),
|
||||
'lastname' => $person->getLastName(),
|
||||
'email' => $person->getEmail(),
|
||||
'phone' => $person->getPhonenumber(),
|
||||
'startdate' => ($participation->getStartDate()) ? $participation->getStartDate()->format('Y-m-d') : null,
|
||||
'enddate' => ($participation->getEndDate()) ? $participation->getEndDate()->format('Y-m-d') : null
|
||||
];
|
||||
}
|
||||
$data = [
|
||||
'id' => $accompanyingCourse->getId(),
|
||||
'remark' => $accompanyingCourse->getRemark(),
|
||||
'closing_motive' => $accompanyingCourse->getClosingMotive()->getName()['fr'],
|
||||
'opening_date' => ($accompanyingCourse->getOpeningDate()) ? $accompanyingCourse->getOpeningDate()->format('Y-m-d') : null,
|
||||
'closing_date' => ($accompanyingCourse->getClosingDate()) ? $accompanyingCourse->getClosingDate()->format('Y-m-d') : null,
|
||||
'persons' => $persons
|
||||
];
|
||||
|
||||
$normalizer = [new ObjectNormalizer()];
|
||||
$encoder = [new JsonEncoder()];
|
||||
|
||||
$serializer = new Serializer($normalizer, $encoder);
|
||||
$serialized = $serializer->serialize($data,'json', []);
|
||||
|
||||
$response = new Response($serialized);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user