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
     submit_value:       Rechercher
10
     submit_value:       Rechercher
11
 users:                Utilisateurs
11
 users:                Utilisateurs
12
 groups:               Groupes
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
 
4
 
5
 use Doctrine\ORM\EntityRepository;
5
 use Doctrine\ORM\EntityRepository;
6
 use Muzich\CoreBundle\Searcher\ElementSearcher;
6
 use Muzich\CoreBundle\Searcher\ElementSearcher;
7
+use Symfony\Component\Config\Definition\Exception\Exception;
7
 
8
 
8
 class ElementRepository extends EntityRepository
9
 class ElementRepository extends EntityRepository
9
 {
10
 {
37
     //$query_with = '';
38
     //$query_with = '';
38
     $where = '';
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
     foreach ($searcher->getTags() as $tag_id)
53
     foreach ($searcher->getTags() as $tag_id)
66
     {
54
     {
67
       if ($where == '')
55
       if ($where == '')
74
       }
62
       }
75
       $params['tid'.$tag_id] = $tag_id;
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
     $query_string = "SELECT e, et, t2, eu, g, fav
111
     $query_string = "SELECT e, et, t2, eu, g, fav
79
       FROM MuzichCoreBundle:Element e 
112
       FROM MuzichCoreBundle:Element e 
80
       LEFT JOIN e.group g 
113
       LEFT JOIN e.group g 
82
       LEFT JOIN e.tags t 
115
       LEFT JOIN e.tags t 
83
       LEFT JOIN e.tags t2 
116
       LEFT JOIN e.tags t2 
84
       LEFT JOIN e.elements_favorites fav WITH fav.user = :uid
117
       LEFT JOIN e.elements_favorites fav WITH fav.user = :uid
118
+      $join_favorite
85
       JOIN e.owner eu $join_personal
119
       JOIN e.owner eu $join_personal
86
       $where
120
       $where
121
+      $where_user
122
+      $where_group
123
+      $where_favorite
87
       ORDER BY e.created DESC "
124
       ORDER BY e.created DESC "
88
     ;
125
     ;
89
-    
90
     $params['uid'] = $user_id;
126
     $params['uid'] = $user_id;
91
     
127
     
92
     $query = $this->getEntityManager()
128
     $query = $this->getEntityManager()
144
       ->setParameter('gid', $group_id)
180
       ->setParameter('gid', $group_id)
145
       ->setMaxResults($limit)
181
       ->setMaxResults($limit)
146
     ;
182
     ;
147
-  }
148
-  
183
+  }  
149
 }
184
 }

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

35
   protected $count = 20;
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
    * @see SearcherInterface
59
    * @see SearcherInterface
39
    * @param array $params 
60
    * @param array $params 
40
    */
61
    */
47
     
68
     
48
     // Mise a jour des attributs
69
     // Mise a jour des attributs
49
     $this->setAttributes(array(
70
     $this->setAttributes(array(
50
-      'network', 'tags', 'count'
71
+      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite'
51
     ), $params);
72
     ), $params);
52
     
73
     
53
   }
74
   }
60
   {
81
   {
61
     // Mise a jour des attributs
82
     // Mise a jour des attributs
62
     $this->setAttributes(array(
83
     $this->setAttributes(array(
63
-      'network', 'tags', 'count'
84
+      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite'
64
     ), $params);
85
     ), $params);
65
   }
86
   }
66
   
87
   
72
   public function getParams()
93
   public function getParams()
73
   {
94
   {
74
     return array(
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
     return $this->count;
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
    */
106
    */
107
   protected function getUserId()
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
 use Muzich\CoreBundle\lib\Controller;
5
 use Muzich\CoreBundle\lib\Controller;
6
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
6
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
 use Muzich\CoreBundle\Entity\UsersElementsFavorites;
7
 use Muzich\CoreBundle\Entity\UsersElementsFavorites;
8
+use Muzich\CoreBundle\Searcher\ElementSearcher;
8
 //use Muzich\CoreBundle\Entity\Group;
9
 //use Muzich\CoreBundle\Entity\Group;
9
 //use Muzich\CoreBundle\Form\Group\GroupForm;
10
 //use Muzich\CoreBundle\Form\Group\GroupForm;
10
 //use Symfony\Component\HttpFoundation\Request;
11
 //use Symfony\Component\HttpFoundation\Request;
59
    */
60
    */
60
   public function myListAction()
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
 
4
 
5
 {% block content %}
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
 {% endblock %}
11
 {% endblock %}