diff --git a/app/AppKernel.php b/app/AppKernel.php index 8691faa06..209464581 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -55,6 +55,9 @@ public function registerBundles() // BBCode new FM\BbcodeBundle\FMBbcodeBundle(), + // Date and times translations + new Sonata\IntlBundle\SonataIntlBundle(), + // API documentation new Nelmio\ApiDocBundle\NelmioApiDocBundle(), diff --git a/composer.json b/composer.json index fc14b914c..ca0f9765c 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ "fzaninotto/faker": "~1.3", "nelmio/api-doc-bundle": "2.5.*", "dopiaza/dpzflickr": "1.2.*", - "jasig/phpcas": "dev-master" + "jasig/phpcas": "dev-master", + "sonata-project/intl-bundle": "2.2.*" }, "scripts": { "post-install-cmd": [ diff --git a/src/Etu/Core/CoreBundle/DataFixtures/ORM/LoadCitiesData.php b/src/Etu/Core/CoreBundle/DataFixtures/ORM/LoadCitiesData.php new file mode 100644 index 000000000..935921a3a --- /dev/null +++ b/src/Etu/Core/CoreBundle/DataFixtures/ORM/LoadCitiesData.php @@ -0,0 +1,50 @@ +setName('Troyes') + ->setSlug('troyes') + ->setPostalCodes('10000') + ->setPopulation(60280) + ->setLatitude(48.3) + ->setLongitude(4.08333); + + $paris = new City(); + $paris->setName('Paris') + ->setSlug('paris') + ->setPostalCodes('75001|75002|75003|75004|75005|75006|75007|75008|75009|75010|75011|75012|75013|75014|75015|75016|75017|75018|75019|75020|75116') + ->setPopulation(2243833) + ->setLatitude(48.86) + ->setLongitude(2.34445); + + $manager->persist($troyes); + $manager->persist($paris); + $manager->flush(); + + $this->addReference('city_troyes', $troyes); + $this->addReference('city_paris', $paris); + } +} \ No newline at end of file diff --git a/src/Etu/Module/ArgentiqueBundle/Controller/AdminController.php b/src/Etu/Module/ArgentiqueBundle/Controller/AdminController.php index cad798a1e..1ac8c68f3 100644 --- a/src/Etu/Module/ArgentiqueBundle/Controller/AdminController.php +++ b/src/Etu/Module/ArgentiqueBundle/Controller/AdminController.php @@ -394,6 +394,9 @@ public function synchronizePhotoAction($photoId) // Flickr $flickr = $this->createFlickrAccess(); + // Imagine + $imagine = new \Imagine\Gd\Imagine(); + // Get database photo /** @var Photo $photo */ $photo = $em->getRepository('EtuModuleArgentiqueBundle:Photo')->find($photoId); @@ -409,7 +412,20 @@ public function synchronizePhotoAction($photoId) file_put_contents($uploadDir.'/'.$photo->getId().'_t.jpg', file_get_contents($sizes['sizes']['size'][2]['source'])); // Original - file_put_contents($uploadDir.'/'.$photo->getId().'_o.jpg', file_get_contents($sizes['sizes']['size'][9]['source'])); + $image = $imagine->open($sizes['sizes']['size'][9]['source']); + + $width = $image->getSize()->getWidth(); + $height = $image->getSize()->getHeight(); + + if ($width > $height) { + $box = new \Imagine\Image\Box(1500, 1500 * ($height / $width)); + } elseif ($width < $height) { + $box = new \Imagine\Image\Box(1500 * ($width / $height), 1500); + } else { + $box = new \Imagine\Image\Box(1500, 1500); + } + + $image->resize($box)->save($uploadDir.'/'.$photo->getId().'_o.jpg'); $photo->setFile($photo->getId().'_o.jpg'); $photo->setIcon($photo->getId().'_t.jpg'); diff --git a/src/Etu/Module/CovoitBundle/Controller/PrivateController.php b/src/Etu/Module/CovoitBundle/Controller/PrivateController.php index 3a7fd70bb..df21b0501 100644 --- a/src/Etu/Module/CovoitBundle/Controller/PrivateController.php +++ b/src/Etu/Module/CovoitBundle/Controller/PrivateController.php @@ -255,6 +255,72 @@ public function editMessageAction(Request $request, CovoitMessage $message) ]; } + /** + * @Route("/{id}/cancel/{confirm}", defaults={"confirm" = false}, name="covoiturage_my_cancel") + * @Template() + */ + public function cancelAction($id, $confirm) + { + if (! $this->getUserLayer()->isUser()) { + return $this->createAccessDeniedResponse(); + } + + /** @var EntityManager $em */ + $em = $this->getDoctrine()->getManager(); + + /** @var Covoit $covoit */ + $covoit = $em->createQueryBuilder() + ->select('c, s, e, a') + ->from('EtuModuleCovoitBundle:Covoit', 'c') + ->leftJoin('c.author', 'a') + ->leftJoin('c.startCity', 's') + ->leftJoin('c.endCity', 'e') + ->where('c.id = :id') + ->setParameter('id', $id) + ->getQuery() + ->getOneOrNullResult(); + + if (! $covoit) { + throw $this->createNotFoundException('Covoit not found'); + } + + if ($covoit->getAuthor()->getId() != $this->getUser()->getId()) { + throw new AccessDeniedHttpException(); + } + + if ($confirm) { + $covoit->getStartCity(); + $covoit->getEndCity(); + + $em->remove($covoit); + $em->flush(); + + $notif = new Notification(); + + $notif + ->setModule($this->getCurrentBundle()->getIdentifier()) + ->setHelper('covoit_canceled') + ->setAuthorId($this->getUser()->getId()) + ->setEntityType('covoit') + ->setEntityId($covoit->getId()) + ->addEntity($covoit); + + $this->getNotificationsSender()->send($notif); + + // Flash message + $this->get('session')->getFlashBag()->set('message', array( + 'type' => 'success', + 'message' => 'covoit.messages.canceled' + )); + + return $this->redirect($this->generateUrl('covoiturage_my_index')); + } + + return [ + 'covoit' => $covoit, + ]; + } + /** * @Route("/{id}/subscribe", name="covoiturage_my_subscribe") */ @@ -286,14 +352,14 @@ public function subscribeAction($id) if (! $this->getUser()->getPhoneNumber()) { $this->get('session')->getFlashBag()->set('message', array( - 'type' => 'error', - 'message' => 'covoit.messages.required_phone' - )); + 'type' => 'error', + 'message' => 'covoit.messages.required_phone' + )); } elseif ($covoit->hasUser($this->getUser())) { $this->get('session')->getFlashBag()->set('message', array( - 'type' => 'error', - 'message' => 'covoit.messages.already_subscribed' - )); + 'type' => 'error', + 'message' => 'covoit.messages.already_subscribed' + )); } else { $subscription = new CovoitSubscription(); $subscription->setCovoit($covoit); @@ -323,14 +389,40 @@ public function subscribeAction($id) $this->getSubscriptionsManager()->subscribe($this->getUser(), 'covoit', $covoit->getId()); $this->get('session')->getFlashBag()->set('message', array( - 'type' => 'success', - 'message' => 'covoit.messages.subscribed' - )); + 'type' => 'success', + 'message' => 'covoit.messages.subscribed' + )); } return $this->redirect($this->generateUrl('covoiturage_view', [ - 'id' => $covoit->getId(), - 'slug' => $covoit->getStartCity()->getSlug() . '-' . $covoit->getEndCity()->getSlug() + 'id' => $covoit->getId(), + 'slug' => $covoit->getStartCity()->getSlug() . '-' . $covoit->getEndCity()->getSlug() + ])); + } + + /** + * @Route("/{id}/unsubscribe", name="covoiturage_my_subscribe") + */ + public function unsubscribeAction(CovoitSubscription $subscription) + { + if (! $this->getUserLayer()->isUser()) { + return $this->createAccessDeniedResponse(); + } + + /** @var EntityManager $em */ + $em = $this->getDoctrine()->getManager(); + + $em->remove($subscription); + $em->flush(); + + $this->get('session')->getFlashBag()->set('message', array( + 'type' => 'success', + 'message' => 'covoit.messages.unsubscribed' + )); + + return $this->redirect($this->generateUrl('covoiturage_view', [ + 'id' => $subscription->getCovoit()->getId(), + 'slug' => $subscription->getCovoit()->getStartCity()->getSlug() . '-' . $subscription->getCovoit()->getEndCity()->getSlug() ])); } } diff --git a/src/Etu/Module/CovoitBundle/DataFixtures/ORM/LoadCovoitData.php b/src/Etu/Module/CovoitBundle/DataFixtures/ORM/LoadCovoitData.php new file mode 100644 index 000000000..8dbfaac4f --- /dev/null +++ b/src/Etu/Module/CovoitBundle/DataFixtures/ORM/LoadCovoitData.php @@ -0,0 +1,45 @@ +setAuthor($this->getReference('user_user')); + $covoit->setStartCity($this->getReference('city_troyes')); + $covoit->setEndCity($this->getReference('city_paris')); + $covoit->setStartAdress($faker->text(150)); + $covoit->setEndAdress($faker->text(150)); + $covoit->setStartHour('16:00'); + $covoit->setEndHour('19:00'); + $covoit->setCapacity(rand(2, 5)); + $covoit->setDate($faker->dateTimeThisYear); + $covoit->setPhoneNumber($faker->phoneNumber); + $covoit->setPrice(rand(15, 35)); + $covoit->setNotes($faker->text(250)); + + $manager->persist($covoit); + $manager->flush(); + } +} \ No newline at end of file diff --git a/src/Etu/Module/CovoitBundle/Entity/Covoit.php b/src/Etu/Module/CovoitBundle/Entity/Covoit.php index df55743c5..81e5b7313 100644 --- a/src/Etu/Module/CovoitBundle/Entity/Covoit.php +++ b/src/Etu/Module/CovoitBundle/Entity/Covoit.php @@ -391,6 +391,19 @@ public function getDate() return $this->date; } + /** + * Get date + * + * @return \DateTime + */ + public function hasCancelationExpired() + { + $expirationDate = clone $this->date; + $expirationDate->modify('-2 days'); + + return new \DateTime() > $expirationDate; + } + /** * Set blablacarUrl * diff --git a/src/Etu/Module/CovoitBundle/Notification/Helper/CanceledHelper.php b/src/Etu/Module/CovoitBundle/Notification/Helper/CanceledHelper.php new file mode 100644 index 000000000..3542358e2 --- /dev/null +++ b/src/Etu/Module/CovoitBundle/Notification/Helper/CanceledHelper.php @@ -0,0 +1,44 @@ +twig = $twig; + } + + /** + * @return string + */ + public function getName() + { + return 'covoit_canceled'; + } + + /** + * @param Notification $notification + * @return string + */ + public function render(Notification $notification) + { + return $this->twig->render('EtuModuleCovoitBundle:Notification:canceled.html.twig', array( + 'notif' => $notification + )); + } +} \ No newline at end of file diff --git a/src/Etu/Module/CovoitBundle/Resources/config/services.yml b/src/Etu/Module/CovoitBundle/Resources/config/services.yml index 7f0c47c50..5eb98baab 100644 --- a/src/Etu/Module/CovoitBundle/Resources/config/services.yml +++ b/src/Etu/Module/CovoitBundle/Resources/config/services.yml @@ -11,6 +11,7 @@ parameters: etu.covoit.notifs.new_message.class: Etu\Module\CovoitBundle\Notification\Helper\NewMessageHelper etu.covoit.notifs.edited.class: Etu\Module\CovoitBundle\Notification\Helper\EditedHelper + etu.covoit.notifs.canceled.class: Etu\Module\CovoitBundle\Notification\Helper\CanceledHelper etu.covoit.notifs.alert.class: Etu\Module\CovoitBundle\Notification\Helper\AlertHelper etu.covoit.notifs.subscription.class: Etu\Module\CovoitBundle\Notification\Helper\SubscriptionHelper @@ -51,6 +52,12 @@ services: tags: - { name: etu.notifs_helper } + etu.covoit.notifs.canceled: + class: %etu.covoit.notifs.canceled.class% + arguments: [@twig] + tags: + - { name: etu.notifs_helper } + etu.covoit.notifs.alert: class: %etu.covoit.notifs.alert.class% arguments: [@twig] diff --git a/src/Etu/Module/CovoitBundle/Resources/translations/messages.fr.yml b/src/Etu/Module/CovoitBundle/Resources/translations/messages.fr.yml index 5621f04bb..3427f76b6 100644 --- a/src/Etu/Module/CovoitBundle/Resources/translations/messages.fr.yml +++ b/src/Etu/Module/CovoitBundle/Resources/translations/messages.fr.yml @@ -6,6 +6,7 @@ covoit: alerts: Mes alertes notifs: + canceled: Le covoiturage %start% - %end% de %author% le %date% a été annulé par son créateur edited: Le covoiturage %start% - %end% de %author% le %date% a été modifié alert: Le covoiturage %start% - %end% de %author% le %date% pourrait vous intéresser new_message: %author% a posté un message sur le covoiturage %start% - %end% du %date% @@ -14,10 +15,12 @@ covoit: messages: created: Votre proposition a bien été créée edited: Votre covoiturage a bien été modifié + canceled: Votre covoiturage a bien été annulé message_sent: Votre message a bien été envoyé message_edited: Votre message a bien été modifié already_subscribed: Vous êtes déjà inscrit à ce covoiturage subscribed: Vous avez bien réservé une place dans ce covoiturage + unsubscribed: Vous avez bien annulé votre réservation dans ce covoiturage alert_created: Votre alerte a bien été crée alert_edited: Votre alerte a bien été modifiée alert_deleted: Votre alerte a bien été supprimée @@ -54,6 +57,7 @@ covoit: start: Le %date% à %startHour% end: (pour une arrivée vers %endHour% à %endCity%) startAdress: Adresse de départ + endAdress: Adresse d'arrivée price: Prix (par place) places_left: label: Places disponibles @@ -65,11 +69,10 @@ covoit: comments: Commentaires no_comment: Aucun commentaire pour le moment comment: Ajouter le commentaire + cancel: Annuler ma réservation private_index: title: Mes covoiturages - from_to: De %startCity% à %endCity% - date: Le %date% à %hour% subscriptions_left: none_or_one: place
restante|some: places
restantes per_place: par place creator: Créateur @@ -121,9 +124,16 @@ covoit: private_edit: title: Modifier un covoiturage + delete: Annuler ce covoiturage submit: Modifier cancel: Annuler + private_delete: + title: Annuler un covoiturage + question: Voulez-vous vraiment supprimer le covoiturage %start% %end% du %date% ?
Cette action est irréversible. + yes: Oui, le supprimer + no: Non, annuler + private_edit_message: title: Modifier un message submit: Modifier le message diff --git a/src/Etu/Module/CovoitBundle/Resources/translations/validators.es.yml b/src/Etu/Module/CovoitBundle/Resources/translations/validators.es.yml new file mode 100644 index 000000000..e69de29bb diff --git a/src/Etu/Module/CovoitBundle/Resources/views/Notification/alert.html.twig b/src/Etu/Module/CovoitBundle/Resources/views/Notification/alert.html.twig index 2acbd7d2b..54fb4a6ca 100644 --- a/src/Etu/Module/CovoitBundle/Resources/views/Notification/alert.html.twig +++ b/src/Etu/Module/CovoitBundle/Resources/views/Notification/alert.html.twig @@ -9,7 +9,7 @@ {{ 'covoit.notifs.alert'|trans({ '%start%': highlight_notif_data(covoit.startCity.name), '%end%': highlight_notif_data(covoit.endCity.name), - '%date%': highlight_notif_data(covoit.date|date('d/m/Y')), + '%date%': highlight_notif_data(covoit.date|format_date), '%author%': highlight_notif_data(covoit.author.fullName) })|raw }} diff --git a/src/Etu/Module/CovoitBundle/Resources/views/Notification/canceled.html.twig b/src/Etu/Module/CovoitBundle/Resources/views/Notification/canceled.html.twig new file mode 100644 index 000000000..245f6c7f9 --- /dev/null +++ b/src/Etu/Module/CovoitBundle/Resources/views/Notification/canceled.html.twig @@ -0,0 +1,22 @@ + +{% set covoit = notif.firstEntity %} + + + + +

