diff --git a/Controller/PersonController.php b/Controller/PersonController.php new file mode 100644 index 000000000..719bd56d5 --- /dev/null +++ b/Controller/PersonController.php @@ -0,0 +1,83 @@ +_getPerson($id); + + if ($person === null) { + $this->createNotFoundException("Person with id $id not found on this server"); + } + + return $this->render('CLChillPersonBundle:Person:view.html.twig', + array("person" => $person, 'menu_composer' => $this->get('menu_composer')) + ); + + } + + public function searchAction() { + $q = $this->getRequest()->query->getAlnum('q', ''); + $q = trim($q); + + if ( $q === '' ) { + $this->get('session') + ->getFlashBag() + ->add('info', + $this->get('translator') + ->trans('search.q_is_empty') ); + } + + $em = $this->getDoctrine()->getManager(); + + $offset = $this->getRequest()->query->getInt('offet', 0); + $limit = $this->getRequest()->query->getInt('limit', 30); + + $persons = $em->createQuery('SELECT p FROM CLChillPersonBundle:Person p' + . ' WHERE LOWER(p.name) like LOWER(:q) OR LOWER(p.surname) ' + . ' like LOWER(:q) ') + ->setParameter('q', '%'.$q.'%') + // ->setOffset($offset) + // ->setLimit($limit) + ->getResult() + ; + + + if (count($persons) === 0 ){ + $this->get('session') + ->getFlashBag() + ->add('info', + $this->get('translator') + ->trans('search.no_results', array( + '%q%' => $q + )) + ); + } + + return $this->render('CLChillPersonBundle:Person:list.html.twig', + array( + 'persons' => $persons, + 'pattern' => $q, + 'menu_composer' => $this->get('menu_composer') + )); + } + + /** + * easy getting a person by his id + * @return \CL\Chill\PersonBundle\Entity\Person + */ + private function _getPerson($id) { + $em = $this->getDoctrine()->getManager(); + + $person = $em->getRepository('CLChillPersonBundle:Person') + ->find($id); + + return $person; + } + +} diff --git a/Entity/Person.php b/Entity/Person.php index 9256ee384..777d1bc25 100644 --- a/Entity/Person.php +++ b/Entity/Person.php @@ -221,6 +221,18 @@ ou une valeur vide lorsque la donnée nest pas connue*/ { return $this->genre; } + + /** + * return gender as a Numeric form. + * Useful for translation :-) + * @return int + */ + public function getGenreNumeric() { + if ($this->getGenre() == self::GENRE_WOMAN) + return 1; + else + return 0; + } /** * Set civil_union @@ -405,4 +417,12 @@ ou une valeur vide lorsque la donnée nest pas connue*/ { return $this->nationality; } + + public function getLabel() { + return $this->getSurname()." ".$this->getName(); + } + + public function __toString() { + return $this->getLabel(); + } } \ No newline at end of file diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 8b1378917..a211a789d 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1 +1,18 @@ + +chill_person_view: + pattern: /view/{id} + defaults: { _controller: CLChillPersonBundle:Person:view } + + +chill_person_search: + pattern: /search + defaults: { _controller: CLChillPersonBundle:Person:search } + +chill_person_view_history: + pattern: /view/{id}/history + defaults: {_controller: CLChillPersonBundle:Person:history } + options: + menu: person + order: 100 + label: menu.person.history \ No newline at end of file diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml new file mode 100644 index 000000000..f05e2acd4 --- /dev/null +++ b/Resources/translations/messages.fr.yml @@ -0,0 +1,16 @@ +person: + name: Nom + surname: Prénom + dateOfBirth: Date de naissance + nationality: Nationalité +search: + q_is_empty: Votre requête est vide. Veuillez introduire un terme de recherche + no_results: La requête %q% ne renvoie aucun résultat. +views: + Person: + view: + born: '{0} Né le %date% | {1} Née le %date%' + without_nationality: Nationalité inconnue + list: + without_nationality: Nationalité inconnue + diff --git a/Resources/views/Person/list.html.twig b/Resources/views/Person/list.html.twig new file mode 100644 index 000000000..2e9d97378 --- /dev/null +++ b/Resources/views/Person/list.html.twig @@ -0,0 +1,46 @@ +{% extends "CLChillMainBundle::layout.html.twig" %} + {% block title %}Recherche {{ pattern }}{% endblock %} + + + + {% block content %} + +
{% trans %}person.name{% endtrans %} | +{% trans %}person.dateOfBirth{% endtrans %} | +{% trans %}person.nationality{% endtrans %} | +
---|---|---|
+ + {{person.surname}} + {{person.name}} + + | +{{person.dateOfBirth.format(date_format)}} | ++ {% if person.nationality is not null %} + {{person.nationality.label}} + {% else %} + {{ 'views.Person.list.without_nationality'|trans }} + {% endif %} + | +
{% transchoice person.genreNumeric + with {'%date%' : person.dateOfBirth.format('d-m-Y')} %}views.Person.view.born{% endtranschoice %}
+{% if person.nationality is not null %} +{{ person.nationality.label }}
+{% else %} +{% trans %}views.Person.view.without_nationality{% endtrans %}
+{% endif %} + + + {{ include("::menu.html.twig", {'person': person, 'menu_composer' : menu_composer }) }} + + + + +{% endblock %} diff --git a/Resources/views/menu.html.twig b/Resources/views/menu.html.twig new file mode 100644 index 000000000..8ad4bc849 --- /dev/null +++ b/Resources/views/menu.html.twig @@ -0,0 +1,9 @@ +