Browse Source

Evolution #387: Ordre des tags

Sevajol Bastien 11 years ago
parent
commit
1e676907a5

+ 31 - 12
src/Muzich/CoreBundle/Command/TagOrderCommand.php View File

@@ -19,6 +19,7 @@ class TagOrderCommand extends ContainerAwareCommand
19 19
     $this
20 20
       ->setName('tagengine:order')
21 21
       ->setDescription('Ordonne la liste des tags sur les pages utilisateurs')
22
+      ->addOption('force', null, InputOption::VALUE_NONE, 'Forcer les opérations sur tous les utilisateurs')
22 23
     ;
23 24
   }
24 25
   
@@ -38,12 +39,21 @@ class TagOrderCommand extends ContainerAwareCommand
38 39
     $output->writeln('<info>Gestion de l\'ordre des tags sur les pages de '
39 40
       .'partages favoris</info>');
40 41
  
41
-    $users = $em->createQuery(
42
-        "SELECT u FROM MuzichCoreBundle:User u"
43
-        . " WHERE u.datas LIKE :favupd"
44
-      )->setParameter('favupd', '%"'.User::DATA_FAV_UPDATED.'":true%')
45
-      ->getResult()
46
-    ;
42
+    if ($input->getOption('force'))
43
+    {
44
+      $users = $em->createQuery("SELECT u FROM MuzichCoreBundle:User u")
45
+        ->getResult()
46
+      ;
47
+    }
48
+    else
49
+    {
50
+      $users = $em->createQuery(
51
+          "SELECT u FROM MuzichCoreBundle:User u"
52
+          . " WHERE u.datas LIKE :favupd"
53
+        )->setParameter('favupd', '%"'.User::DATA_FAV_UPDATED.'":true%')
54
+        ->getResult()
55
+      ;
56
+    }
47 57
     
48 58
     if (count($users))
