Просмотр исходного кода

Evolution #807: Rendre ou enlever "public" de sa playlist

Bastien Sevajol 11 лет назад
Родитель
Сommit
3f2a7fdb7f

+ 3 - 6
src/Muzich/CoreBundle/Form/Playlist/PlaylistForm.php Просмотреть файл

@@ -14,12 +14,9 @@ class PlaylistForm extends AbstractType
14 14
       'required' => true,
15 15
     ));
16 16
     
17
-    if (!$options['data']->getId())
18
-    {
19
-      $builder->add('public', 'checkbox', array(
20
-        'required' => false,
21
-      ));
22
-    }
17
+    $builder->add('public', 'checkbox', array(
18
+      'required' => false,
19
+    ));
23 20
   }
24 21
 
25 22
   public function getName()

+ 8 - 15
src/Muzich/CoreBundle/Managers/PlaylistManager.php Просмотреть файл

@@ -135,26 +135,12 @@ class PlaylistManager
135 135
     $playlist_copied = new Playlist();
136 136
     $playlist_copied->setOwner($user);
137 137
     $playlist_copied->setName($playlist->getName());
138
-    $playlist_copied->setPublic(true);
138
+    $playlist_copied->setPublic(false);
139 139
     $playlist_copied->setTags($playlist->getTags());
140 140
     $playlist_copied->setElements($playlist->getElements());
141 141
     $playlist_copied->setCopied($playlist);
142 142
     $playlist->addCopy($playlist_copied);
143
-    
144
-    //foreach ($user->getPlaylistsOwneds() as $fuck)
145
-    //{
146
-    //  var_dump($fuck->getName());
147
-    //}
148
-    //
149 143
     $user->getPlaylistsOwneds()->add($playlist_copied);
150
-    //
151
-    //var_dump($playlist_copied->getOwner()->getUsername());
152
-    //
153
-    //foreach ($user->getPlaylistsOwneds() as $fuck)
154
-    //{
155
-    //  var_dump($fuck->getName());
156
-    //}
157
-    //die();
158 144
     
159 145
     $this->entity_manager->persist($playlist_copied);
160 146
     $this->entity_manager->persist($user);
@@ -246,4 +232,11 @@ class PlaylistManager
246 232
     }
247 233
   }
248 234
   
235
+  public function privatizePlaylist(Playlist $playlist)
236
+  {
237
+    $this->copyPlaylistForPickedUsers($playlist);
238
+    $playlist->setPublic(false);
239
+    $this->entity_manager->persist($playlist);
240
+  }
241
+  
249 242
 }

+ 23 - 2
src/Muzich/CoreBundle/Tests/Controller/PlaylistControllerTest.php Просмотреть файл

@@ -403,7 +403,7 @@ class PlaylistControllerTest extends FunctionalTest
403 403
   
404 404
   protected function checkPlaylistOwnedBy($playlist, $user)
405 405
   {
406
-    $this->assertEquals($playlist->getOwner()->getId(), $user->getId());
406
+    $this->assertEquals($playlist->getOwner()->getUsername(), $user->getUsername());
407 407
   }
408 408
   
409 409
   protected function checkPlaylistNotOwnedBy($playlist, $user)
@@ -425,6 +425,26 @@ class PlaylistControllerTest extends FunctionalTest
425 425
     $this->checkPlaylistOwnedBy($this->playlists['bux_bob_pub'], $this->users['bux']);
426 426
   }
427 427
   
428
+  public function testCopyWhenPickedPlaylistPrivatized()
429
+  {
430
+    $this->init();
431
+    $this->initCopysContextData();
432
+    $this->connectUser('bob', 'toor');
433
+    
434
+    $this->checkPlaylistPickedBy($this->playlists['bob_pub'], $this->users['bux']);
435
+    $this->checkPlaylistNotOwnedBy($this->playlists['bob_pub'], $this->users['bux']);
436
+    
437
+    $this->playlists['bob_pub']->setPublic(false);
438
+    $this->updatePlaylist($this->playlists['bob_pub']);
439
+    $this->playlists['bux_bob_pub'] = $this->findOneBy('Playlist', array(
440
+      'name' => 'A travers l\'espace',
441
+      'owner' => $this->users['bux']->getId()
442
+    ));
443
+    $this->assertTrue(!is_null($this->playlists['bux_bob_pub']));
444
+    $this->assertEquals(false, $this->playlists['bux_bob_pub']->isPublic());
445
+    $this->checkPlaylistOwnedBy($this->playlists['bux_bob_pub'], $this->users['bux']);
446
+  }
447
+  
428 448
   protected function deletePlaylist($playlist)
429 449
   {
430 450
     $this->tests_cases->playlistDelete($playlist->getId());
@@ -463,7 +483,7 @@ class PlaylistControllerTest extends FunctionalTest
463 483
   
464 484
   public function testUpdate()
465 485
   {
466
-     $this->init();
486
+    $this->init();
467 487
     $this->initReadContextData();
468 488
     $this->connectUser('bux', 'toor');
469 489
     $this->goToPage($this->generateUrl('playlist', array('user_slug' => $this->users['bux']->getSlug(), 'playlist_id' => $this->playlists['bux_1_pub']->getId())));
@@ -487,6 +507,7 @@ class PlaylistControllerTest extends FunctionalTest
487 507
     
488 508
     $form = $this->selectForm('form.playlist_edit input[type="submit"]');
489 509
     $form['playlist[name]'] = $playlist->getName();
510
+    $form['playlist[public]'] = $playlist->isPublic();
490 511
     $this->submit($form);
491 512
   }
492 513
   

+ 6 - 0
src/Muzich/PlaylistBundle/Controller/EditController.php Просмотреть файл

@@ -174,10 +174,16 @@ class EditController extends Controller
174 174
       throw $this->createNotFoundException();
175 175
     
176 176
     $playlist_name = $playlist->getName();
177
+    $playlist_public = $playlist->isPublic();
177 178
     $form = $this->getPlaylistForm($playlist);
178 179
     $form->bind($request);
179 180
     if ($form->isValid())
180 181
     {
182
+      if ($playlist_public && !$playlist->isPublic())
183
+      {
184
+        $this->getPlaylistManager()->privatizePlaylist($playlist);
185
+      }
186
+      
181 187
       $this->persist($form->getData());
182 188
       $this->flush();
183 189
       

+ 3 - 5
src/Muzich/PlaylistBundle/Resources/views/Show/form.html.twig Просмотреть файл

@@ -5,11 +5,9 @@
5 5
 {{ form_errors(form) }}
6 6
 {{ form_errors(form.name) }}
7 7
 
8
-{% if display_public_widget %}
9
-  {{ form_errors(form.public) }}
10
-  {{ form_widget(form.public) }}
11
-  <label for="playlist_public">{{ 'playlist.public_label'|trans({}, 'elements') }}</label>
12
-{% endif %}
8
+{{ form_errors(form.public) }}
9
+{{ form_widget(form.public) }}
10
+<label for="playlist_public">{{ 'playlist.public_label'|trans({}, 'elements') }}</label>
13 11
 
14 12
 <div class="field">
15 13
   {{ form_widget(form.name, {'attr':{'class':'niceinput'}}) }}