|
|
@@ -21,6 +21,7 @@ class ElementRepository extends EntityRepository
|
|
21
|
21
|
return $this->getEntityManager()
|
|
22
|
22
|
->createQuery('
|
|
23
|
23
|
SELECT e FROM MuzichCoreBundle:Element e
|
|
|
24
|
+ WHERE e.private = 0
|
|
24
|
25
|
ORDER BY e.name ASC'
|
|
25
|
26
|
)
|
|
26
|
27
|
->getResult()
|
|
|
@@ -39,7 +40,7 @@ class ElementRepository extends EntityRepository
|
|
39
|
40
|
->createQuery("SELECT e FROM MuzichCoreBundle:Element e WHERE 1 = 2")
|
|
40
|
41
|
;
|
|
41
|
42
|
}
|
|
42
|
|
-
|
|
|
43
|
+
|
|
43
|
44
|
$esqb = new ElementSearcherQueryBuilder($this->getEntityManager(), $searcher, $user_id, $params);
|
|
44
|
45
|
|
|
45
|
46
|
// Si on demande une comptabilisation, on retourne juste la requete qui selectionne les ids
|
|
|
@@ -52,335 +53,6 @@ class ElementRepository extends EntityRepository
|
|
52
|
53
|
return $esqb->getElementsQuery();
|
|
53
|
54
|
}
|
|
54
|
55
|
|
|
55
|
|
-
|
|
56
|
|
-
|
|
57
|
|
-// /**
|
|
58
|
|
-// * TODO: Faire un bel objet pour gérer tout ça =)
|
|
59
|
|
-// * => Utiliser l'objet ElementSearcher (ou du moin réorganiser ça en plusieurs
|
|
60
|
|
-// * objets)
|
|
61
|
|
-// *
|
|
62
|
|
-// *
|
|
63
|
|
-// * @param ElementSearcher $searcher
|
|
64
|
|
-// * @return Doctrine\ORM\Query
|
|
65
|
|
-// */
|
|
66
|
|
-// public function findBySearchOLD(ElementSearcher $searcher, $user_id, $exec_type = 'execute', $params = array())
|
|
67
|
|
-// {
|
|
68
|
|
-// // Tableaux des paramétres
|
|
69
|
|
-// $params_ids = array();
|
|
70
|
|
-// $params_select = array();
|
|
71
|
|
-// $params_select['uid'] = $user_id;
|
|
72
|
|
-// $order_by = "ORDER BY e_.created DESC, e_.id DESC";
|
|
73
|
|
-//
|
|
74
|
|
-// // Première chose, si on impose les element_ids on a pas besoin de faire
|
|
75
|
|
-// // le filtrage
|
|
76
|
|
-// if ($searcher->hasIds())
|
|
77
|
|
-// {
|
|
78
|
|
-// // Dans ce cas ou les ids sont déjà donné, on ne peut pas avoir de nouveaux
|
|
79
|
|
-// // éléments
|
|
80
|
|
-// if ($searcher->isSearchingNew())
|
|
81
|
|
-// {
|
|
82
|
|
-// return $query = $this->getEntityManager()
|
|
83
|
|
-// ->createQuery("SELECT e FROM MuzichCoreBundle:Element e WHERE 1 = 2")
|
|
84
|
|
-// ;
|
|
85
|
|
-// }
|
|
86
|
|
-//
|
|
87
|
|
-// if (($id_limit = $searcher->getIdLimit()))
|
|
88
|
|
-// {
|
|
89
|
|
-// return $this->getSelectElementForSearchQuery($params_select, $user_id, $searcher->getIds(), $id_limit, $searcher->getCount(), $searcher->getIdsDisplay());
|
|
90
|
|
-// }
|
|
91
|
|
-// return $this->getSelectElementForSearchQuery($params_select, $user_id, $searcher->getIds(), null, null, $searcher->getIdsDisplay());
|
|
92
|
|
-// }
|
|
93
|
|
-//
|
|
94
|
|
-// // Booléen nous permettant de savoir si un where a déjà été écrit
|
|
95
|
|
-// $is_where = false;
|
|
96
|
|
-//
|
|
97
|
|
-// // Si c'est une recherche string, les autres paramètres ne sont pas nécéssaire
|
|
98
|
|
-// // TODO: Dans la nouvelle version ourquoi pas !!
|
|
99
|
|
-// // TODOOO: Pas encore dans new version (string)
|
|
100
|
|
-// $where_string = '';
|
|
101
|
|
-// if (($string = $searcher->getString()))
|
|
102
|
|
-// {
|
|
103
|
|
-// // On prépare notre liste de mots
|
|
104
|
|
-// $words = array_unique(array_merge(
|
|
105
|
|
-// explode(' ', $string),
|
|
106
|
|
-// explode('-', $string),
|
|
107
|
|
-// explode('- ', $string),
|
|
108
|
|
-// explode(' -', $string),
|
|
109
|
|
-// explode(' - ', $string),
|
|
110
|
|
-// explode(',', $string),
|
|
111
|
|
-// explode(', ', $string),
|
|
112
|
|
-// explode(' ,', $string),
|
|
113
|
|
-// explode(' , ', $string)
|
|
114
|
|
-// ));
|
|
115
|
|
-//
|
|
116
|
|
-// // On récupère les ids des elements correspondants
|
|
117
|
|
-// $word_min_length = 0;
|
|
118
|
|
-// if (isset($params['word_min_length']))
|
|
119
|
|
-// {
|
|
120
|
|
-// $word_min_length = $params['word_min_length'];
|
|
121
|
|
-// }
|
|
122
|
|
-// foreach ($words as $i => $word)
|
|
123
|
|
-// {
|
|
124
|
|
-// if (strlen($word) >= $word_min_length)
|
|
125
|
|
-// {
|
|
126
|
|
-// if ($where_string === '')
|
|
127
|
|
-// {
|
|
128
|
|
-// $where_string = ($is_where) ? ' AND (' : ' WHERE (';
|
|
129
|
|
-// $is_where = true;
|
|
130
|
|
-// $where_string .= "UPPER(e_.name) LIKE :str".$i;
|
|
131
|
|
-// }
|
|
132
|
|
-// else
|
|
133
|
|
-// {
|
|
134
|
|
-// $where_string .= " OR UPPER(e_.name) LIKE :str".$i;
|
|
135
|
|
-// }
|
|
136
|
|
-// $params_ids['str'.$i] = '%'.strtoupper($word).'%';
|
|
137
|
|
-// }
|
|
138
|
|
-// }
|
|
139
|
|
-// $where_string .= ')';
|
|
140
|
|
-//
|
|
141
|
|
-// }
|
|
142
|
|
-//
|
|
143
|
|
-//
|
|
144
|
|
-// // Construction des conditions pour la selection d'ids
|
|
145
|
|
-// $where_tags = '';
|
|
146
|
|
-// $join_tags = '';
|
|
147
|
|
-//
|
|
148
|
|
-// /*
|
|
149
|
|
-// * des fois on se retrouve avec un string au lieu d'un tableau
|
|
150
|
|
-// */
|
|
151
|
|
-// $tags = $searcher->getTags();
|
|
152
|
|
-//
|
|
153
|
|
-// if (!is_array($tags))
|
|
154
|
|
-// {
|
|
155
|
|
-// $tags_decoded = json_decode($tags);
|
|
156
|
|
-// $tags = array();
|
|
157
|
|
-// foreach ($tags_decoded as $tag_id)
|
|
158
|
|
-// {
|
|
159
|
|
-// $tags[$tag_id] = $tag_id;
|
|
160
|
|
-// }
|
|
161
|
|
-// }
|
|
162
|
|
-//
|
|
163
|
|
-// if (count($tags))
|
|
164
|
|
-// {
|
|
165
|
|
-// foreach ($tags as $tag_id => $tag_name)
|
|
166
|
|
-// {
|
|
167
|
|
-// // LEFT JOIN car un element n'est pas obligatoirement lié a un/des tags
|
|
168
|
|
-// $join_tags = " LEFT JOIN e_.tags t_";
|
|
169
|
|
-//
|
|
170
|
|
-// // Construction du chere pour les tags
|
|
171
|
|
-// if ($where_tags == '')
|
|
172
|
|
-// {
|
|
173
|
|
-// $where_tags .= ' WHERE (t_.id = :tid'.$tag_id;
|
|
174
|
|
-// }
|
|
175
|
|
-// else
|
|
176
|
|
-// {
|
|
177
|
|
-// $where_tags .= ' OR t_.id = :tid'.$tag_id;
|
|
178
|
|
-// }
|
|
179
|
|
-// $params_ids['tid'.$tag_id] = $tag_id;
|
|
180
|
|
-// }
|
|
181
|
|
-// // Fermeture de la parenthése qui isole la condition des tags
|
|
182
|
|
-// $where_tags .= ')';
|
|
183
|
|
-// $is_where = true;
|
|
184
|
|
-// }
|
|
185
|
|
-//
|
|
186
|
|
-// // Construction de la condition network
|
|
187
|
|
-// $join_network = '';
|
|
188
|
|
-// $where_network = '';
|
|
189
|
|
-// if ($searcher->getNetwork() == ElementSearcher::NETWORK_PERSONAL)
|
|
190
|
|
-// {
|
|
191
|
|
-// $join_network =
|
|
192
|
|
-// " JOIN e_.owner o_"
|
|
193
|
|
-// // LEFT JOIN car l'element n'est pas obligatoirement lié a un groupe
|
|
194
|
|
-// . " LEFT JOIN e_.group g_"
|
|
195
|
|
-// // LEFT JOIN car owner n'est pas obligatoirement lié a des followers
|
|
196
|
|
-// . " LEFT JOIN o_.followers_users f_"
|
|
197
|
|
-// // LEFT JOIN car le groupe n'est pas obligatoirement lié a des followers
|
|
198
|
|
-// . " LEFT JOIN g_.followers gf_"
|
|
199
|
|
-// ;
|
|
200
|
|
-// $where_network = ($is_where) ? ' AND' : ' WHERE';
|
|
201
|
|
-// $is_where = true;
|
|
202
|
|
-// // Le filtre applique: Soit le proprio fait partis des followeds de l'utilisateur
|
|
203
|
|
-// // soit l'element est ajouté dans un groupe que l'utilisateur follow.
|
|
204
|
|
-// $where_network .= ' (f_.follower = :userid OR gf_.follower = :useridg)';
|
|
205
|
|
-// $params_ids['userid'] = $user_id;
|
|
206
|
|
-// $params_ids['useridg'] = $user_id;
|
|
207
|
|
-// }
|
|
208
|
|
-//
|
|
209
|
|
-// // ajout du filtre sur un user si c'est le cas
|
|
210
|
|
-// $where_user = '';
|
|
211
|
|
-// // Si c'est une recherche
|
|
212
|
|
-// // de favoris, on ne filtre pas sur le proprio de l'element
|
|
213
|
|
-// if (($search_user_id = $searcher->getUserId()) && !$searcher->isFavorite())
|
|
214
|
|
-// {
|
|
215
|
|
-// $where_user = ($is_where) ? ' AND' : ' WHERE';
|
|
216
|
|
-// $is_where = true;
|
|
217
|
|
-// $where_user .= ' e_.owner = :suid';
|
|
218
|
|
-// $params_ids['suid'] = $search_user_id;
|
|
219
|
|
-// }
|
|
220
|
|
-//
|
|
221
|
|
-// // ajout du filtre sur un user si c'est le cas
|
|
222
|
|
-// $where_group = '';
|
|
223
|
|
-// // Si c'est une recherche
|
|
224
|
|
-// // de favoris, on ne filtre pas sur le proprio de l'element
|
|
225
|
|
-// if (($search_group_id = $searcher->getGroupId()) && !$searcher->isFavorite())
|
|
226
|
|
-// {
|
|
227
|
|
-// $where_group = ($is_where) ? ' AND' : ' WHERE';
|
|
228
|
|
-// $is_where = true;
|
|
229
|
|
-// $where_group .= ' e_.group = :sgid';
|
|
230
|
|
-// $params_ids['sgid'] = $search_group_id;
|
|
231
|
|
-// }
|
|
232
|
|
-//
|
|
233
|
|
-// // Filtre pour afficher uniquement les elements mis en favoris
|
|
234
|
|
-// $join_favorite = '';
|
|
235
|
|
-// $where_favorite = '';
|
|
236
|
|
-// if ($searcher->isFavorite())
|
|
237
|
|
-// {
|
|
238
|
|
-// $where_favorite = ($is_where) ? ' AND' : ' WHERE';
|
|
239
|
|
-// $is_where = true;
|
|
240
|
|
-// if (($favorite_user_id = $searcher->getUserId()) && !$searcher->getGroupId())
|
|
241
|
|
-// {
|
|
242
|
|
-// // Pas de LEFT JOIN car on ne veut que les elements mis en favoris
|
|
243
|
|
-// $join_favorite = 'JOIN e_.elements_favorites fav2_';
|
|
244
|
|
-// $where_favorite .= ' fav2_.user = :fuid';
|
|
245
|
|
-// $params_ids['fuid'] = $favorite_user_id;
|
|
246
|
|
-// }
|
|
247
|
|
-// else if (($favorite_group_id = $searcher->getGroupId()) && !$searcher->getUserId())
|
|
248
|
|
-// {
|
|
249
|
|
-// // TODO: Faire en sorte que ça affiche les favoris des gens suivant
|
|
250
|
|
-// // le groupe
|
|
251
|
|
-// }
|
|
252
|
|
-// else
|
|
253
|
|
-// {
|
|
254
|
|
-// throw new Exception('For use favorite search element, you must specify an user_id or group_id');
|
|
255
|
|
-// }
|
|
256
|
|
-// }
|
|
257
|
|
-//
|
|
258
|
|
-// // Si id_limit est précisé c'est que l'on demande "la suite" ou "les nouveaux"
|
|
259
|
|
-// $where_id_limit = '';
|
|
260
|
|
-// if (($id_limit = $searcher->getIdLimit()) && !$searcher->isSearchingNew())
|
|
261
|
|
-// {
|
|
262
|
|
-// $where_id_limit = ($is_where) ? ' AND' : ' WHERE';
|
|
263
|
|
-// $is_where = true;
|
|
264
|
|
-// $where_id_limit .= " e_.id < :id_limit";
|
|
265
|
|
-// $params_ids['id_limit'] = $id_limit;
|
|
266
|
|
-// }
|
|
267
|
|
-// elseif ($id_limit && $searcher->isSearchingNew())
|
|
268
|
|
-// {
|
|
269
|
|
-// $where_id_limit = ($is_where) ? ' AND' : ' WHERE';
|
|
270
|
|
-// $is_where = true;
|
|
271
|
|
-// $where_id_limit .= " e_.id > :id_limit";
|
|
272
|
|
-// $params_ids['id_limit'] = $id_limit;
|
|
273
|
|
-// // Pour pouvoir charger les x nouveaux on doit organiser la liste
|
|
274
|
|
-// // de manière croissante
|
|
275
|
|
-// $order_by = "ORDER BY e_.created ASC, e_.id ASC";
|
|
276
|
|
-// }
|
|
277
|
|
-//
|
|
278
|
|
-//
|
|
279
|
|
-// // Recherche strict ou non ?
|
|
280
|
|
-// $where_tag_strict = '';
|
|
281
|
|
-// if ($searcher->getTagStrict() && count($tags))
|
|
282
|
|
-// {
|
|
283
|
|
-// // On a besoin de récupérer la liste des element_id qui ont les tags
|
|
284
|
|
-// // demandés.
|
|
285
|
|
-// $tag_ids = '';
|
|
286
|
|
-// foreach ($tags as $tag_id => $tag_name)
|
|
287
|
|
-// {
|
|
288
|
|
-// if ($tag_ids === '')
|
|
289
|
|
-// {
|
|
290
|
|
-// $tag_ids .= (int)$tag_id;
|
|
291
|
|
-// }
|
|
292
|
|
-// else
|
|
293
|
|
-// {
|
|
294
|
|
-// $tag_ids .= ','.(int)$tag_id;
|
|
295
|
|
-// }
|
|
296
|
|
-// }
|
|
297
|
|
-//
|
|
298
|
|
-// $sql = "SELECT et.element_id FROM elements_tag et "
|
|
299
|
|
-// ."WHERE et.tag_id IN ($tag_ids) group by et.element_id "
|
|
300
|
|
-// ."having count(distinct et.tag_id) = ".count($tags);
|
|
301
|
|
-// $rsm = new \Doctrine\ORM\Query\ResultSetMapping;
|
|
302
|
|
-// $rsm->addScalarResult('element_id', 'element_id');
|
|
303
|
|
-//
|
|
304
|
|
-// $strict_element_ids_result = $this->getEntityManager()
|
|
305
|
|
-// ->createNativeQuery($sql, $rsm)
|
|
306
|
|
-// //->setParameter('ids', $tag_ids)
|
|
307
|
|
-// ->getScalarResult()
|
|
308
|
|
-// ;
|
|
309
|
|
-//
|
|
310
|
|
-// $strict_element_ids = array();
|
|
311
|
|
-// foreach ($strict_element_ids_result as $strict_id)
|
|
312
|
|
-// {
|
|
313
|
|
-// $strict_element_ids[] = $strict_id['element_id'];
|
|
314
|
|
-// }
|
|
315
|
|
-//
|
|
316
|
|
-// if (count($strict_element_ids))
|
|
317
|
|
-// {
|
|
318
|
|
-// $where_tag_strict = ($is_where) ? ' AND' : ' WHERE';
|
|
319
|
|
-// $where_tag_strict .= ' e_.id IN (:tag_strict_ids)';
|
|
320
|
|
-// $params_ids['tag_strict_ids'] = $strict_element_ids;
|
|
321
|
|
-// }
|
|
322
|
|
-// // Ce else palie au bug du au cas ou $strict_element_ids est egal a array();
|
|
323
|
|
-// else
|
|
324
|
|
-// {
|
|
325
|
|
-// $where_tag_strict = ($is_where) ? ' AND' : ' WHERE';
|
|
326
|
|
-// $where_tag_strict .= ' 1 = 2';
|
|
327
|
|
-// }
|
|
328
|
|
-// }
|
|
329
|
|
-//
|
|
330
|
|
-// // Requête qui selectionnera les ids en fonction des critéres
|
|
331
|
|
-// $id_query = $this->getEntityManager()
|
|
332
|
|
-// ->createQuery(
|
|
333
|
|
-// "SELECT e_.id
|
|
334
|
|
-// FROM MuzichCoreBundle:Element e_
|
|
335
|
|
-// $join_tags
|
|
336
|
|
-// $join_network
|
|
337
|
|
-// $join_favorite
|
|
338
|
|
-// $where_tags
|
|
339
|
|
-// $where_network
|
|
340
|
|
-// $where_user
|
|
341
|
|
-// $where_group
|
|
342
|
|
-// $where_favorite
|
|
343
|
|
-// $where_tag_strict
|
|
344
|
|
-// $where_string
|
|
345
|
|
-// $where_id_limit
|
|
346
|
|
-// GROUP BY e_.id
|
|
347
|
|
-// $order_by")
|
|
348
|
|
-// ->setParameters($params_ids)
|
|
349
|
|
-// ;
|
|
350
|
|
-//
|
|
351
|
|
-// // Si on a précisé que l'on voulait un count, pas de limite
|
|
352
|
|
-// if ($exec_type != 'count')
|
|
353
|
|
-// {
|
|
354
|
|
-// $id_query->setMaxResults($searcher->getCount());
|
|
355
|
|
-// }
|
|
356
|
|
-//
|
|
357
|
|
-// // si l'on a demandé un count
|
|
358
|
|
-// if ($exec_type == 'count')
|
|
359
|
|
-// {
|
|
360
|
|
-// // On retourne cette query
|
|
361
|
|
-// return $id_query;
|
|
362
|
|
-// }
|
|
363
|
|
-//
|
|
364
|
|
-// $r_ids = $id_query->getArrayResult();
|
|
365
|
|
-//
|
|
366
|
|
-// $ids = array();
|
|
367
|
|
-//
|
|
368
|
|
-// if (count($r_ids))
|
|
369
|
|
-// {
|
|
370
|
|
-// foreach ($r_ids as $r_id)
|
|
371
|
|
-// {
|
|
372
|
|
-// $ids[] = $r_id['id'];
|
|
373
|
|
-// }
|
|
374
|
|
-//
|
|
375
|
|
-// return $this->getSelectElementForSearchQuery($params_select, $user_id, $ids);
|
|
376
|
|
-// }
|
|
377
|
|
-//
|
|
378
|
|
-// // Il faut retourner une Query
|
|
379
|
|
-// return $query = $this->getEntityManager()
|
|
380
|
|
-// ->createQuery("SELECT e FROM MuzichCoreBundle:Element e WHERE 1 = 2")
|
|
381
|
|
-// ;
|
|
382
|
|
-// }
|
|
383
|
|
-
|
|
384
|
56
|
protected function getSelectElementForSearchQuery($params_select, $user_id, $ids, $id_limit = null, $count_limit = null, $ids_display = null)
|
|
385
|
57
|
{
|
|
386
|
58
|
$where = "";
|
|
|
@@ -408,6 +80,7 @@ class ElementRepository extends EntityRepository
|
|
408
|
80
|
$left_join
|
|
409
|
81
|
JOIN e.owner o
|
|
410
|
82
|
WHERE e.id IN (:ids) $where
|
|
|
83
|
+ AND WHERE e.private = 0
|
|
411
|
84
|
ORDER BY e.created DESC, e.id DESC"
|
|
412
|
85
|
;
|
|
413
|
86
|
|
|
|
@@ -443,6 +116,7 @@ class ElementRepository extends EntityRepository
|
|
443
|
116
|
JOIN e.group g
|
|
444
|
117
|
JOIN e.tags t
|
|
445
|
118
|
WHERE u.id = :uid
|
|
|
119
|
+ AND WHERE e.private = 0
|
|
446
|
120
|
ORDER BY e.created DESC'
|
|
447
|
121
|
)
|
|
448
|
122
|
->setParameter('uid', $user_id)
|
|
|
@@ -467,6 +141,7 @@ class ElementRepository extends EntityRepository
|
|
467
|
141
|
JOIN e.group g
|
|
468
|
142
|
JOIN e.tags t
|
|
469
|
143
|
WHERE g.id = :gid
|
|
|
144
|
+ AND WHERE e.private = 0
|
|
470
|
145
|
ORDER BY e.created DESC'
|
|
471
|
146
|
)
|
|
472
|
147
|
->setParameter('gid', $group_id)
|
|
|
@@ -513,20 +188,32 @@ class ElementRepository extends EntityRepository
|
|
513
|
188
|
/**
|
|
514
|
189
|
* WARNING: Seulement compatibel avec MySQL !!
|
|
515
|
190
|
*/
|
|
516
|
|
- public function getElementsWithIdsOrderingQueryBuilder($element_ids)
|
|
|
191
|
+ public function getElementsWithIdsOrderingQueryBuilder($element_ids, $show_privates = false, $user_id = true)
|
|
517
|
192
|
{
|
|
518
|
193
|
$doctrineConfig = $this->getEntityManager()->getConfiguration();
|
|
519
|
194
|
$doctrineConfig->addCustomStringFunction('FIELD', 'Muzich\CoreBundle\DoctrineExtensions\Query\Mysql\Field');
|
|
520
|
195
|
|
|
521
|
196
|
if (count($element_ids))
|
|
522
|
197
|
{
|
|
523
|
|
- return $this->getEntityManager()->createQueryBuilder()
|
|
|
198
|
+ $qb = $this->getEntityManager()->createQueryBuilder()
|
|
524
|
199
|
->select('e, field(e.id, ' . implode(', ', $element_ids) . ') as HIDDEN field')
|
|
525
|
200
|
->from('MuzichCoreBundle:Element', 'e')
|
|
526
|
201
|
->where('e.id IN (:element_ids)')
|
|
527
|
202
|
->setParameter('element_ids', $element_ids)
|
|
528
|
203
|
->orderBy('field')
|
|
529
|
204
|
;
|
|
|
205
|
+
|
|
|
206
|
+ if (!$show_privates)
|
|
|
207
|
+ {
|
|
|
208
|
+ $qb->andWhere('e.private = 0');
|
|
|
209
|
+ }
|
|
|
210
|
+ else if ($user_id)
|
|
|
211
|
+ {
|
|
|
212
|
+ $qb->andWhere('(e.private = 0 OR (e.private = 1 AND e.owner = :owner_id))');
|
|
|
213
|
+ $qb->setParameter('owner_id', $user_id);
|
|
|
214
|
+ }
|
|
|
215
|
+
|
|
|
216
|
+ return $qb;
|
|
530
|
217
|
}
|
|
531
|
218
|
|
|
532
|
219
|
return $this->getEntityManager()->createQueryBuilder()
|