Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CTRV/CommonBundle/CTRVCommonBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace CTRV\CommonBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class CTRVCommonBundle extends Bundle
{
}
75 changes: 75 additions & 0 deletions CTRV/CommonBundle/Controller/AbusController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace CTRV\CommonBundle\Controller;

use Doctrine\ORM\EntityRepository;

use Symfony\Component\HttpFoundation\Response;

use CTRV\CommonBundle\DependencyInjection\Constants;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use JMS\SecurityExtraBundle\Annotation\Secure;
use CTRV\CommonBundle\Entity\Abuse;
/**
* Abuse controller.
*
* @Route("/abuse")
*/
class AbusController extends Controller
{

/**
* @Route("/list",name="abuse")
* @Template()
* Retourne la liste de tous les Abus
*/
public function allAbuseAction(){

$currentCity = $this->get("session_service")->getCity();
$city = $this->getDoctrine()->getEntityManager()->getRepository('CTRVCommonBundle:City')->find($currentCity->getId());

if ($currentCity == null) {
$this->get('session')->getFlashBag()->add('error', $this->get('translator')->trans('session.city.not_found'));
$this->redirect($this->generateUrl("home"));
}

$page = intval ($this->getRequest()->get("page",1));
//pagination
$nb_entities = $abuses = $this->getDoctrine()->getRepository('CTRVCommonBundle:Abuse')->getAllAbuseNumber($city);
$nb_entities_page = Constants::abuse_number_per_page;
$nb_pages = ceil($nb_entities/$nb_entities_page);
$offset = ($page-1) * $nb_entities_page;

$abusesPublicMessage = $this->getDoctrine()->getRepository("CTRVCommonBundle:Abuse")->getAllPublicMessageAbuses($city, $offset, $nb_entities_page);
$abusesComment = $this->getDoctrine()->getRepository("CTRVCommonBundle:Abuse")->getAllCommentAbuses($city, $offset, $nb_entities_page);
$abuses = $abusesPublicMessage;
$abuses = array_merge($abuses, $abusesComment );

return array (
'entities' => $abuses,
'nb_pages' => $nb_pages,
'page' => $page,
'nb_entities' => $nb_entities
);
}

/**
* Supprimer un abus
*
* @Route("/{id}/delete", name="abuse_delete" ) //requirements={"id" = "\d+"}
* @Method("POST")
* @Template()
*/
public function deleteAction($id) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('CTRVCommonBundle:Comment')->find($id);

$em->remove($entity);
$em->flush();

return new Response(json_encode(array('result'=>true)));
}
}
112 changes: 112 additions & 0 deletions CTRV/CommonBundle/Controller/AuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace CTRV\CommonBundle\Controller;

use CTRV\CommonBundle\Form\RegistrationType;

use Symfony\Component\Security\Core\SecurityContext;

use CTRV\CommonBundle\Form\UserAuthType;

use Symfony\Component\HttpFoundation\Response;

use CTRV\CommonBundle\DependencyInjection\Constants;

use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use CTRV\CommonBundle\Entity\User;
use JMS\SecurityExtraBundle\Annotation\Secure;


/**
* User controller.
*
*
*/
class AuthController extends Controller
{

/**
* Affiche le formulaire de connexion
* @Template()
*/
public function loginAction () {

$request = $this->getRequest();
$session = $request->getSession();

// get the login error if there is one
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(
SecurityContext::AUTHENTICATION_ERROR
);
} else {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}

return array(
// last username entered by the user
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error
);
}

/**
* Affiche la page indiquant que vous n'avez pas les droits d'acces
* @Route("/insufficient_access",name="insufficient_access")
* @Template()
*/
public function insufficientAccessAction () {

$referer = $this->getRequest()->headers->get('referer');
return array("url"=>$referer);
}

