Bastien Sevajol 11 年 前
コミット
2e3ef63dab

+ 6 - 0
src/Muzich/CoreBundle/Managers/PlaylistManager.php ファイルの表示

@@ -247,4 +247,10 @@ class PlaylistManager
247 247
       ->findOneById($element_data['id']);
248 248
   }
249 249
   
250
+  public function getElementsObjects(Playlist $playlist)
251
+  {
252
+    return $this->entity_manager->getRepository('MuzichCoreBundle:Element')
253
+      ->findById($playlist->getElementsIds());
254
+  }
255
+  
250 256
 }

+ 10 - 5
src/Muzich/CoreBundle/Propagator/EventElement.php ファイルの表示

@@ -114,11 +114,12 @@ class EventElement extends EventPropagator
114 114
       $ur->addPoints($score_action);
115 115
       $element->addPoints($score_action);
116 116
       $element->increaseCountFavorited();
117
+      $this->getEntityManager()->persist($element);
117 118
     }
118 119
     
119 120
     $uea = new UserEventAction($element->getOwner(), $this->container);
120 121
     $event = $uea->proceed(Event::TYPE_FAV_ADDED_ELEMENT, $element->getId());
121
-    $this->container->get('doctrine')->getEntityManager()->persist($event);
122
+    $this->getEntityManager()->persist($event);
122 123
   }
123 124
   
124 125
   /**
@@ -136,6 +137,7 @@ class EventElement extends EventPropagator
136 137
       $ur->removePoints($score_action);
137 138
       $element->removePoints($score_action);
138 139
       $element->uncreaseCountFavorited();
140
+      $this->getEntityManager()->persist($element);
139 141
     }
140 142
   }
141 143
   
@@ -176,11 +178,14 @@ class EventElement extends EventPropagator
176 178
     ;
177 179
   }
178 180
   
179
-  public function removedFromPlaylist(Element $element, User $removed_by_user, Playlist $playlist)
181
+  public function removedFromPlaylist(Element $element, User $removed_by_user, Playlist $playlist, $persist_before = true)
180 182
   {
181
-    // On persiste les modifs pour compter correctement
182
-    $this->getEntityManager()->persist($playlist);
183
-    $this->getEntityManager()->flush();
183
+    if ($persist_before)
184
+    {
185
+      // On persiste les modifs pour compter correctement
186
+      $this->getEntityManager()->persist($playlist);
187
+      $this->getEntityManager()->flush();
188
+    }
184 189
     
185 190
     $ur = new UserReputation($element->getOwner());
186 191
     $security_context = new SecurityContext($removed_by_user);

+ 4 - 4
src/Muzich/PlaylistBundle/Controller/EditController.php ファイルの表示

@@ -32,7 +32,7 @@ class EditController extends Controller
32 32
     if (!$this->tokenIsCorrect() || !($playlist = $playlist_manager->findOwnedPlaylistWithId($playlist_id, $this->getUser())))
33 33
       return $this->jsonNotFoundResponse();
34 34
     
35
-    $element = $playlist_manager->getElementWithIndex($index);
35
+    $element = $playlist_manager->getElementWithIndex($playlist, $index);
36 36
     $playlist_manager->removePlaylistElementWithIndex($playlist, $index);
37 37
     
38 38
     $event = new EventElement($this->container);
@@ -56,7 +56,7 @@ class EditController extends Controller
56 56
     $playlist_manager->addElementToPlaylist($element, $playlist);
57 57
     
58 58
     $event = new EventElement($this->container);
59
-    $event->addedFromPlaylist($element, $this->getUser(), $playlist);
59
+    $event->addedToPlaylist($element, $this->getUser(), $playlist);
60 60
     
61 61
     $this->persist($element);
62 62
     $this->flush();
@@ -78,7 +78,7 @@ class EditController extends Controller
78 78
       $this->getPlaylistManager()->addElementToPlaylist($element, $form->getData());
79 79
       
80 80
       $event = new EventElement($this->container);
81
-      $event->addedFromPlaylist($element, $this->getUser(), $form->getData());
81
+      $event->addedToPlaylist($element, $this->getUser(), $form->getData());
82 82
 
83 83
       $this->persist($element);
84 84
       $this->flush();
@@ -109,7 +109,7 @@ class EditController extends Controller
109 109
     $this->getPlaylistManager()->removePickedPlaylistToUser($this->getUser(), $playlist);
110 110
     
111 111
     $event = new EventElement($this->container);
112
-    $event->addedFromPlaylist($element, $this->getUser(), $new_playlist);
112
+    $event->addedToPlaylist($element, $this->getUser(), $new_playlist);
113 113
     
114 114
     $this->persist($element);
115 115
     $this->flush();