Pārlūkot izejas kodu

Evolution #677: Soundcloud: tags proposés

Sevajol Bastien 11 gadus atpakaļ
vecāks
revīzija
1e339b1845

+ 1 - 1
src/Muzich/CoreBundle/Controller/ElementController.php Parādīt failu

@@ -933,7 +933,7 @@ class ElementController extends Controller
933 933
   
934 934
   protected function findTagsWithProposeds($tags)
935 935
   {
936
-    $tag_like = new TagLike($this->getDoctrine());
936
+    $tag_like = new TagLike($this->getDoctrine()->getEntityManager());
937 937
     $tags_with_likes = array();
938 938
     foreach ($tags as $tag_name)
939 939
     {

+ 1 - 1
src/Muzich/CoreBundle/Controller/SearchController.php Parādīt failu

@@ -258,7 +258,7 @@ class SearchController extends Controller
258 258
       if (strlen(trim($string_search)) > 1)
259 259
       {
260 260
         // On utilise l'objet TagLike
261
-        $TagLike = new TagLike($this->getDoctrine());
261
+        $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
262 262
         // Pour trier nos tags d'une manière plus humaine
263 263
         $sort_response = $TagLike->getSimilarTags($string_search, $this->getUserId());
264 264
       

+ 4 - 1
src/Muzich/CoreBundle/Factory/ElementFactory.php Parādīt failu

@@ -5,6 +5,7 @@ namespace Muzich\CoreBundle\Factory;
5 5
 use Muzich\CoreBundle\Entity\Element;
6 6
 use Symfony\Component\DependencyInjection\Container;
7 7
 use \Exception;
8
+use Doctrine\ORM\EntityManager;
8 9
 
9 10
 /**
10 11
  *
@@ -19,16 +20,18 @@ abstract class ElementFactory
19 20
    */
20 21
   protected $element;
21 22
   protected $container;
23
+  protected $entity_manager;
22 24
   
23 25
   /**
24 26
    *
25 27
    * @param Element $element
26 28
    * @param Container $container 
27 29
    */
28
-  public function __construct(Element $element, Container $container)
30
+  public function __construct(Element $element, Container $container, EntityManager $entity_manager)
29 31
   {
30 32
     $this->element   = $element;
31 33
     $this->container = $container;
34
+    $this->entity_manager = $entity_manager;
32 35
   }
33 36
   
34 37
   /**

+ 37 - 3
src/Muzich/CoreBundle/Factory/Elements/Soundcloudcom.php Parādīt failu

@@ -4,6 +4,7 @@ namespace Muzich\CoreBundle\Factory\Elements;
4 4
 
5 5
 use Muzich\CoreBundle\Factory\ElementFactory;
6 6
 use Muzich\CoreBundle\Entity\Element;
7
+use Muzich\CoreBundle\Util\TagLike;
7 8
 
8 9
 /**
9 10
  * 
@@ -186,16 +187,49 @@ class Soundcloudcom extends ElementFactory
186 187
         {
187 188
           $this->element->setData(Element::DATA_ARTIST, $result['user']['username']);
188 189
         }
189
-
190
+        
191
+        $genres = '';
190 192
         if (array_key_exists('genre', $result) )
191 193
         {
192 194
           if (strlen($result['genre']))
193 195
           {
194
-            $this->element->setData(Element::DATA_TAGS, array($result['genre']));
196
+            $genres = $result['genre'];
197
+          }
198
+        }
199
+        
200
+        $tags_list = '';
201
+        if (array_key_exists('tag_list', $result) )
202
+        {
203
+          if (strlen($result['tag_list']))
204
+          {
205
+            $tags_list = $result['tag_list'];
195 206
           }
196 207
         }
208
+        
209
+        $tags_string = $genres.' '.$tags_list.' '.str_replace(' ', '-', $genres);
210
+        $tags_like = array();
211
+        if (strlen($tags_string))
212
+        {
213
+          $tag_like = new TagLike($this->entity_manager);
214
+          foreach (explode(' ', $tags_string) as $word)
215
+          {
216
+            $similar_tags = $tag_like->getSimilarTags($word, $this->element->getOwner()->getId());
217
+            if (count($similar_tags))
218
+            {
219
+              if ($similar_tags['same_found'])
220
+              {
221
+                $tags_like[] = $similar_tags['tags'][0]['name'];
222
+              }
223
+            }
224
+          }
225
+          $tags_like[] = $genres;
226
+          if (count($tags_like))
227
+          {
228
+            $this->element->setData(Element::DATA_TAGS, array_unique($tags_like));
229
+          }
230
+        }
231
+        
197 232
       }
198
-            
199 233
     }
200 234
   }
201 235
   

+ 8 - 8
src/Muzich/CoreBundle/Managers/ElementManager.php Parādīt failu

@@ -152,28 +152,28 @@ class ElementManager
152 152
     switch ($this->element->getType())
153 153
     {
154 154
       case 'youtube.com':
155
-        return new Youtubecom($this->element, $this->container);
155
+        return new Youtubecom($this->element, $this->container, $this->em);
156 156
       break;
157 157
       case 'youtu.be':
158
-        return new Youtube($this->element, $this->container);
158
+        return new Youtube($this->element, $this->container, $this->em);
159 159
       break;
160 160
       case 'soundcloud.com':
161
-        return new Soundcloudcom($this->element, $this->container);
161
+        return new Soundcloudcom($this->element, $this->container, $this->em);
162 162
       break;
163 163
       case 'jamendo.com':
164
-        return new Jamendocom($this->element, $this->container);
164
+        return new Jamendocom($this->element, $this->container, $this->em);
165 165
       break;
166 166
       case 'dailymotion.com':
167
-        return new Dailymotioncom($this->element, $this->container);
167
+        return new Dailymotioncom($this->element, $this->container, $this->em);
168 168
       break;
169 169
       case 'deezer.com':
170
-        return new Deezercom($this->element, $this->container);
170
+        return new Deezercom($this->element, $this->container, $this->em);
171 171
       break;
172 172
       case 'vimeo.com':
173
-        return new Vimeocom($this->element, $this->container);
173
+        return new Vimeocom($this->element, $this->container, $this->em);
174 174
       break;
175 175
       case 'spotify.com':
176
-        return new Spotifycom($this->element, $this->container);
176
+        return new Spotifycom($this->element, $this->container, $this->em);
177 177
       break;
178 178
       default:
179 179
         throw new \Exception("La Factory n'est pas prise en charge pour ce type.");

+ 27 - 1
src/Muzich/CoreBundle/Tests/ElementFactory/ElementFactoryTest.php Parādīt failu

@@ -373,9 +373,35 @@ class ElementFactoryTest extends UnitTest
373 373
       'data_download' => null,
374 374
       'data_download_url' => 'http://soundcloud.com/matas/sets/library-project/download',
375 375
       'data_artist' => 'matas',
376
-      'data_normalized_url' => 'http://api.soundcloud.com/playlists/3770'
376
+      'data_normalized_url' => 'http://api.soundcloud.com/playlists/3770',
377
+      'data_tags' => array(0 => '')
377 378
     ),$datas);
378 379
     
380
+    // Test des tags récupérés
381
+    $datas = $this->proceed_element_datas_api(
382
+      $bux, 
383
+      'https://soundcloud.com/mixessss3/white-stripes-vs-led-zeppelin-icky-kinky-love-rock-mashup-dj-zebra'
384
+    );
385
+    
386
+    $this->assertTrue(array_key_exists('data_thumb_url', $datas));
387
+    if (array_key_exists('data_thumb_url', $datas))
388
+    {
389
+      unset($datas['data_thumb_url']);
390
+    }
391
+    
392
+    $this->assertEquals(array(
393
+      'data_ref_id' => 2215186,
394
+      'data_title' => 'White Stripes Vs Led Zeppelin - Icky Kinky Love (Rock Mashup) DJ Zebra',
395
+      //'data_thumb_url' => 'http://i1.sndcdn.com/artworks-000000514203-fsvbcj-large.jpg?51826bf',
396
+      'data_type' => 'track',
397
+      'data_download' => false,
398
+      'data_download_url' => 'https://soundcloud.com/mixessss3/white-stripes-vs-led-zeppelin-icky-kinky-love-rock-mashup-dj-zebra/download',
399
+      'data_artist' => 'Mixes and Mashups #3',
400
+      'data_normalized_url' => 'http://api.soundcloud.com/tracks/2215186',
401
+      'data_tags' => array(0 => 'Rock', 1 => 'rock  ')
402
+    ),$datas);
403
+    
404
+    
379 405
     // 'http://soundcloud.com/matas/above-hyperion-redux'
380 406
     $datas = $this->proceed_element_datas_api(
381 407
       $bux, 

+ 7 - 7
src/Muzich/CoreBundle/Tests/Tag/TagReadTest.php Parādīt failu

@@ -49,7 +49,7 @@ class TagReadTest extends UnitTest
49 49
         'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk' 
50 50
     );
51 51
     
52
-    $TagLike = new TagLike($this->getDoctrine());
52
+    $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
53 53
     $response = $TagLike->getSimilarTags('punk', $bux->getId());
54 54
     
55 55
     $this->assertEquals(count($cresults), count($response['tags']));
@@ -73,7 +73,7 @@ class TagReadTest extends UnitTest
73 73
         'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk' 
74 74
     );
75 75
     
76
-    $TagLike = new TagLike($this->getDoctrine());
76
+    $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
77 77
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk', $bux->getId()));
78 78
     
79 79
     $this->assertEquals($cresults, $tags);
@@ -85,7 +85,7 @@ class TagReadTest extends UnitTest
85 85
         'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk' 
86 86
     );
87 87
     
88
-    $TagLike = new TagLike($this->getDoctrine());
88
+    $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
89 89
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('anarcho punk', $bux->getId()));
90 90
     
91 91
     $this->assertEquals($cresults, $tags);
@@ -97,7 +97,7 @@ class TagReadTest extends UnitTest
97 97
         'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk' 
98 98
     );
99 99
     
100
-    $TagLike = new TagLike($this->getDoctrine());
100
+    $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
101 101
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk anarcho', $bux->getId()));
102 102
     
103 103
     $this->assertEquals($cresults, $tags);
@@ -109,7 +109,7 @@ class TagReadTest extends UnitTest
109 109
         'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk' 
110 110
     );
111 111
     
112
-    $TagLike = new TagLike($this->getDoctrine());
112
+    $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
113 113
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk anar', $bux->getId()));
114 114
     
115 115
     $this->assertEquals($cresults, $tags);
@@ -121,7 +121,7 @@ class TagReadTest extends UnitTest
121 121
         'Pop-punk', 'Post-Punk', 'Punk rock', 'Ska-jazz', 'Skacore',  'Synthpunk' 
122 122
     );
123 123
     
124
-    $TagLike = new TagLike($this->getDoctrine());
124
+    $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
125 125
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('ska punk', $bux->getId()));
126 126
     
127 127
     $this->assertEquals($cresults, $tags);
@@ -132,7 +132,7 @@ class TagReadTest extends UnitTest
132 132
       'Horror punk'
133 133
     );
134 134
     
135
-    $TagLike = new TagLike($this->getDoctrine());
135
+    $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
136 136
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('horror', $bux->getId()));
137 137
     
138 138
     $this->assertEquals($cresults, $tags);

+ 1 - 1
src/Muzich/CoreBundle/Tests/User/UserTest.php Parādīt failu

@@ -41,7 +41,7 @@ class UserTest extends UnitTest
41 41
         $jungle->getId() => 'Jungle',
42 42
         $hardtek->getId()  => 'Hardtek',
43 43
         array_search('Nouveau 1', $bux->getTagsFavoritesQuick())  => 'Nouveau 1'
44
-      ), $bux->getTagsFavoritesQuick());
44
+      ), array_unique($bux->getTagsFavoritesQuick()));
45 45
     }
46 46
     else
47 47
     {

+ 5 - 5
src/Muzich/CoreBundle/Util/TagLike.php Parādīt failu

@@ -2,8 +2,8 @@
2 2
 
3 3
 namespace Muzich\CoreBundle\Util;
4 4
 
5
-use Doctrine\Bundle\DoctrineBundle\Registry;
6 5
 use Muzich\CoreBundle\Util\StrictCanonicalizer;
6
+use Doctrine\ORM\EntityManager;
7 7
 
8 8
 /**
9 9
  * Cette classe permet d'aider a la recherche de mot similaires a un mot
@@ -13,11 +13,11 @@ use Muzich\CoreBundle\Util\StrictCanonicalizer;
13 13
 class TagLike
14 14
 {
15 15
   
16
-  protected $registry;
16
+  protected $entity_manager;
17 17
   
18
-  public function __construct(Registry $registry)
18
+  public function __construct(EntityManager $entity_manager)
19 19
   {
20
-    $this->registry = $registry;
20
+    $this->entity_manager = $entity_manager;
21 21
   }
22 22
   
23 23
   /**
@@ -168,7 +168,7 @@ class TagLike
168 168
     }
169 169
 
170 170
     $params['uid'] = '%"'.$user_id.'"%';
171
-    $tags_query = $this->registry->getEntityManager()->createQuery("
171
+    $tags_query = $this->entity_manager->createQuery("
172 172
       SELECT t.name, t.slug, t.id FROM MuzichCoreBundle:Tag t
173 173
       $where
174 174