Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ungdev/site-etu
Browse files Browse the repository at this point in the history
  • Loading branch information
tgalopin committed May 28, 2014
2 parents 58f15c2 + d6404f5 commit d0bc990
Show file tree
Hide file tree
Showing 27 changed files with 551 additions and 162 deletions.
3 changes: 3 additions & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
50 changes: 50 additions & 0 deletions src/Etu/Core/CoreBundle/DataFixtures/ORM/LoadCitiesData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Etu\Core\CoreBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

use Etu\Core\CoreBundle\Entity\City;
use Etu\Core\CoreBundle\Entity\Page;

class LoadCitiesData extends AbstractFixture implements OrderedFixtureInterface
{
/**
* {@inheritDoc}
*/
public function getOrder()
{
return 2;
}

/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$troyes = new City();
$troyes->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);
}
}
18 changes: 17 additions & 1 deletion src/Etu/Module/ArgentiqueBundle/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down
114 changes: 103 additions & 11 deletions src/Etu/Module/CovoitBundle/Controller/PrivateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
]));
}
}
45 changes: 45 additions & 0 deletions src/Etu/Module/CovoitBundle/DataFixtures/ORM/LoadCovoitData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Etu\Module\BugsBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Etu\Module\CovoitBundle\Entity\Covoit;
use Faker\Factory;

class LoadCovoitData extends AbstractFixture implements OrderedFixtureInterface
{
/**
* {@inheritDoc}
*/
public function getOrder()
{
return 5;
}

/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$faker = Factory::create('fr_FR');

$covoit = new Covoit();
$covoit->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();
}
}
13 changes: 13 additions & 0 deletions src/Etu/Module/CovoitBundle/Entity/Covoit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
44 changes: 44 additions & 0 deletions src/Etu/Module/CovoitBundle/Notification/Helper/CanceledHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Etu\Module\CovoitBundle\Notification\Helper;

use Etu\Core\CoreBundle\Entity\Notification;
use Etu\Core\CoreBundle\Notification\Helper\HelperInterface;

/**
* Notification for an canceled covoit
*/
class CanceledHelper implements HelperInterface
{
/**
* @var \Twig_Environment
*/
protected $twig;

/**
* @param \Twig_Environment $twig
*/
public function __construct(\Twig_Environment $twig)
{
$this->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
));
}
}
7 changes: 7 additions & 0 deletions src/Etu/Module/CovoitBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
Loading

0 comments on commit d0bc990

Please sign in to comment.