ShowController.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Muzich\HomeBundle\Controller;
  3. use Muzich\CoreBundle\lib\Controller;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  5. use Muzich\CoreBundle\Form\Element\ElementAddForm;
  6. use Muzich\CoreBundle\Entity\Element;
  7. class ShowController extends Controller
  8. {
  9. /**
  10. * Page public de l'utilisateur demandé.
  11. *
  12. * @Template()
  13. * @param string $slug
  14. */
  15. public function showUserAction($slug, $count = null)
  16. {
  17. $viewed_user = $this->findUserWithSlug($slug);
  18. $search_object = $this->createSearchObject(array(
  19. 'user_id' => $viewed_user->getId(),
  20. 'count' => ($count)?$count:$this->container->getParameter('search_default_count')
  21. ));
  22. return array(
  23. 'viewed_user' => $viewed_user,
  24. 'elements' => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
  25. 'following' => $this->getUser()->isFollowingUserByQuery($this->getDoctrine(), $viewed_user->getId()),
  26. 'user' => $this->getUser(),
  27. 'more_count' => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2,
  28. 'more_route' => 'show_user_more'
  29. );
  30. }
  31. /**
  32. * Page publique du groupe demandé.
  33. *
  34. * @Template()
  35. * @param string $slug
  36. */
  37. public function showGroupAction($slug, $count = null)
  38. {
  39. $group = $this->findGroupWithSlug($slug);
  40. $search_object = $this->createSearchObject(array(
  41. 'group_id' => $group->getId(),
  42. 'count' => ($count)?$count:$this->container->getParameter('search_default_count')
  43. ));
  44. ($group->getOwner()->getId() == $this->getUserId()) ? $his = true : $his = false;
  45. if ($his || $group->getOpen())
  46. {
  47. $add_form = $this->getAddForm();
  48. }
  49. return array(
  50. 'group' => $group,
  51. 'his_group' => ($group->getOwner()->getId() == $this->getUserId()) ? true : false,
  52. 'elements' => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
  53. 'following' => $this->getUser()->isFollowingGroupByQuery($this->getDoctrine(), $group->getId()),
  54. 'user' => $this->getUser(),
  55. 'add_form' => (isset($add_form)) ? $add_form->createView() : null,
  56. 'add_form_name' => (isset($add_form)) ? $add_form->getName() : null,
  57. 'more_count' => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2,
  58. 'more_route' => 'show_group_more'
  59. );
  60. }
  61. }