]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Repository/SnippetRepository.php
Add snippet feature
[airbundle] / Repository / SnippetRepository.php
diff --git a/Repository/SnippetRepository.php b/Repository/SnippetRepository.php
new file mode 100644 (file)
index 0000000..a1d696b
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+namespace Rapsys\AirBundle\Repository;
+
+use Symfony\Component\Translation\TranslatorInterface;
+use Doctrine\ORM\Query\ResultSetMapping;
+
+/**
+ * SnippetRepository
+ */
+class SnippetRepository extends \Doctrine\ORM\EntityRepository {
+       /**
+        * Find snippets by locale and user id
+        *
+        * @param string $locale The locale
+        * @param User|int $user The user
+        * @return array The snippets or empty array
+        */
+       public function findByLocaleUserId($locale, $user) {
+               //Fetch snippets
+               $ret = $this->getEntityManager()
+                       ->createQuery('SELECT s FROM RapsysAirBundle:Snippet s WHERE s.locale = :locale and s.user = :user')
+                       ->setParameter('locale', $locale)
+                       ->setParameter('user', $user)
+                       ->getResult();
+
+               //Send result
+               return $ret;
+       }
+}