diff --git a/CHANGELOG.md b/CHANGELOG.md
index bfb349b2e..53339485c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to
* [person] suggest entities (person | thirdparty) when creating/editing the accompanying course (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/119)
+* [activity] add custom validation on the Activity class, based on what is required from the ActivityType (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/188)
* [main] translate multiselect messages when selecting/creating address
* [main] set the coordinates of the city when creating a new address OR choosing "pas d'adresse complète"
* Use the user.label in accompanying course banner, instead of username;
@@ -21,7 +22,10 @@ and this project adheres to
* [activity] check ACL on activity list in person context
* [list for accompanying course in person] filter list using ACL
* [validation] toasts are displayed for errors when modifying accompanying course (generalization required).
+* [period] only the user can enable confidentiality
* add an endpoint for checking permissions. See https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/232
+* [activity] for a new activity: suggest and create on-the-fly locations based on the accompanying course location + location of the suggested parties
+* [calendar] for a new rdv: suggest and create on-the-fly locations based on the accompanying course location + location of the suggested parties
## Test releases
diff --git a/phpstan-critical.neon b/phpstan-critical.neon
index 6147f2022..b214654bf 100644
--- a/phpstan-critical.neon
+++ b/phpstan-critical.neon
@@ -70,11 +70,6 @@ parameters:
count: 1
path: src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php
- -
- message: "#^Undefined variable\\: \\$value$#"
- count: 1
- path: src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/LocationValidityValidator.php
-
-
message: "#^Undefined variable\\: \\$choiceSlug$#"
count: 1
diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php
index f4248b5e8..0f725c2b3 100644
--- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php
+++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php
@@ -137,7 +137,7 @@ final class ActivityController extends AbstractController
static fn (ActivityReason $ar): int => $ar->getId()
)
->toArray(),
- 'type_id' => $activity->getType()->getId(),
+ 'type_id' => $activity->getActivityType()->getId(),
'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null,
'date' => $activity->getDate()->format('Y-m-d'),
'attendee' => $activity->getAttendee(),
@@ -194,7 +194,7 @@ final class ActivityController extends AbstractController
$form = $this->createForm(ActivityType::class, $entity, [
'center' => $entity->getCenter(),
'role' => new Role('CHILL_ACTIVITY_UPDATE'),
- 'activityType' => $entity->getType(),
+ 'activityType' => $entity->getActivityType(),
'accompanyingPeriod' => $accompanyingPeriod,
])->handleRequest($request);
@@ -327,7 +327,7 @@ final class ActivityController extends AbstractController
$entity->setAccompanyingPeriod($accompanyingPeriod);
}
- $entity->setType($activityType);
+ $entity->setActivityType($activityType);
$entity->setDate(new DateTime('now'));
if ($request->query->has('activityData')) {
@@ -385,7 +385,7 @@ final class ActivityController extends AbstractController
$form = $this->createForm(ActivityType::class, $entity, [
'center' => $entity->getCenter(),
'role' => new Role('CHILL_ACTIVITY_CREATE'),
- 'activityType' => $entity->getType(),
+ 'activityType' => $entity->getActivityType(),
'accompanyingPeriod' => $accompanyingPeriod,
])->handleRequest($request);
@@ -408,7 +408,7 @@ final class ActivityController extends AbstractController
$activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
- $defaultLocationId = $this->getUser()->getCurrentLocation()->getId();
+ $defaultLocation = $this->getUser()->getCurrentLocation();
return $this->render($view, [
'person' => $person,
@@ -416,7 +416,7 @@ final class ActivityController extends AbstractController
'entity' => $entity,
'form' => $form->createView(),
'activity_json' => $activity_array,
- 'default_location_id' => $defaultLocationId,
+ 'default_location' => $defaultLocation,
]);
}
diff --git a/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeController.php b/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeController.php
index 140a0b855..81c978bf2 100644
--- a/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeController.php
+++ b/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeController.php
@@ -23,6 +23,7 @@ class AdminActivityTypeController extends CRUDController
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator)
{
/** @var \Doctrine\ORM\QueryBuilder $query */
- return $query->orderBy('e.ordering', 'ASC');
+ return $query->orderBy('e.ordering', 'ASC')
+ ->addOrderBy('e.id', 'ASC');
}
}
diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php
index 85abed5e5..c63ce90f7 100644
--- a/src/Bundle/ChillActivityBundle/Entity/Activity.php
+++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php
@@ -9,6 +9,7 @@
namespace Chill\ActivityBundle\Entity;
+use Chill\ActivityBundle\Validator\Constraints as ActivityValidator;
use Chill\DocStoreBundle\Entity\Document;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
@@ -41,6 +42,7 @@ use Symfony\Component\Serializer\Annotation\SerializedName;
* @DiscriminatorMap(typeProperty="type", mapping={
* "activity": Activity::class
* })
+ * @ActivityValidator\ActivityValidity
*/
/*
@@ -202,7 +204,9 @@ class Activity implements HasCenterInterface, HasScopeInterface, AccompanyingPer
public function addPerson(?Person $person): self
{
if (null !== $person) {
- $this->persons[] = $person;
+ if (!$this->persons->contains($person)) {
+ $this->persons[] = $person;
+ }
}
return $this;
@@ -236,7 +240,9 @@ class Activity implements HasCenterInterface, HasScopeInterface, AccompanyingPer
public function addThirdParty(?ThirdParty $thirdParty): self
{
if (null !== $thirdParty) {
- $this->thirdParties[] = $thirdParty;
+ if (!$this->thirdParties->contains($thirdParty)) {
+ $this->thirdParties[] = $thirdParty;
+ }
}
return $this;
@@ -245,7 +251,9 @@ class Activity implements HasCenterInterface, HasScopeInterface, AccompanyingPer
public function addUser(?User $user): self
{
if (null !== $user) {
- $this->users[] = $user;
+ if (!$this->users->contains($user)) {
+ $this->users[] = $user;
+ }
}
return $this;
diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php
index 0e9b1150a..4cb4250b5 100644
--- a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php
+++ b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php
@@ -12,6 +12,7 @@ namespace Chill\ActivityBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use Symfony\Component\Serializer\Annotation\Groups;
+use Symfony\Component\Validator\Constraints as Assert;
/**
* Class ActivityType.
@@ -29,11 +30,13 @@ class ActivityType
public const FIELD_REQUIRED = 2;
/**
+ * @deprecated not in use
* @ORM\Column(type="string", nullable=false, options={"default": ""})
*/
private string $accompanyingPeriodLabel = '';
/**
+ * @deprecated not in use
* @ORM\Column(type="smallint", nullable=false, options={"default": 1})
*/
private int $accompanyingPeriodVisible = self::FIELD_INVISIBLE;
@@ -195,16 +198,21 @@ class ActivityType
/**
* @ORM\Column(type="smallint", nullable=false, options={"default": 1})
+ * @Assert\EqualTo(propertyPath="socialIssuesVisible", message="This parameter must be equal to social issue parameter")
*/
private int $socialActionsVisible = self::FIELD_INVISIBLE;
/**
* @ORM\Column(type="string", nullable=false, options={"default": ""})
+ *
+ * @deprecated not in use
*/
private string $socialDataLabel = '';
/**
* @ORM\Column(type="smallint", nullable=false, options={"default": 1})
+ *
+ * @deprecated not in use
*/
private int $socialDataVisible = self::FIELD_INVISIBLE;
@@ -260,16 +268,6 @@ class ActivityType
*/
private int $userVisible = self::FIELD_REQUIRED;
- public function getAccompanyingPeriodLabel(): string
- {
- return $this->accompanyingPeriodLabel;
- }
-
- public function getAccompanyingPeriodVisible(): int
- {
- return $this->accompanyingPeriodVisible;
- }
-
/**
* Get active
* return true if the type is active.
@@ -446,16 +444,6 @@ class ActivityType
return $this->socialActionsVisible;
}
- public function getSocialDataLabel(): string
- {
- return $this->socialDataLabel;
- }
-
- public function getSocialDataVisible(): int
- {
- return $this->socialDataVisible;
- }
-
public function getSocialIssuesLabel(): ?string
{
return $this->socialIssuesLabel;
@@ -537,20 +525,6 @@ class ActivityType
return self::FIELD_INVISIBLE !== $this->{$property};
}
- public function setAccompanyingPeriodLabel(string $accompanyingPeriodLabel): self
- {
- $this->accompanyingPeriodLabel = $accompanyingPeriodLabel;
-
- return $this;
- }
-
- public function setAccompanyingPeriodVisible(int $accompanyingPeriodVisible): self
- {
- $this->accompanyingPeriodVisible = $accompanyingPeriodVisible;
-
- return $this;
- }
-
/**
* Set active
* set to true if the type is active.
@@ -768,20 +742,6 @@ class ActivityType
return $this;
}
- public function setSocialDataLabel(string $socialDataLabel): self
- {
- $this->socialDataLabel = $socialDataLabel;
-
- return $this;
- }
-
- public function setSocialDataVisible(int $socialDataVisible): self
- {
- $this->socialDataVisible = $socialDataVisible;
-
- return $this;
- }
-
public function setSocialIssuesLabel(string $socialIssuesLabel): self
{
$this->socialIssuesLabel = $socialIssuesLabel;
diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php b/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php
index 300be5c4c..682d73aaf 100644
--- a/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php
+++ b/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php
@@ -56,7 +56,7 @@ class ActivityTypeType extends AbstractType
'persons', 'user', 'date', 'place', 'persons',
'thirdParties', 'durationTime', 'travelTime', 'attendee',
'reasons', 'comment', 'sentReceived', 'documents',
- 'emergency', 'accompanyingPeriod', 'socialData', 'users',
+ 'emergency', 'socialIssues', 'socialActions', 'users',
];
foreach ($fields as $field) {
diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/App.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/App.vue
index 52454c2f7..2fb9d022d 100644
--- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/App.vue
+++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/App.vue
@@ -1,7 +1,7 @@
-
- {{ entity.location.locationType.title|localize_translatable_string }} {{ entity.location.name }} + ({{ entity.location.locationType.title|localize_translatable_string }})
{{ entity.location.address|chill_entity_render_box }} {% else %} diff --git a/src/Bundle/ChillActivityBundle/Validator/Constraints/ActivityValidity.php b/src/Bundle/ChillActivityBundle/Validator/Constraints/ActivityValidity.php new file mode 100644 index 000000000..6164c3c5d --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Validator/Constraints/ActivityValidity.php @@ -0,0 +1,42 @@ +getActivityType()->getPersonsVisible() === 2 && count($activity->getPersons()) === 0) { + $this->context + ->buildViolation($constraint->noPersonsMessage) + ->addViolation(); + } + + if ($activity->getActivityType()->getUsersVisible() === 2 && count($activity->getUsers()) === 0) { + $this->context + ->buildViolation($constraint->noUsersMessage) + ->addViolation(); + } + + if ($activity->getActivityType()->getThirdPartiesVisible() === 2 && count($activity->getThirdParties()) === 0) { + $this->context + ->buildViolation($constraint->noThirdPartiesMessage) + ->addViolation(); + } + + if ($activity->getActivityType()->getUserVisible() === 2 && null === $activity->getUser()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('user')) + ->addViolation(); + } + + if ($activity->getActivityType()->getDateVisible() === 2 && null === $activity->getDate()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('date')) + ->addViolation(); + } + + if ($activity->getActivityType()->getLocationVisible() === 2 && null === $activity->getLocation()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('location')) + ->addViolation(); + } + + if ($activity->getActivityType()->getDurationTimeVisible() === 2 && null === $activity->getDurationTime()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('duration time')) + ->addViolation(); + } + + if ($activity->getActivityType()->getTravelTimeVisible() === 2 && null === $activity->getTravelTime()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('travel time')) + ->addViolation(); + } + + if ($activity->getActivityType()->getAttendeeVisible() === 2 && null === $activity->getAttendee()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('attendee')) + ->addViolation(); + } + + if ($activity->getActivityType()->getReasonsVisible() === 2 && null === $activity->getReasons()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('reasons')) + ->addViolation(); + } + + if ($activity->getActivityType()->getCommentVisible() === 2 && null === $activity->getComment()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('comment')) + ->addViolation(); + } + + if ($activity->getActivityType()->getSentReceivedVisible() === 2 && null === $activity->getSentReceived()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('sent/received')) + ->addViolation(); + } + + if ($activity->getActivityType()->getDocumentsVisible() === 2 && null === $activity->getDocuments()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('document')) + ->addViolation(); + } + + if ($activity->getActivityType()->getEmergencyVisible() === 2 && null === $activity->getEmergency()) { + $this->context + ->buildViolation($constraint->makeIsRequiredMessage('emergency')) + ->addViolation(); + } + + if ($activity->getActivityType()->getSocialIssuesVisible() === 2 && $activity->getSocialIssues()->count() === 0) { + $this->context + ->buildViolation($constraint->socialIssuesMessage) + ->addViolation(); + } + + if ($activity->getActivityType()->getSocialActionsVisible() === 2 && $activity->getSocialActions()->count() === 0) { + $this->context + ->buildViolation($constraint->socialActionsMessage) + ->addViolation(); + } + } +} diff --git a/src/Bundle/ChillActivityBundle/config/services.yaml b/src/Bundle/ChillActivityBundle/config/services.yaml index 4e93e38be..1ca413f0e 100644 --- a/src/Bundle/ChillActivityBundle/config/services.yaml +++ b/src/Bundle/ChillActivityBundle/config/services.yaml @@ -27,3 +27,8 @@ services: Chill\ActivityBundle\Repository\: resource: '../Repository/' + + Chill\ActivityBundle\Validator\Constraints\: + autowire: true + autoconfigure: true + resource: '../Validator/Constraints/' diff --git a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml index d0c3ddc6d..959eee233 100644 --- a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml @@ -139,34 +139,40 @@ ActivityReasonCategory is inactive and won't be proposed: La catégorie est inac # activity type type admin ActivityType list: Types d'activités Create a new activity type: Créer un nouveau type d'activité -Persons visible: Visibilté du champ Personnes +Persons visible: Visibilité du champ Personnes Persons label: Libellé du champ Personnes -User visible: Visibilté du champ Utilisateur +User visible: Visibilité du champ Utilisateur User label: Libellé du champ Utilisateur -Date visible: Visibilté du champ Date +Date visible: Visibilité du champ Date Date label: Libellé du champ Date -Place visible: Visibilté du champ Lieu +Place visible: Visibilité du champ Lieu Place label: Libellé du champ Lieu -Third parties visible: Visibilté du champ Tiers +Third parties visible: Visibilité du champ Tiers Third parties label: Libellé du champ Tiers -Duration time visible: Visibilté du champ Durée +Duration time visible: Visibilité du champ Durée Duration time label: Libellé du champ Durée -Travel time visible: Visibilté du champ Durée de déplacement +Travel time visible: Visibilité du champ Durée de déplacement Travel time label: Libellé du champ Durée de déplacement -Attendee visible: Visibilté du champ Présence de l'usager +Attendee visible: Visibilité du champ Présence de l'usager Attendee label: Libellé du champ Présence de l'usager -Reasons visible: Visibilté du champ Sujet +Reasons visible: Visibilité du champ Sujet Reasons label: Libellé du champ Sujet -Comment visible: Visibilté du champ Commentaire +Comment visible: Visibilité du champ Commentaire Comment label: Libellé du champ Commentaire -Emergency visible: Visibilté du champ Urgent +Emergency visible: Visibilité du champ Urgent Emergency label: Libellé du champ Urgent -Accompanying period visible: Visibilté du champ Période d'accompagnement +Accompanying period visible: Visibilité du champ Période d'accompagnement Accompanying period label: Libellé du champ Période d'accompagnement -Social data visible: Visibilté du champ Données sociales -Social data label: Libellé du champ Données sociales -Users visible: Visibilté du champ Utilisateurs +Social issues visible: Visibilité du champ Problématiques sociales +Social issues label: Libellé du champ Problématiques sociales +Social actions visible: Visibilité du champ Action sociale +Social actions label: Libellé du champ Action sociale +Users visible: Visibilité du champ Utilisateurs Users label: Libellé du champ Utilisateurs +Sent received visible: Visibilité du champ Entrant / Sortant +Sent received label: Libellé du champ Entrant / Sortant +Documents visible: Visibilité du champ Documents +Documents label: Libellé du champ Documents # activity type category admin ActivityTypeCategory list: Liste des catégories des types d'activité diff --git a/src/Bundle/ChillActivityBundle/translations/validators.fr.yml b/src/Bundle/ChillActivityBundle/translations/validators.fr.yml index edda0b67b..072ac55d2 100644 --- a/src/Bundle/ChillActivityBundle/translations/validators.fr.yml +++ b/src/Bundle/ChillActivityBundle/translations/validators.fr.yml @@ -1,2 +1,22 @@ The reasons's level should not be empty: Le niveau du sujet ne peut pas être vide At least one reason must be choosen: Au moins un sujet doit être choisi +For this type of activity, you must add at least one person: Pour ce type d'activité, vous devez ajouter au moins un usager +For this type of activity, you must add at least one user: Pour ce type d'activité, vous devez ajouter au moins un utilisateur +For this type of activity, you must add at least one third party: Pour ce type d'activité, vous devez ajouter au moins un tiers +For this type of activity, user is required: Pour ce type d'activité, l'utilisateur est requis +For this type of activity, date is required: Pour ce type d'activité, la date est requise +For this type of activity, location is required: Pour ce type d'activité, la localisation est requise +For this type of activity, attendee is required: Pour ce type d'activité, le champ "Présence de la personne" est requis +For this type of activity, duration time is required: Pour ce type d'activité, la durée est requise +For this type of activity, travel time is required: Pour ce type d'activité, la durée du trajet est requise +For this type of activity, reasons is required: Pour ce type d'activité, le champ "sujet" est requis +For this type of activity, comment is required: Pour ce type d'activité, un commentaire est requis +For this type of activity, sent/received is required: Pour ce type d'activité, le champ Entrant/Sortant est requis +For this type of activity, document is required: Pour ce type d'activité, un document est requis +For this type of activity, emergency is required: Pour ce type d'activité, le champ "Urgent" est requis +For this type of activity, accompanying period is required: Pour ce type d'activité, le parcours d'accompagnement est requis +For this type of activity, you must add at least one social issue: Pour ce type d'activité, vous devez ajouter au moins une problématique sociale +For this type of activity, you must add at least one social action: Pour ce type d'activité, vous devez indiquez au moins une action sociale + +# admin +This parameter must be equal to social issue parameter: Ce paramètre doit être égal au paramètre "Visibilité du champs Problématiques sociales" diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 0165142f7..6e6bce842 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -332,12 +332,12 @@ class CalendarController extends AbstractController $personsId = array_map( static fn (Person $p): int => $p->getId(), - $entity->getPersons() + $entity->getPersons()->toArray() ); $professionalsId = array_map( static fn (ThirdParty $thirdParty): ?int => $thirdParty->getId(), - $entity->getProfessionals() + $entity->getProfessionals()->toArray() ); $durationTime = $entity->getEndDate()->diff($entity->getStartDate()); diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store.js b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store.js index 457d31799..edfb7f236 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store.js +++ b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store.js @@ -1,5 +1,6 @@ import 'es6-promise/auto'; import { createStore } from 'vuex'; +import { postLocation } from 'ChillActivityAssets/vuejs/Activity/api'; const debug = process.env.NODE_ENV !== 'production'; @@ -33,7 +34,6 @@ const store = createStore({ }, getters: { suggestedEntities(state) { - console.log(state.activity) if (typeof(state.activity.accompanyingPeriod) === 'undefined') { return []; } @@ -189,8 +189,35 @@ const store = createStore({ updateLocation({ commit }, value) { console.log('### action: updateLocation', value); let hiddenLocation = document.getElementById("chill_calendarbundle_calendar_location"); - hiddenLocation.value = value.id; - commit('updateLocation', value); + if (value.onthefly) { + const body = { + "type": "location", + "name": value.name === '__AccompanyingCourseLocation__' ? null : value.name, + "locationType": { + "id": value.locationType.id, + "type": "location-type" + } + }; + if (value.address.id) { + Object.assign(body, { + "address": { + "id": value.address.id + }, + }) + } + postLocation(body) + .then( + location => hiddenLocation.value = location.id + ).catch( + err => { + console.log(err.message); + } + ); + } else { + hiddenLocation.value = value.id; + } + commit("updateLocation", value); + } } diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig index 5dfde6fc3..7c59996d2 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig @@ -41,8 +41,8 @@- {{ entity.location.locationType.title|localize_translatable_string }} {{ entity.location.name }} + ({{ entity.location.locationType.title|localize_translatable_string }})
{{ entity.location.address|chill_entity_render_box }} {% else %} diff --git a/src/Bundle/ChillMainBundle/Controller/LocationApiController.php b/src/Bundle/ChillMainBundle/Controller/LocationApiController.php index 52b6f1e81..16fc414d9 100644 --- a/src/Bundle/ChillMainBundle/Controller/LocationApiController.php +++ b/src/Bundle/ChillMainBundle/Controller/LocationApiController.php @@ -10,8 +10,6 @@ namespace Chill\MainBundle\Controller; use Chill\MainBundle\CRUD\Controller\ApiController; -use DateInterval; -use DateTime; use Symfony\Component\HttpFoundation\Request; /** @@ -21,22 +19,11 @@ class LocationApiController extends ApiController { public function customizeQuery(string $action, Request $request, $query): void { - $query->andWhere($query->expr()->orX( - $query->expr()->andX( - $query->expr()->eq('e.createdBy', ':user'), - $query->expr()->gte('e.createdAt', ':dateBefore') - ), + $query->andWhere( $query->expr()->andX( $query->expr()->eq('e.availableForUsers', "'TRUE'"), $query->expr()->eq('e.active', "'TRUE'"), - $query->expr()->isNotNull('e.name'), - $query->expr()->neq('e.name', ':emptyString'), ) - )) - ->setParameters([ - 'user' => $this->getUser(), - 'dateBefore' => (new DateTime())->sub(new DateInterval('P6M')), - 'emptyString' => '', - ]); + ); } } diff --git a/src/Bundle/ChillMainBundle/Entity/LocationType.php b/src/Bundle/ChillMainBundle/Entity/LocationType.php index 8b171eb0f..b0d91a4f1 100644 --- a/src/Bundle/ChillMainBundle/Entity/LocationType.php +++ b/src/Bundle/ChillMainBundle/Entity/LocationType.php @@ -11,6 +11,7 @@ namespace Chill\MainBundle\Entity; use Chill\MainBundle\Repository\LocationTypeRepository; use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; @@ -20,9 +21,14 @@ use Symfony\Component\Serializer\Annotation\DiscriminatorMap; * @DiscriminatorMap(typeProperty="type", mapping={ * "location-type": LocationType::class * }) + * @UniqueEntity({"defaultFor"}) */ class LocationType { + public const DEFAULT_FOR_3PARTY = 'thirdparty'; + + public const DEFAULT_FOR_PERSON = 'person'; + public const STATUS_NEVER = 'never'; public const STATUS_OPTIONAL = 'optional'; @@ -53,6 +59,12 @@ class LocationType */ private string $contactData = self::STATUS_OPTIONAL; + /** + * @ORM\Column(type="string", nullable=true, length=32, unique=true) + * @Serializer\Groups({"read"}) + */ + private ?string $defaultFor = null; + /** * @ORM\Id * @ORM\GeneratedValue @@ -87,6 +99,11 @@ class LocationType return $this->contactData; } + public function getDefaultFor(): ?string + { + return $this->defaultFor; + } + public function getId(): ?int { return $this->id; @@ -125,6 +142,13 @@ class LocationType return $this; } + public function setDefaultFor(?string $defaultFor): self + { + $this->defaultFor = $defaultFor; + + return $this; + } + public function setTitle(array $title): self { $this->title = $title; diff --git a/src/Bundle/ChillMainBundle/Form/LocationTypeType.php b/src/Bundle/ChillMainBundle/Form/LocationTypeType.php index 1e4776f8f..41372b48e 100644 --- a/src/Bundle/ChillMainBundle/Form/LocationTypeType.php +++ b/src/Bundle/ChillMainBundle/Form/LocationTypeType.php @@ -71,6 +71,18 @@ final class LocationTypeType extends AbstractType ], 'expanded' => true, ] + ) + ->add( + 'defaultFor', + ChoiceType::class, + [ + 'choices' => [ + 'none' => null, + 'person' => LocationType::DEFAULT_FOR_PERSON, + 'thirdparty' => LocationType::DEFAULT_FOR_3PARTY, + ], + 'expanded' => true, + ] ); } } diff --git a/src/Bundle/ChillMainBundle/Resources/public/lib/api/apiMethods.js b/src/Bundle/ChillMainBundle/Resources/public/lib/api/apiMethods.js index 5b49ba546..96a95ad93 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/lib/api/apiMethods.js +++ b/src/Bundle/ChillMainBundle/Resources/public/lib/api/apiMethods.js @@ -10,7 +10,6 @@ body: (body !== null) ? JSON.stringify(body) : null }) .then(response => { - if (response.ok) { return response.json(); } diff --git a/src/Bundle/ChillMainBundle/Resources/views/LocationType/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/LocationType/index.html.twig index ec617c6c0..5402d5e89 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/LocationType/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/LocationType/index.html.twig @@ -11,6 +11,7 @@