Permalink
Browse files

added public user profile page

  • Loading branch information...
inmarelibero committed Oct 28, 2012
1 parent e7f0953 commit 9cbb2e9cfda6a742eb63f5f5dcb1b37ecd9b4b08
@@ -0,0 +1,40 @@
+<?php
+
+namespace Bricks\SiteBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+
+/**
+ * @Route("/profile")
+ */
+class UserProfileController extends Controller
+{
+ /**
+ * @Route("/show/{username}", name="userprofile_show")
+ * @Template()
+ */
+ public function showAction($username)
+ {
+ $userManager = $this->container->get('fos_user.user_manager');
+
+ $user = $userManager->findUserByUsername($username);
+
+ if (!$user) {
+ throw $this->createNotFoundException("Unable to find User \"{$username}\".");
+ }
+
+
+ $em = $this->getDoctrine()->getManager();
+ $publishedBricks = $em->getRepository('BricksSiteBundle:Brick')->findBy(array(
+ 'user' => $user,
+ 'published' => true
+ ));
+
+ return array(
+ 'user' => $user,
+ 'publishedBricks' => $publishedBricks
+ );
+ }
+}
@@ -12,7 +12,7 @@
<p class="description">{{ brick.description }}</p>
<hr>
- <i class="icon-user"></i> {{ brick.user }}
+ <i class="icon-user"></i> <a href="{{ path('userprofile_show', {'username': brick.user.username}) }}">{{ brick.user }}</a>
|
<i class="icon-calendar"></i> last update: {{ brick.updatedAt|date('d/m/Y') }}
@@ -62,7 +62,7 @@
{{ brick.title }}
</a>
<p>
- <i class="icon-user"></i> {{ brick.user }}
+ <i class="icon-user"></i> <a href="{{ path('userprofile_show', {'username': brick.user.username}) }}">{{ brick.user }}</a>
|
<i class="icon-calendar"></i> last update: {{ brick.updatedAt|date('d/m/Y') }}
</p>
@@ -0,0 +1,39 @@
+{% extends 'BricksSiteBundle::layout.html.twig' %}
+
+{% block main %}
+
+ <div id="brick-show-wrapper">
+
+ <div class="row">
+ <div class="span12">
+
+ <h1>{{ user.username }}</h1>
+
+ <hr>
+
+ <h3>Published bricks</h3>
+
+ <ul class="bricks-list">
+ {% for brick in publishedBricks %}
+ <li>
+ <a href="{{ path('brick_show', {id: brick.id, slug: brick.slug}) }}">
+ {{ brick.title }}
+ </a>
+ <p>
+ <i class="icon-user"></i> <a href="{{ path('userprofile_show', {'username': brick.user.username}) }}">{{ brick.user }}</a>
+ |
+ <i class="icon-calendar"></i> last update: {{ brick.updatedAt|date('d/m/Y') }}
+ </p>
+ </li>
+ {% endfor %}
+ </ul>
+
+ </div>
+ </div>
+
+ </div>
+
+{% endblock %}
+
+{# SEO #}
+{% block meta_title_content %}{{ user.username }} profile | SymfonyBricks.com{% endblock %}
@@ -33,6 +33,12 @@ class User extends BaseUser
* @ORM\Column(type="datetime")
*/
private $updated_at;
+
+ /**
+ * @ORM\OneToMany(targetEntity="Bricks\SiteBundle\Entity\Brick", mappedBy="user", cascade={"persist"})
+ * @ORM\OrderBy({"created_at" = "ASC"})
+ */
+ private $bricks;
/**************************************************************************************************
* custom functions
@@ -101,4 +107,37 @@ public function getUpdatedAt()
{
return $this->updated_at;
}
+
+ /**
+ * Add bricks
+ *
+ * @param Bricks\SiteBundle\Entity\Brick $bricks
+ * @return User
+ */
+ public function addBrick(\Bricks\SiteBundle\Entity\Brick $bricks)
+ {
+ $this->bricks[] = $bricks;
+
+ return $this;
+ }
+
+ /**
+ * Remove bricks
+ *
+ * @param Bricks\SiteBundle\Entity\Brick $bricks
+ */
+ public function removeBrick(\Bricks\SiteBundle\Entity\Brick $bricks)
+ {
+ $this->bricks->removeElement($bricks);
+ }
+
+ /**
+ * Get bricks
+ *
+ * @return Doctrine\Common\Collections\Collection
+ */
+ public function getBricks()
+ {
+ return $this->bricks;
+ }
}

0 comments on commit 9cbb2e9

Please sign in to comment.