Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. It’s been a week I’m on this and It still doesn’t work ><
  2.  
  3. LE CONTROLEUR
  4.  
  5. I think there are many problemes and think is controller because don't find $postes array . I don't no do this .
  6.  
  7. `` `php /**
  8. * @Route("/", name="filter_index", methods={"GET","POST"})
  9. */
  10. public function index(Request $resquest, FilterRepository $filterRepository): Response
  11. {
  12. {// creation du formulaire
  13. $filterType = $this->createForm(FilterType::class);
  14. // Il n'est pas mappé
  15. $filterType->handleRequest($resquest);
  16.  
  17. if ($filterType->isSubmitted() && $filterType->isValid()) {
  18.  
  19. // Requête recupére poste et horaire par chefEquipe
  20. $postes = $filterRepository->filter( $filterType->get('chefEquipe')->getData());
  21.  
  22. // On redirige vers la vue
  23. return $this->render('filter/index.html.twig', ['postes' => $postes, 'filterType' => $filterType->createView()]);
  24. }
  25. return $this->render('filter/index.html.twig', [ 'filterType' => $filterType->createView(),
  26. ]);
  27. }
  28. }
  29. `` `
  30.  
  31.  
  32.  
  33. LE FORMTYPE`` `php
  34. public function buildForm(FormBuilderInterface $builder, array $options)
  35. {
  36. $builder ->
  37. add('chefEquipe', EntityType::class, [
  38. 'class' => ChefEquipe::class,
  39. //Requete avec le query builder recupére chefEquipe affichage avec un bouton
  40. 'query_builder' => function (EntityRepository $er) {
  41. return $er->createQueryBuilder('c')
  42. ->orderBy('c.chefEquipe', 'ASC');
  43. },
  44. 'choice_label' => 'chefEquipe',
  45. 'label' => 'Chef Equipe', 'placeholder' => 'Tous', 'required' => false
  46. ]);
  47.  
  48.  
  49.  
  50. $builder->add('Valider', SubmitType::class, ['attr' => ['class' => 'hollow button secondary']]);
  51.  
  52. }
  53.  
  54. public function configureOptions(OptionsResolver $resolver)
  55. {
  56. $resolver->setDefaults([
  57. 'mapped' => false,
  58. ]);
  59. }
  60. `` `
  61. LE REPOSITORY
  62. `` `php
  63. public function __construct(RegistryInterface $registry)
  64. {
  65. parent::__construct($registry, Poste::class);
  66. }
  67.  
  68. public function filter(?ChefEquipe $chefEquipe)
  69. {
  70. $conn = $this->getEntityManager()
  71. ->getConnection();
  72. $sql = 'SELECT * FROM chef_equipe INNER JOIN poste as po ON chef_equipe.chef_equipe = po.chef_equipe INNER JOIN horaire as ho ON chef_equipe.chef_equipe = ho.chef_equipe WHERE chef_equipe.chef_equipe="BRICARD GERALD" ';
  73. $stmt = $conn->prepare($sql);
  74. $stmt->execute(array('chefEquipe' => $chefEquipe->getId()));
  75. var_dump($stmt->fetchAll());die;
  76.  
  77. }
  78.  
  79. `` `
  80. Maybe there are better for this request ?!
  81.  
  82.  
  83. My TEMPLATE
  84. `` `php
  85. {% extends 'base.html.twig' %}
  86.  
  87. {% block title %}Poste index{% endblock %}
  88.  
  89. {% block body %}
  90.  
  91. {% include 'filter/search.html.twig' %}
  92.  
  93. <h1>Poste index</h1>
  94.  
  95. <table class="table">
  96. <thead>
  97. <tr>
  98. <th>Id</th>
  99. <th>Lundi</th>
  100. <th>Mardi</th>
  101. <th>Mercredi</th>
  102. <th>Jeudi</th>
  103. <th>Vendredi</th>
  104. <th>Samedi</th>
  105. <th>Dimanche</th>
  106. <th>ChefEquipe</th>
  107. <th>Equipe</th>
  108. <th>actions</th>
  109. </tr>
  110. </thead>
  111. <tbody>
  112. {% for poste in postes %}
  113. <tr>
  114. <td>{{ poste.id }}</td>
  115. <td>{{ horaire.nomPrenom }}</td>
  116. <td>{{ poste.lundi }}</td>
  117. <td>{{ horaire.lundi }}</td>
  118.  
  119. <td>{{ poste.mardi }}</td>
  120. <td>{{ horaire.mardi }}</td>
  121.  
  122. <td>{{ poste.mercredi }}</td>
  123. <td>{{ horaire.mercredi }}</td>
  124.  
  125. <td>{{ poste.jeudi }}</td>
  126. <td>{{ horaire.jeudi }}</td>
  127.  
  128. <td>{{ poste.vendredi }}</td>
  129. <td>{{ horaire.vendredi }}</td>
  130.  
  131. <td>{{ poste.samedi }}</td>
  132. <td>{{ horaire.samedi }}</td>
  133.  
  134. <td>{{ poste.dimanche }}</td>
  135. <td>{{ horaire.dimanche }}</td>
  136.  
  137. <td>{{ poste.chefEquipe }}</td>
  138. <td>{{ horaire.chefEquipe }}</td>
  139. <td>{{ chefequipe.chefEquipe }}</td>
  140.  
  141. <td>{{ poste.equipe }}</td>
  142. <td>
  143. <a href="{{ path('poste_show', {'id': poste.id}) }}">show</a>
  144. <a href="{{ path('poste_edit', {'id': poste.id}) }}">edit</a>
  145. </td>
  146. </tr>
  147. {% else %}
  148. <tr>
  149. <td colspan="11">no records found</td>
  150. </tr>
  151. {% endfor %}
  152. </tbody>
  153. </table>
  154.  
  155. <a href="{{ path('poste_new') }}">Create new</a>
  156. {% endblock %}
  157.  
  158. `` `
  159. TEMPLATE FORM WITH CHOICE`` `php
  160. {% extends 'base.html.twig' %}
  161. {% block title %}Search{% endblock %}
  162.  
  163. {% block body %}
  164. {{ form_start(filterType) }}
  165. {{ form_widget(filterType) }}
  166. {{ form_end(filterType) }}
  167. {% endblock %}
  168.  
  169. `` `
  170. My ENTITY
  171.  
  172. `` `php
  173.  
  174. /**
  175. * Poste
  176. *
  177. * @ORMTable(name="poste", uniqueConstraints={@ORMUniqueConstraint(name="nom_prenom", columns={"nom_prenom"})})
  178. * @ORMEntity
  179. */
  180. class Poste
  181. {
  182. /**
  183. * @var int
  184. *
  185. * @ORMColumn(name="id", type="integer", nullable=false)
  186. * @ORMId
  187. * @ORMGeneratedValue(strategy="IDENTITY")
  188. */
  189. private $id;
  190.  
  191. /**
  192. * @var string|null
  193. *
  194. * @ORMColumn(name="lundi", type="string", length=255, nullable=true)
  195. */
  196. private $lundi;
  197.  
  198. /**
  199. * @var string|null
  200. *
  201. * @ORMColumn(name="mardi", type="string", length=255, nullable=true)
  202. */
  203. private $mardi;
  204.  
  205. /**
  206. * @var string|null
  207. *
  208. * @ORMColumn(name="mercredi", type="string", length=255, nullable=true)
  209. */
  210. private $mercredi;
  211.  
  212. /**
  213. * @var string|null
  214. *
  215. * @ORMColumn(name="jeudi", type="string", length=255, nullable=true)
  216. */
  217. private $jeudi;
  218.  
  219. /**
  220. * @var string|null
  221. *
  222. * @ORMColumn(name="vendredi", type="string", length=255, nullable=true)
  223. */
  224. private $vendredi;
  225.  
  226. /**
  227. * @var string|null
  228. *
  229. * @ORMColumn(name="samedi", type="string", length=255, nullable=true)
  230. */
  231. private $samedi;
  232.  
  233. /**
  234. * @var string|null
  235. *
  236. * @ORMColumn(name="dimanche", type="string", length=255, nullable=true)
  237. */
  238. private $dimanche;
  239.  
  240. /**
  241. * @var string
  242. *
  243. * @ORMColumn(name="chef_equipe", type="string", length=255, nullable=false)
  244. */
  245. private $chefEquipe;
  246.  
  247. /**
  248. * @var string
  249. *
  250. * @ORMColumn(name="equipe", type="string", length=1000, nullable=false)
  251. */
  252. private $equipe;
  253.  
  254. /**
  255. * @var Horaire
  256. *
  257. * @ORMManyToMany(targetEntity="Horaire")
  258. * @ORMJoinColumn(name="nom_prenom", referencedColumnName="nom_prenom")
  259. *
  260. */
  261. private $nomPrenom;
  262.  
  263. /**
  264. * @ORMColumn(type="string", length=255, nullable=true)
  265. */
  266. private $nom_prenom;
  267.  
  268.  
  269.  
  270. public function getId(): ?int
  271. {
  272. return $this->id;
  273. }
  274.  
  275. public function getLundi(): ?string
  276. {
  277. return $this->lundi;
  278. }
  279.  
  280. public function setLundi(?string $lundi): self
  281. {
  282. $this->lundi = $lundi;
  283.  
  284. return $this;
  285. }
  286.  
  287. public function getMardi(): ?string
  288. {
  289. return $this->mardi;
  290. }
  291.  
  292. public function setMardi(?string $mardi): self
  293. {
  294. $this->mardi = $mardi;
  295.  
  296. return $this;
  297. }
  298.  
  299. public function getMercredi(): ?string
  300. {
  301. return $this->mercredi;
  302. }
  303.  
  304. public function setMercredi(?string $mercredi): self
  305. {
  306. $this->mercredi = $mercredi;
  307.  
  308. return $this;
  309. }
  310.  
  311. public function getJeudi(): ?string
  312. {
  313. return $this->jeudi;
  314. }
  315.  
  316. public function setJeudi(?string $jeudi): self
  317. {
  318. $this->jeudi = $jeudi;
  319.  
  320. return $this;
  321. }
  322.  
  323. public function getVendredi(): ?string
  324. {
  325. return $this->vendredi;
  326. }
  327.  
  328. public function setVendredi(?string $vendredi): self
  329. {
  330. $this->vendredi = $vendredi;
  331.  
  332. return $this;
  333. }
  334.  
  335. public function getSamedi(): ?string
  336. {
  337. return $this->samedi;
  338. }
  339.  
  340. public function setSamedi(?string $samedi): self
  341. {
  342. $this->samedi = $samedi;
  343.  
  344. return $this;
  345. }
  346.  
  347. public function getDimanche(): ?string
  348. {
  349. return $this->dimanche;
  350. }
  351.  
  352. public function setDimanche(?string $dimanche): self
  353. {
  354. $this->dimanche = $dimanche;
  355.  
  356. return $this;
  357. }
  358.  
  359. public function getChefEquipe(): ?string
  360. {
  361. return $this->chefEquipe;
  362. }
  363.  
  364. public function setChefEquipe(string $chefEquipe): self
  365. {
  366. $this->chefEquipe = $chefEquipe;
  367.  
  368. return $this;
  369. }
  370.  
  371. public function getEquipe(): ?string
  372. {
  373. return $this->equipe;
  374. }
  375.  
  376. public function setEquipe(string $equipe): self
  377. {
  378. $this->equipe = $equipe;
  379.  
  380. return $this;
  381. }
  382.  
  383. public function getNomPrenom():? Horaire
  384. {
  385. return $this->nomPrenom;
  386. }
  387.  
  388. public function setNomPrenom(?Horaire $nomPrenom): self
  389. {
  390. $this->nomPrenom = $nomPrenom;
  391.  
  392. return $this;
  393. }
  394.  
  395. public function __toString()
  396. {
  397. return $this->chefEquipe = $this->getChefEquipe() ;
  398. }
  399.  
  400. `` `
  401.  
  402. `` `php **
  403. * @ORMEntity(repositoryClass="AppRepositoryChefEquipeRepository")
  404. */
  405. class ChefEquipe
  406. {
  407. /**
  408. * @ORMId()
  409. * @ORMGeneratedValue()
  410. * @ORMColumn(type="integer")
  411. */
  412. private $id;
  413.  
  414. /**
  415. * @ORMColumn(type="string", length=255, nullable=true)
  416. */
  417. private $chefEquipe;
  418.  
  419. public function getId(): ?int
  420. {
  421. return $this->id;
  422. }
  423.  
  424. public function getChefEquipe(): ?string
  425. {
  426. return $this->chefEquipe;
  427. }
  428.  
  429. public function setChefEquipe(?string $chefEquipe): self
  430. {
  431. $this->chefEquipe = $chefEquipe;
  432.  
  433. return $this;
  434. }
  435. }
  436.  
  437. `` `
  438.  
  439. PLEASE HELPE ME !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement