mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -251,7 +251,7 @@ class AccompanyingPeriod
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getClosingDate()
|
||||
public function getClosingDate(): ?\DateTime
|
||||
{
|
||||
return $this->closingDate;
|
||||
}
|
||||
@@ -425,15 +425,17 @@ class AccompanyingPeriod
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isClosingAfterOpening()
|
||||
public function isClosingAfterOpening(): bool
|
||||
{
|
||||
$diff = $this->getOpeningDate()->diff($this->getClosingDate());
|
||||
|
||||
if ($diff->invert === 0) {
|
||||
return true;
|
||||
} else {
|
||||
if (null === $this->getClosingDate()) {
|
||||
return false;
|
||||
}
|
||||
$diff = $this->getOpeningDate()->diff($this->getClosingDate());
|
||||
|
||||
if ($diff->invert === 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getUser(): ?User
|
||||
@@ -447,8 +449,8 @@ class AccompanyingPeriod
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrigin(): Origin
|
||||
|
||||
public function getOrigin(): ?Origin
|
||||
{
|
||||
return $this->origin;
|
||||
}
|
||||
@@ -539,8 +541,8 @@ class AccompanyingPeriod
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStep(): string
|
||||
|
||||
public function getStep(): ?string
|
||||
{
|
||||
return $this->step;
|
||||
}
|
||||
@@ -551,8 +553,8 @@ class AccompanyingPeriod
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIntensity(): string
|
||||
|
||||
public function getIntensity(): ?string
|
||||
{
|
||||
return $this->intensity;
|
||||
}
|
||||
|
@@ -369,7 +369,7 @@ class Person implements HasCenterInterface
|
||||
/**
|
||||
* Return the opened accompanying period.
|
||||
*/
|
||||
public function getOpenedAccompanyingPeriod() : AccompanyingPeriod
|
||||
public function getOpenedAccompanyingPeriod() : ?AccompanyingPeriod
|
||||
{
|
||||
if ($this->isOpen() === false) {
|
||||
return null;
|
||||
|
@@ -8,6 +8,7 @@
|
||||
|
||||
<h1>{{ block('title') }}</h1>
|
||||
|
||||
{#
|
||||
<pre>
|
||||
{{ accompanyingCourse.id }}
|
||||
{{ accompanyingCourse.openingDate|format_date('short') }}
|
||||
@@ -20,10 +21,9 @@ usagers:
|
||||
{{ p.person.id }} | <a href="{{ path('chill_person_accompanying_period_list', { person_id: p.person.id }) }}">{{ p.person.fullnamecanonical }}</a> | {{ p.startdate|format_date('short') }} | {{ p.enddate|format_date('short') }}
|
||||
{% endfor %}
|
||||
</pre>
|
||||
|
||||
{{ dump() }}
|
||||
#}
|
||||
|
||||
<h3>TESTS AREA vuejs:</h3>
|
||||
{% verbatim %}
|
||||
<div id="app" data-name="{{ app.user.username }}"></div>
|
||||
{% endverbatim %}
|
||||
|
@@ -38,3 +38,6 @@ services:
|
||||
$personMove: '@Chill\PersonBundle\Actions\Remove\PersonMove'
|
||||
$eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface'
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
Chill\PersonBundle\Controller\AccompanyingCourseController:
|
||||
tags: ['controller.service_arguments']
|
||||
|
Reference in New Issue
Block a user