49 59
     {
@@ -77,12 +87,21 @@ class TagOrderCommand extends ContainerAwareCommand
77 87
     // diffusion
78 88
     $output->writeln('<info>Gestion de l\'ordre des tags sur les diffusions</info>');
79 89
  
80
-    $users = $em->createQuery(
81
-        "SELECT u FROM MuzichCoreBundle:User u"
82
-        . " WHERE u.datas LIKE :favupd"
83
-      )->setParameter('favupd', '%"'.User::DATA_DIFF_UPDATED.'":true%')
84
-      ->getResult()
85
-    ;
90
+    if ($input->getOption('force'))
91
+    {
92
+      $users = $em->createQuery("SELECT u FROM MuzichCoreBundle:User u")
93
+        ->getResult()
94
+      ;
95
+    }
96
+    else
97
+    {
98
+      $users = $em->createQuery(
99
+          "SELECT u FROM MuzichCoreBundle:User u"
100
+          . " WHERE u.datas LIKE :favupd"
101
+        )->setParameter('favupd', '%"'.User::DATA_DIFF_UPDATED.'":true%')
102
+        ->getResult()
103
+      ;
104
+    }
86 105
     
87 106
     if (count($users))
88 107
     {

+ 1 - 1
src/Muzich/CoreBundle/Controller/CoreController.php View File

@@ -198,7 +198,7 @@ class CoreController extends Controller
198 198
    *  Procédure d'ajout d'un element
199 199
    */
200 200
   public function elementAddAction($group_slug)
201
-  {   
201
+  {
202 202
     if (($response = $this->mustBeConnected()))
203 203
     {
204 204
       return $response;

+ 90 - 0
src/Muzich/CoreBundle/Tests/Tag/TagReadTest.php View File

@@ -4,6 +4,7 @@ namespace Muzich\CoreBundle\Tests\Searcher;
4 4
 
5 5
 use Muzich\CoreBundle\lib\UnitTest;
6 6
 use Muzich\CoreBundle\Util\TagLike;
7
+use Muzich\CoreBundle\lib\Tag as TagLib;
7 8
 
8 9
 class TagReadTest extends UnitTest
9 10
 {  
@@ -210,4 +211,93 @@ class TagReadTest extends UnitTest
210 211
     $this->assertEquals($rtags, $tags);
211 212
   }
212 213
   
214
+  /*
215
+   * Test des opération de création d'une liste ordonné de tags en fonction 
216
+   * d'une liste d'élèments
217
+   */
218
+  public function testTagOrder()
219
+  {
220
+    $bux = $this->getUser('bux');
221
+    $joelle = $this->getUser('joelle');
222
+    $tag_lib = new TagLib();
223
+    
224
+    $hardtek  = $this->findOneBy('Tag', array('name' => 'Hardtek'));
225
+    $metal    = $this->findOneBy('Tag', array('name' => 'Metal'));
226
+    $electro  = $this->findOneBy('Tag', array('name' => 'Electro'));
227
+    $hardcore = $this->findOneBy('Tag', array('name' => 'Hardcore'));
228
+    $chanteuse = $this->findOneBy('Tag', array('name' => 'Chanteuse'));
229
+    $dubstep  = $this->findOneBy('Tag', array('name' => 'Dubstep'));
230
+    $medieval = $this->findOneBy('Tag', array('name' => 'Medieval'));
231
+    $beatbox = $this->findOneBy('Tag', array('name' => 'Beatbox'));
232
+    
233
+    /*
234
+     * Test de la récuparéation de l'ordre des tags
235
+     */
236
+    
237
+    $search = new \Muzich\CoreBundle\Searcher\ElementSearcher();
238
+    $search->init(array(
239
+      'user_id'  => $bux->getId()
240
+    ));
241
+    $elements = $search->getElements($this->getDoctrine(), $bux->getId());
242
+    
243
+    $tag_reference = $tag_lib->getOrderedTagsWithElements($elements);
244
+    
245
+    $this->assertEquals(array(
246
+      $hardtek->getId(),
247
+      $metal->getId(),
248
+      $electro->getId(),
249
+      $hardcore->getId()
250
+    ), $tag_reference);
251
+    
252
+    ////////////
253
+    
254
+    
255
+    $search = new \Muzich\CoreBundle\Searcher\ElementSearcher();
256
+    $search->init(array(
257
+      'user_id'  => $joelle->getId()
258
+    ));
259
+    $elements = $search->getElements($this->getDoctrine(), $bux->getId());
260
+    
261
+    $tag_reference = $tag_lib->getOrderedTagsWithElements($elements);
262
+    
263
+    $this->assertEquals(array(
264
+      $chanteuse->getId(),
265
+      $dubstep->getId(),
266
+      $medieval->getId(),
267
+      $beatbox->getId()
268
+    ), $tag_reference);
269
+    
270
+    /*
271
+     * Test du trie de tags en fonction d'une liste référente
272
+     */
273
+    
274
+    // Tag non ordonés
275
+    $tags_disordered = array(
276
+      $medieval,
277
+      $beatbox,
278
+      $hardcore,
279
+      $dubstep,
280
+      $chanteuse
281
+    );
282
+    
283
+    // On ordonne tout ça avec la référence calculé juste avant
284
+    $tags_ordered = $tag_lib->sortTagWithOrderedReference($tags_disordered, $tag_reference);
285
+    
286
+    $tags_ordered_ids = array();
287
+    foreach ($tags_ordered as $tag_ordered)
288
+    {
289
+      $tags_ordered_ids[] = $tag_ordered->getId();
290
+    }
291
+    
292
+    $this->assertEquals(
293
+      array(
294
+        $chanteuse->getId(),
295
+        $dubstep->getId(),
296
+        $medieval->getId(),
297
+        $beatbox->getId(),
298
+        $hardcore->getId()
299
+      ), $tags_ordered_ids
300
+    );
301
+  }
302
+  
213 303
 }

+ 22 - 0
src/Muzich/CoreBundle/lib/UnitTest.php View File

@@ -103,4 +103,26 @@ class UnitTest extends \PHPUnit_Framework_TestCase
103 103
     $this->getDoctrine()->getEntityManager()->flush();
104 104
   }
105 105
   
106
+  /**
107
+   *
108
+   * @return \Doctrine\ORM\EntityManager 
109
+   */
110
+  protected function getEntityManager()
111
+  {
112
+    return $this->getDoctrine()->getEntityManager();
113
+  }
114
+  
115
+  /**
116
+   * Raccourcis de findOneBy
117
+   * 
118
+   * @param string $entityName
119
+   * @param array $params
120
+   * @return object 
121
+   */
122
+  protected function findOneBy($entityName, array $params)
123
+  {
124
+    return $this->getEntityManager()->getRepository('MuzichCoreBundle:'.$entityName)
125
+      ->findOneBy($params);
126
+  }
127
+  
106 128
 }