Browse Source

(contenu) page d'affichage de ses favoris.

bastien 13 years ago
parent
commit
5b872dcc61

+ 4 - 1
app/Resources/translations/network.fr.yml View File

@@ -10,4 +10,7 @@ search:
10 10
     submit_value:       Rechercher
11 11
 users:                Utilisateurs
12 12
 groups:               Groupes
13
-followed_by:          Vous êtes suivis par
13
+followed_by:          Vous êtes suivis par
14
+
15
+favorites:
16
+  your_favorites:     Vos favoris

+ 61 - 26
src/Muzich/CoreBundle/Repository/ElementRepository.php View File

@@ -4,6 +4,7 @@ namespace Muzich\CoreBundle\Repository;
4 4
 
5 5
 use Doctrine\ORM\EntityRepository;
6 6
 use Muzich\CoreBundle\Searcher\ElementSearcher;
7
+use Symfony\Component\Config\Definition\Exception\Exception;
7 8
 
8 9
 class ElementRepository extends EntityRepository
9 10
 {
@@ -37,31 +38,18 @@ class ElementRepository extends EntityRepository
37 38
     //$query_with = '';
38 39
     $where = '';
39 40
     
40
-    switch ($searcher->getNetwork())
41
+    // Ajout du filtre limitant au réseau personel si c'est le cas
42
+    if ($searcher->getNetwork() == ElementSearcher::NETWORK_PERSONAL)
41 43
     {
42
-      case ElementSearcher::NETWORK_PERSONAL:
43
-        
44
-        $join_personal = "
45
-          LEFT JOIN eu.followers_users f WITH f.follower = :userid "
46
-          ."JOIN g.followers gf WITH gf.follower = :useridg"
47
-          ;
48
-        $params['userid'] = $user_id;
49
-        $params['useridg'] = $user_id;
50
-        
51
-      break;
44
+      $join_personal = "
45
+        LEFT JOIN eu.followers_users f WITH f.follower = :userid "
46
+        ."JOIN g.followers gf WITH gf.follower = :useridg"
47
+        ;
48
+      $params['userid'] = $user_id;
49
+      $params['useridg'] = $user_id;
52 50
     }
53 51
     
54
-//    $query_with = "WITH ";
55
-//    foreach ($searcher->getTags() as $tag_id)
56
-//    {
57
-//      if ($query_with != "WITH ")
58
-//      {
59
-//        $query_with .= "OR ";
60
-//      }
61
-//      $query_with .= "t.id = :tagid".$tag_id." ";
62
-//      $params['tagid'.$tag_id] = $tag_id;
63
-//    }
64
-    
52
+    // ajout du filtres de trie avec les tags transmis
65 53
     foreach ($searcher->getTags() as $tag_id)
66 54
     {
67 55
       if ($where == '')
@@ -74,7 +62,52 @@ class ElementRepository extends EntityRepository
74 62
       }
75 63
       $params['tid'.$tag_id] = $tag_id;
76 64
     }
77
-        
65
+    
66
+    // ajout du filtre sur un user si c'est le cas
67
+    $where_user = '';
68
+    //                                                  Si c'est une recherche 
69
+    //                de favoris, on ne filtre pas sur le proprio de l'element
70
+    if (($search_user_id = $searcher->getUserId()) && !$searcher->isFavorite())
71
+    {
72
+      $where_user = ($where != '') ? ' AND' : ' WHERE';
73
+      $where_user .= ' e.owner = :suid';
74
+      $params['suid'] = $search_user_id;
75
+    }
76
+    
77
+    // ajout du filtre sur un user si c'est le cas
78
+    $where_group = '';
79
+    //                                                 Si c'est une recherche 
80
+    //               de favoris, on ne filtre pas sur le proprio de l'element
81
+    if (($search_group_id = $searcher->getGroupId()) && !$searcher->isFavorite())
82
+    {
83
+      $where_group = ($where != '') ? ' AND' : ' WHERE';
84
+      $where_group .= ' e.group = :sgid';
85
+      $params['sgid'] = $search_group_id;
86
+    }
87
+    
88
+    // Filtre pour afficher que les elements mis en favoris si c'est la demande
89
+    $join_favorite = ''; $where_favorite = '';
90
+    if ($searcher->isFavorite())
91
+    {
92
+      $where_favorite = ($where != '') ? ' AND' : ' WHERE';
93
+      if (($favorite_user_id = $searcher->getUserId()) && !$searcher->getGroupId())
94
+      {
95
+        $join_favorite = 'JOIN e.elements_favorites fav2';
96
+        $where_favorite .= ' fav2.user = :fuid';
97
+        $params['fuid'] = $favorite_user_id;
98
+      }
99
+      else if (($favorite_group_id = $searcher->getGroupId()) && !$searcher->getUserId())
100
+      {
101
+        // TODO: Faire en sorte que ça affiche les favrois des gens suivant
102
+        // le groupe
103
+      }
104
+      else
105
+      {
106
+        throw new Exception('For use favorite search element, you must specify an user_id or group_id');
107
+      }
108
+    }
109
+    
110
+    // Construction de la requête finale
78 111
     $query_string = "SELECT e, et, t2, eu, g, fav
79 112
       FROM MuzichCoreBundle:Element e 
80 113
       LEFT JOIN e.group g 
@@ -82,11 +115,14 @@ class ElementRepository extends EntityRepository
82 115
       LEFT JOIN e.tags t 
83 116
       LEFT JOIN e.tags t2 
