Permalink
Browse files

added bricks search feature

  • Loading branch information...
inmarelibero committed Oct 28, 2012
1 parent 5c51382 commit d76baaf8582471e563bd77c2d0f94c9708ccb424
@@ -73,4 +73,24 @@ public function showAction($id)
'brick' => $entity
);
}
+
+ /**
+ * Search bricks
+ *
+ * @Route("/search", name="brick_search")
+ * @Template()
+ */
+ public function searchAction()
+ {
+ $em = $this->getDoctrine()->getManager();
+
+ $q = $this->getRequest()->get('q');
+
+ $entities = $em->getRepository('BricksSiteBundle:Brick')->search($q);
+
+ return array(
+ 'q' => $q,
+ 'entities' => $entities
+ );
+ }
}
@@ -12,4 +12,23 @@
*/
class BrickRepository extends EntityRepository
{
+ public function search($q)
+ {
+ $em = $this->getEntityManager();
+
+ $qb = $em->createQueryBuilder()
+ ->select('e')
+ ->from('BricksSiteBundle:Brick', 'e')
+ ;
+
+ // set 'q' doctrine parameter
+ $qb->setParameter('q', '%'.$q.'%');
+
+ /**
+ * searche in 'title' field
+ */
+ $qb->andWhere($qb->expr()->like('e.title', ':q'));
+
+ return $qb->getQuery()->getResult();
+ }
}
@@ -107,5 +107,14 @@ MAIN NAVBAR
a#brand { font-size: 20px; }
}
+
+ li#nav-search-bricks { padding-left: 30px;
+ form { margin: 0px;
+ input[type="text"] {
+ width: 200px;
+ margin-top: 6px;
+ }
+ }
+ }
}
}
@@ -0,0 +1,39 @@
+{% extends 'BricksSiteBundle::layout.html.twig' %}
+
+{% block main %}
+
+
+ <div id="brick-search-wrapper">
+
+ <div class="row">
+ <div class="span12">
+
+ <h1>Results for "{{ q }}"</h1>
+
+ <hr>
+
+ {% if entities|length > 0 %}
+ <ul class="bricks-list">
+ {% for brick in entities %}
+ <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>
+ {% else %}
+ No bricks found
+ {% endif %}
+
+ </div>
+ </div>
+
+ </div>
+
+{% endblock %}
@@ -53,6 +53,14 @@
SymfonyBricks.com
</a>
</li>
+ <li id="nav-search-bricks">
+ <form action="{{ path('brick_search') }}">
+ <div class="input-append">
+ <input name="q" class="span2" size="16" type="text">
+ <button class="btn" type="submit"><i class="icon-search"></i> </button>
+ </div>
+ </form>
+ </li>
</ul>
<ul class="nav pull-right">
<li>

0 comments on commit d76baaf

Please sign in to comment.