|
@@ -348,13 +348,10 @@ class User extends BaseUser
|
348
|
348
|
*/
|
349
|
349
|
public function updateTagsFavoritesById(EntityManager $em, $ids)
|
350
|
350
|
{
|
351
|
|
- // TODO: attention aux relations déjà existantes.
|
352
|
|
- // TODO penser a supprimer celles qui n'existes plus.
|
353
|
|
-
|
354
|
351
|
$ids_to_add = $ids;
|
355
|
352
|
|
356
|
353
|
// Pour chacun des tags favoris
|
357
|
|
- foreach ($this->tags_favorites as $tag_favorite)
|
|
354
|
+ foreach ($this->tags_favorites as $ii => $tag_favorite)
|
358
|
355
|
{
|
359
|
356
|
$trouve = false;
|
360
|
357
|
foreach ($ids as $i => $id)
|
|
@@ -365,6 +362,7 @@ class User extends BaseUser
|
365
|
362
|
// Si le tag était favoris déjà avant (et aussi maintenant)
|
366
|
363
|
// il ne sera ni a ajouter, ni a supprimer.
|
367
|
364
|
unset($ids_to_add[$i]);
|
|
365
|
+ var_dump($ids_to_add);
|
368
|
366
|
}
|
369
|
367
|
}
|
370
|
368
|
|
|
@@ -376,27 +374,26 @@ class User extends BaseUser
|
376
|
374
|
}
|
377
|
375
|
}
|
378
|
376
|
|
379
|
|
- $tag_favorite_position_max = $this->getTagFavoritePositionMax();
|
380
|
|
-
|
381
|
|
- // Pour les nouveaux ids restants
|
382
|
|
- foreach ($ids as $id)
|
|
377
|
+ if (count($ids_to_add))
|
383
|
378
|
{
|
384
|
|
- $tag = $em->getRepository('MuzichCoreBundle:Tag')
|
385
|
|
- ->findOneById($id)
|
386
|
|
- ;
|
387
|
|
-
|
388
|
|
- $tag_favorite = new UsersTagsFavorites();
|
389
|
|
- $tag_favorite->setUser($this);
|
390
|
|
- $tag_favorite->setTag($tag);
|
391
|
|
- $tag_favorite->setPosition($tag_favorite_position_max);
|
392
|
|
- $tag_favorite_position_max++;
|
393
|
|
-
|
394
|
|
- $this->addUsersTagsFavorites($tag_favorite);
|
395
|
|
- $em->persist($tag_favorite);
|
|
379
|
+ $tag_favorite_position_max = $this->getTagFavoritePositionMax();
|
|
380
|
+ $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids_to_add)->execute();
|
|
381
|
+
|
|
382
|
+ // Pour les nouveaux ids restants
|
|
383
|
+ foreach ($tags as $tag)
|
|
384
|
+ {
|
|
385
|
+ $tag_favorite = new UsersTagsFavorites();
|
|
386
|
+ $tag_favorite->setUser($this);
|
|
387
|
+ $tag_favorite->setTag($tag);
|
|
388
|
+ $tag_favorite->setPosition($tag_favorite_position_max);
|
|
389
|
+ $tag_favorite_position_max++;
|
|
390
|
+
|
|
391
|
+ $this->addUsersTagsFavorites($tag_favorite);
|
|
392
|
+ $em->persist($tag_favorite);
|
|
393
|
+ }
|
396
|
394
|
}
|
397
|
395
|
|
398
|
396
|
$em->flush();
|
399
|
|
-
|
400
|
397
|
}
|
401
|
398
|
|
402
|
399
|
/**
|