/**
* Afficher et traite le formulaire d'inscription d'un utilisateur
* @Route("/register",name="register")
* @Template()
* @Secure(roles="ROLE_ADMIN")
*/
public function registerAction () {

$em = $this->getDoctrine()->getEntityManager();
$form = $this->createForm(new RegistrationType(), new User());

if ($this->getRequest()->getMethod()=="POST") {

$form->bind($this->getRequest());

if ($form->isValid()) {

$user = $form->getData();
$userid = hash('ripemd160',$user->getLogin().$user->getEmail().date('d/m/y-H:i:s'));

$encoder = $this->get('password_service');

$role = $this->getDoctrine()->getEntityManager()->getRepository("CTRVCommonBundle:Role")->findOneBy(array("name"=>Constants::ROLE_USER));

$user->setSalt(uniqid(mt_rand()));
$user->setRole($role);
$user->setUserid($userid);
$user->setPassword($encoder->encodePassword($user->getPassword(), $user->getSalt()));
$user->setIsActive(true);
$user->setIsBlocked(false);

$em->persist($user);
$em->flush();

return $this->redirect($this->generateUrl("home"));
}
}

return array('form' => $form->createView());
}


}
133 changes: 133 additions & 0 deletions CTRV/CommonBundle/Controller/CityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

namespace CTRV\CommonBundle\Controller;

use Doctrine\ORM\EntityRepository;
use CTRV\CommonBundle\Form\CityType;
use CTRV\CommonBundle\Entity\City;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use CTRV\CommonBundle\DependencyInjection\Constants;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

/**
* City controller.
*
* @Route("/city")
*/
class CityController extends Controller
{

/**
* @Route("/list",name="city")
* @Template()
* Retourne la liste de toutes les villes
*/
public function getAllCitiesAction(){

$em = $this->getDoctrine()->getEntityManager();
$currentCity = $this->get('session_service')->getCity();

if ($currentCity == null) {
$this->get('session')->getFlashBag()->add('error', $this->get('translator')->trans('session.city.not_found'));
$this->redirect($this->generateUrl("home"));
}
$page = intval($this->getRequest()->get("page",1));

//pagination
$nb_entities = $cities = $this->getDoctrine()->getEntityManager()->getRepository('CTRVCommonBundle:City')->getAllCitiesNumber();
$nb_entities_page = Constants::city_number_per_page;
$nb_pages = ceil($nb_entities/$nb_entities_page);
$offset = ($page-1) * $nb_entities_page;

$cities = $this->getDoctrine()->getEntityManager()->getRepository('CTRVCommonBundle:City')->getAllCities($offset, $nb_entities_page);

return array (
'entities' => $cities,
'nb_pages' => $nb_pages,
'page' => $page,
'nb_entities' => $nb_entities
);
}

/**
* ajouter une nouvelle ville
* @Route("/add",name="addCity")
* @Template()
*/
public function addCityAction () {
$em = $this->getDoctrine()->getEntityManager();
$form = $this->createForm(new CityType(),new City());
// On vérifie qu'elle est de type POST
if ($this->getRequest()->getMethod() == 'POST') {
// On fait le lien Requête <-> Formulaire
$form->bind($this->getRequest());
// On vérifie que les valeurs rentrées sont correctes
if ($form->isValid()) {
// On enregistre notre objet $city dans la base de données
$city = $form->getData();
$em->persist($city);
$em->flush();
// on redirige vers la liste des types de place
return $this->redirect($this->generateUrl("city"));
}
}
return array('form'=>$form->createView());

}

/**
* modifier une ville
* @Route("/editCity/{id}",name="edit_city")
* @Template()
*/
public function editCityAction(City $city) {
$form = $this->createForm(new CityType(), $city);
$request=$this->getRequest();
// On vérifie qu'elle est de type POST
if ($this->getRequest()->getMethod() == 'POST') {
// On fait le lien Requête <-> Formulaire
$form->bind($this->getRequest());
// On vérifie que les valeurs rentrées sont correctes
if ($form->isValid()) {
// On enregistre notre objet $city dans la base de données
$em = $this->getDoctrine()->getEntityManager();
$em->persist($city);
$em->flush();
// on redirige vers la liste des places existantes
return $this->redirect($this->generateUrl("city"));
}

}


return array(
'city'=> $city,
'form'=>$form->createView());

}
/**
* Deletes a City entity.
*
* @Route("/{id}/delete", name="city_delete" ) //requirements={"id" = "\d+"}
* @Method("POST")
* @Template()
*/
public function deleteAction($id) {

$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('CTRVCommonBundle:City')->find($id);

$em->remove($entity);
$em->flush();

return new Response(json_encode(array('result'=>true)));
}



}
Loading