84 117
       LEFT JOIN e.elements_favorites fav WITH fav.user = :uid
118
+      $join_favorite
85 119
       JOIN e.owner eu $join_personal
86 120
       $where
121
+      $where_user
122
+      $where_group
123
+      $where_favorite
87 124
       ORDER BY e.created DESC "
88 125
     ;
89
-    
90 126
     $params['uid'] = $user_id;
91 127
     
92 128
     $query = $this->getEntityManager()
@@ -144,6 +180,5 @@ class ElementRepository extends EntityRepository
144 180
       ->setParameter('gid', $group_id)
145 181
       ->setMaxResults($limit)
146 182
     ;
147
-  }
148
-  
183
+  }  
149 184
 }

+ 44 - 5
src/Muzich/CoreBundle/Searcher/ElementSearcher.php View File

@@ -35,6 +35,27 @@ class ElementSearcher extends Searcher implements SearcherInterface
35 35
   protected $count = 20;
36 36
   
37 37
   /**
38
+   * Id de l'user si on limite la recherche a un utilisateur
39
+   * 
40
+   * @var int
41
+   */
42
+  protected $user_id = null;
43
+  
44
+  /**
45
+   * Id du groupe si on limite la recherche a un groupe
46
+   * 
47
+   * @var int
48
+   */
49
+  protected $group_id = null;
50
+  
51
+  /**
52
+   * Est-ce les favoris qui sont recherché
53
+   * 
54
+   * @var boolean 
55
+   */
56
+  protected $favorite = false;
57
+  
58
+  /**
38 59
    * @see SearcherInterface
39 60
    * @param array $params 
40 61
    */
@@ -47,7 +68,7 @@ class ElementSearcher extends Searcher implements SearcherInterface
47 68
     
48 69
     // Mise a jour des attributs
49 70
     $this->setAttributes(array(
50
-      'network', 'tags', 'count'
71
+      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite'
51 72
     ), $params);
52 73
     
53 74
   }
@@ -60,7 +81,7 @@ class ElementSearcher extends Searcher implements SearcherInterface
60 81
   {
61 82
     // Mise a jour des attributs
62 83
     $this->setAttributes(array(
63
-      'network', 'tags', 'count'
84
+      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite'
64 85
     ), $params);
65 86
   }
66 87
   
@@ -72,9 +93,12 @@ class ElementSearcher extends Searcher implements SearcherInterface
72 93
   public function getParams()
73 94
   {
74 95
     return array(
75
-      'network' => $this->getNetwork(),
76
-      'tags' => $this->getTags(),
77
-      'count' => $this->getCount()
96
+      'network'  => $this->getNetwork(),
97
+      'tags'     => $this->getTags(),
98
+      'count'    => $this->getCount(),
99
+      'user_id'  => $this->getUserId(),
100
+      'group_id' => $this->getGroupId(),
101
+      'favorite' => $this->isFavorite()
78 102
     );
79 103
   }
80 104
   
@@ -93,4 +117,19 @@ class ElementSearcher extends Searcher implements SearcherInterface
93 117
     return $this->count;
94 118
   }
95 119
   
120
+  public function getUserId()
121
+  {
122
+    return $this->user_id;
123
+  }
124
+  
125
+  public function getGroupId()
126
+  {
127
+    return $this->group_id;
128
+  }
129
+  
130
+  public function isFavorite()
131
+  {
132
+    return $this->favorite;
133
+  }
134
+  
96 135
 }

+ 1 - 1
src/Muzich/CoreBundle/lib/Controller.php View File

@@ -106,7 +106,7 @@ class Controller extends BaseController
106 106
    */
107 107
   protected function getUserId()
108 108
   {
109
-    $this->getUser()->getId();
109
+    return $this->getUser()->getId();
110 110
   }
111 111
   
112 112
   /**

+ 9 - 2
src/Muzich/FavoriteBundle/Controller/FavoriteController.php View File

@@ -5,6 +5,7 @@ namespace Muzich\FavoriteBundle\Controller;
5 5
 use Muzich\CoreBundle\lib\Controller;
6 6
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7 7
 use Muzich\CoreBundle\Entity\UsersElementsFavorites;
8
+use Muzich\CoreBundle\Searcher\ElementSearcher;
8 9
 //use Muzich\CoreBundle\Entity\Group;
9 10
 //use Muzich\CoreBundle\Form\Group\GroupForm;
10 11
 //use Symfony\Component\HttpFoundation\Request;
@@ -59,9 +60,15 @@ class FavoriteController extends Controller
59 60
    */
60 61
   public function myListAction()
61 62
   {
63
+    $search_object = new ElementSearcher();
64
+    $search_object->init(array(
65
+      'user_id'  => $this->getUserId(),
66
+      'favorite' => true
67
+    ));
62 68
     
63
-    
64
-    return array();
69
+    return array(
70
+        'search_object' => $search_object
71
+    );
65 72
   }
66 73
   
67 74
 }

+ 2 - 0
src/Muzich/FavoriteBundle/Resources/views/Favorite/myList.html.twig View File

@@ -4,6 +4,8 @@
4 4
 
5 5
 {% block content %}
6 6
 
7
+  <h2>{{ 'favorites.your_favorites'|trans({}, 'network') }}</h2>
7 8
 
9
+  {% render "MuzichCoreBundle:Search:doSearchElements" with { 'search': search_object } %}
8 10
     
9 11
 {% endblock %}