+ {{ 'covoit.notifs.canceled'|trans({ + '%start%': highlight_notif_data(covoit.startCity.name), + '%end%': highlight_notif_data(covoit.endCity.name), + '%date%': highlight_notif_data(covoit.date|format_date), + '%author%': highlight_notif_data(covoit.author.fullName) + })|raw }} +

+ +
+ {{ time_diff(notif.date)|ucfirst }} +
+ +
+
\ No newline at end of file diff --git a/src/Etu/Module/CovoitBundle/Resources/views/Notification/edited.html.twig b/src/Etu/Module/CovoitBundle/Resources/views/Notification/edited.html.twig index 19c54ac31..c372cc91d 100644 --- a/src/Etu/Module/CovoitBundle/Resources/views/Notification/edited.html.twig +++ b/src/Etu/Module/CovoitBundle/Resources/views/Notification/edited.html.twig @@ -9,7 +9,7 @@ {{ 'covoit.notifs.edited'|trans({ '%start%': highlight_notif_data(covoit.startCity.name), '%end%': highlight_notif_data(covoit.endCity.name), - '%date%': highlight_notif_data(covoit.date|date('d/m/Y')), + '%date%': highlight_notif_data(covoit.date|format_date), '%author%': highlight_notif_data(covoit.author.fullName) })|raw }} diff --git a/src/Etu/Module/CovoitBundle/Resources/views/Notification/newMessage.html.twig b/src/Etu/Module/CovoitBundle/Resources/views/Notification/newMessage.html.twig index 4c1ec1d46..a17941220 100644 --- a/src/Etu/Module/CovoitBundle/Resources/views/Notification/newMessage.html.twig +++ b/src/Etu/Module/CovoitBundle/Resources/views/Notification/newMessage.html.twig @@ -10,7 +10,7 @@ {{ 'covoit.notifs.new_message'|trans({ '%start%': highlight_notif_data(covoit.startCity.name), '%end%': highlight_notif_data(covoit.endCity.name), - '%date%': highlight_notif_data(covoit.date|date('d/m/Y')), + '%date%': highlight_notif_data(covoit.date|format_date), '%author%': highlight_notif_data(message.author.fullName) })|raw }} diff --git a/src/Etu/Module/CovoitBundle/Resources/views/Notification/subscription.html.twig b/src/Etu/Module/CovoitBundle/Resources/views/Notification/subscription.html.twig index c036e7560..85c9e0c02 100644 --- a/src/Etu/Module/CovoitBundle/Resources/views/Notification/subscription.html.twig +++ b/src/Etu/Module/CovoitBundle/Resources/views/Notification/subscription.html.twig @@ -10,7 +10,7 @@ {{ 'covoit.notifs.subscription'|trans({ '%start%': highlight_notif_data(covoit.startCity.name), '%end%': highlight_notif_data(covoit.endCity.name), - '%date%': highlight_notif_data(covoit.date|date('d/m/Y')), + '%date%': highlight_notif_data(covoit.date|format_date), '%name%': highlight_notif_data(covoit.author.fullName) })|raw }} diff --git a/src/Etu/Module/CovoitBundle/Resources/views/Private/cancel.html.twig b/src/Etu/Module/CovoitBundle/Resources/views/Private/cancel.html.twig new file mode 100644 index 000000000..32cb88ae0 --- /dev/null +++ b/src/Etu/Module/CovoitBundle/Resources/views/Private/cancel.html.twig @@ -0,0 +1,34 @@ +{% extends '::page-2cols.html.twig' %} + +{% block title %}{{ 'covoit.private_delete.title'|trans }}{% endblock %} + +{% block titleIcon %} + {{ 'base.logo.alt'|trans }} +{% endblock %} + +{% block content %} + {% include 'EtuModuleCovoitBundle::menu.html.twig' with {'active': 'none'} %} + +
+
+ +

