|
@@ -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
|
}
|