diff --git a/src/Bundle/ChillMainBundle/Doctrine/Event/TrackCreateUpdateSubscriber.php b/src/Bundle/ChillMainBundle/Doctrine/Event/TrackCreateUpdateSubscriber.php index 222ed2213..3926e2062 100644 --- a/src/Bundle/ChillMainBundle/Doctrine/Event/TrackCreateUpdateSubscriber.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Event/TrackCreateUpdateSubscriber.php @@ -2,6 +2,7 @@ namespace Chill\MainBundle\Doctrine\Event; +use Chill\MainBundle\Entity\User; use Doctrine\Common\EventSubscriber; use Doctrine\ORM\Events; use Doctrine\Persistence\Event\LifecycleEventArgs; @@ -37,7 +38,8 @@ class TrackCreateUpdateSubscriber implements EventSubscriber { $object = $args->getObject(); - if ($object instanceof TrackCreationInterface) { + if ($object instanceof TrackCreationInterface + && $this->security->getUser() instanceof User) { $object->setCreatedBy($this->security->getUser()); $object->setCreatedAt(new \DateTimeImmutable('now')); } @@ -54,7 +56,8 @@ class TrackCreateUpdateSubscriber implements EventSubscriber protected function onUpdate(object $object): void { - if ($object instanceof TrackUpdateInterface) { + if ($object instanceof TrackUpdateInterface + && $this->security->getUser() instanceof User) { $object->setUpdatedBy($this->security->getUser()); $object->setUpdatedAt(new \DateTimeImmutable('now')); } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 69d461319..d5b43446c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -22,6 +22,8 @@ namespace Chill\PersonBundle\Entity; +use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; +use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; use Chill\MainBundle\Entity\Scope; use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; @@ -29,6 +31,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin; use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\ThirdPartyBundle\Entity\ThirdParty; +use DateTimeInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; @@ -46,7 +49,7 @@ use Symfony\Component\Serializer\Annotation\DiscriminatorMap; * "accompanying_period"=AccompanyingPeriod::class * }) */ -class AccompanyingPeriod +class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface { /** * Mark an accompanying period as "occasional" @@ -260,6 +263,23 @@ class AccompanyingPeriod */ private Collection $socialIssues; + /** + * @ORM\Column(type="datetime", nullable=true, options={"default": NULL}) + */ + private \DateTimeInterface $createdAt; + + /** + * @ORM\ManyToOne( + * targetEntity=User::class + * ) + */ + private User $updatedBy; + + /** + * @ORM\Column(type="datetime", nullable=true, options={"default": NULL}) + */ + private \DateTimeInterface $updatedAt; + /** * AccompanyingPeriod constructor. * @@ -789,4 +809,25 @@ class AccompanyingPeriod } ); } + + public function setCreatedAt(\DateTimeInterface $datetime): self + { + $this->createdAt = $datetime; + + return $this; + } + + public function setUpdatedBy(User $user): self + { + $this->updatedBy = $user; + + return $this; + } + + public function setUpdatedAt(\DateTimeInterface $datetime): self + { + $this->updatedAt = $datetime; + + return $this; + } } diff --git a/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php b/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php index 74052e87c..e9ce20b53 100644 --- a/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php +++ b/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php @@ -3,6 +3,7 @@ namespace Chill\PersonBundle\Menu; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Knp\Menu\MenuItem; use Symfony\Contracts\Translation\TranslatorInterface; @@ -32,24 +33,31 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface public function buildMenu($menuId, MenuItem $menu, array $parameters): void { + $period = $parameters['accompanyingCourse']; + $menu->addChild($this->translator->trans('Resume Accompanying Course'), [ 'route' => 'chill_person_accompanying_course_index', 'routeParameters' => [ - 'accompanying_period_id' => $parameters['accompanyingCourse']->getId() + 'accompanying_period_id' => $period->getId() ]]) ->setExtras(['order' => 10]); $menu->addChild($this->translator->trans('Edit Accompanying Course'), [ 'route' => 'chill_person_accompanying_course_show', 'routeParameters' => [ - 'accompanying_period_id' => $parameters['accompanyingCourse']->getId() + 'accompanying_period_id' => $period->getId() ]]) ->setExtras(['order' => 20]); + if (AccompanyingPeriod::STEP_DRAFT === $period->getStep()) { + // no more menu items if the period is draft + return; + } + $menu->addChild($this->translator->trans('Accompanying Course Details'), [ 'route' => 'chill_person_accompanying_course_history', 'routeParameters' => [ - 'accompanying_period_id' => $parameters['accompanyingCourse']->getId() + 'accompanying_period_id' => $period->getId() ]]) ->setExtras(['order' => 30]); } diff --git a/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php b/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php index ea6a1d060..0b307204d 100644 --- a/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php +++ b/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php @@ -71,6 +71,14 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface 'icons' => [ 'plus' ] ]); } + + $menu->addChild($this->translator->trans('Create an accompanying course'), [ + 'route' => 'chill_person_accompanying_course_new' + ]) + ->setExtras([ + 'order' => 11, + 'icons' => [ 'plus' ] + ]); } /** diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/banner.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/banner.html.twig index c8d566e84..94663e2f0 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/banner.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/banner.html.twig @@ -12,19 +12,17 @@
- {{ 'Started on %date%'|trans({'%date%': accompanyingCourse.openingDate|format_date('short') } ) }}
- {% if accompanyingCourse.user is not null %}
- par {{ accompanyingCourse.user.usernameCanonical }}
+ {% if 'DRAFT' == accompanyingCourse.getStep() %}
+ Brouillon
+ {% else %}
+ {{ 'Started on %date%'|trans({'%date%': accompanyingCourse.openingDate|format_date('short') } ) }}
+ {% if accompanyingCourse.user is not null %}
+ par {{ accompanyingCourse.user.username }}
+ {% endif %}
{% endif %}
-{{ accompanyingCourse.id }} -{{ accompanyingCourse.openingDate|format_date('short') }} -{{ accompanyingCourse.closingDate|format_date('short') }} -{{ accompanyingCourse.closingMotive|chill_entity_render_box }} -{{ accompanyingCourse.remark|raw }} -{{ accompanyingCourse.user }} -usagers: -{% for p in accompanyingCourse.participations %} - {{ p.person.id }} | {{ p.person.fullnamecanonical }} | {{ p.startdate|format_date('short') }} | {{ p.enddate|format_date('short') }} -{% endfor %} -+