+ {{ 'covoit.private_delete.question'|trans({ + '%start%': covoit.startCity.name, + '%end%': covoit.endCity.name, + '%date%': covoit.date|format_date + })|raw }} +

+ +
+ +

+ + Oui, le supprimer + + + Non, annuler + +

+
+{% endblock %} diff --git a/src/Etu/Module/CovoitBundle/Resources/views/Private/index.html.twig b/src/Etu/Module/CovoitBundle/Resources/views/Private/index.html.twig index 9ac92cc87..d97fa07d1 100644 --- a/src/Etu/Module/CovoitBundle/Resources/views/Private/index.html.twig +++ b/src/Etu/Module/CovoitBundle/Resources/views/Private/index.html.twig @@ -67,48 +67,43 @@ class="covoit-list-item{% if today > covoit.date %} covoit-list-item-done{% endif %}">
-
- {{ covoit.capacity - (covoit.subscriptions|length) }} +
+ {{ covoit.capacity - (covoit.subscriptions|length) }}
{{ 'covoit.private_index.subscriptions_left'|transchoice(covoit.capacity - (covoit.subscriptions|length))|raw }}
-
- {{ covoit.price }} € +
+ + {{ covoit.price }} € +
{{ 'covoit.private_index.per_place'|trans }}
-
- {% if covoit.author.id == app.user.id %} - {{ 'covoit.private_index.creator'|trans }} - {% else %} - {{ 'covoit.private_index.subscribed'|trans }} - {% endif %} +
+ + {{ covoit.date|format_date }} + +
+ {{ covoit.startHour|format_time(null, null, null, constant('IntlDateFormatter::SHORT')) }}
- {{ 'covoit.private_index.from_to'|trans({ - '%startCity%': covoit.startCity.name, - '%endCity%': covoit.endCity.name - }) }} + {{ covoit.startCity.name }} + {{ covoit.endCity.name }}
- - {{ 'covoit.private_index.date'|trans({ - '%date%': covoit.date|date('d/m/Y'), - '%hour%': covoit.startHour|date('H:i') - }) }} - + {{ covoit.author.fullName }}
{% else %}

{{ 'covoit.private_index.no_covoit.text'|trans }} - - {{ 'covoit.private_index.no_covoit.link'|trans }} - -

+ + {{ 'covoit.private_index.no_covoit.link'|trans }} + +

{% endfor %}