mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-08 08:49:52 +00:00
view one person + list
This commit is contained in:
parent
d0c480802e
commit
03091a94d6
83
Controller/PersonController.php
Normal file
83
Controller/PersonController.php
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace CL\Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
use CL\Chill\PersonBundle\Entity\Person;
|
||||||
|
|
||||||
|
class PersonController extends Controller {
|
||||||
|
|
||||||
|
public function viewAction($id){
|
||||||
|
|
||||||
|
$person = $this->_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -221,6 +221,18 @@ ou une valeur vide lorsque la donnée nest pas connue*/
|
|||||||
{
|
{
|
||||||
return $this->genre;
|
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
|
* Set civil_union
|
||||||
@ -405,4 +417,12 @@ ou une valeur vide lorsque la donnée nest pas connue*/
|
|||||||
{
|
{
|
||||||
return $this->nationality;
|
return $this->nationality;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLabel() {
|
||||||
|
return $this->getSurname()." ".$this->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString() {
|
||||||
|
return $this->getLabel();
|
||||||
|
}
|
||||||
}
|
}
|
@ -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
|
16
Resources/translations/messages.fr.yml
Normal file
16
Resources/translations/messages.fr.yml
Normal file
@ -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 <span class="research">%q%</span> 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
|
||||||
|
|
46
Resources/views/Person/list.html.twig
Normal file
46
Resources/views/Person/list.html.twig
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{% extends "CLChillMainBundle::layout.html.twig" %}
|
||||||
|
{% block title %}Recherche {{ pattern }}{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<table class="striped rounded">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans %}person.name{% endtrans %}</th>
|
||||||
|
<th>{% trans %}person.dateOfBirth{% endtrans %}</th>
|
||||||
|
<th>{% trans %}person.nationality{% endtrans %}</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for person in persons %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="{{ path('chill_person_view', {id : person.id}) }}">
|
||||||
|
<span class="personSurname">{{person.surname}}</span>
|
||||||
|
<span class="personName">{{person.name}}</span>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td><span class="personDateOfBirth">{{person.dateOfBirth.format(date_format)}}</span></td>
|
||||||
|
<td>
|
||||||
|
{% if person.nationality is not null %}
|
||||||
|
<span class="personNationality">{{person.nationality.label}}</span>
|
||||||
|
{% else %}
|
||||||
|
{{ 'views.Person.list.without_nationality'|trans }}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
34
Resources/views/Person/view.html.twig
Normal file
34
Resources/views/Person/view.html.twig
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{% extends "CLChillMainBundle::layout.html.twig" %}
|
||||||
|
|
||||||
|
|
||||||
|
{#
|
||||||
|
|
||||||
|
This view should receive those arguments:
|
||||||
|
- person
|
||||||
|
|
||||||
|
|
||||||
|
#}
|
||||||
|
|
||||||
|
{% block title %}CLChillPersonBundle:Person:see{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>
|
||||||
|
<span class="surname">{{ person.surname }}</span>
|
||||||
|
<span class="personName">{{ person.name }}</span>
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<p class="date detail">{% transchoice person.genreNumeric
|
||||||
|
with {'%date%' : person.dateOfBirth.format('d-m-Y')} %}views.Person.view.born{% endtranschoice %}</p>
|
||||||
|
{% if person.nationality is not null %}
|
||||||
|
<p class="nationality detail">{{ person.nationality.label }}</p>
|
||||||
|
{% else %}
|
||||||
|
<p class="nationality detail without_nationality">{% trans %}views.Person.view.without_nationality{% endtrans %}</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{{ include("::menu.html.twig", {'person': person, 'menu_composer' : menu_composer }) }}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
9
Resources/views/menu.html.twig
Normal file
9
Resources/views/menu.html.twig
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<div>
|
||||||
|
<ul>
|
||||||
|
{% for menu in menu_composer.getRoutesFor('person') %}
|
||||||
|
<li>{{ path(menu, {'id': person.id}) }}</li>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
16
Tests/Controller/PersonControllerTest.php
Normal file
16
Tests/Controller/PersonControllerTest.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace CL\Chill\PersonBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
|
class PersonControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
public function testSee()
|
||||||
|
{
|
||||||
|
$client = static::createClient();
|
||||||
|
|
||||||
|
$crawler = $client->request('GET', '/see');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user