Преглед на файлове

Evolution #677: Soundcloud: tags proposés

Sevajol Bastien преди 11 години
родител
ревизия
1e339b1845

+ 1 - 1
src/Muzich/CoreBundle/Controller/ElementController.php Целия файл

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

+ 1 - 1
src/Muzich/CoreBundle/Controller/SearchController.php Целия файл

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

+ 4 - 1
src/Muzich/CoreBundle/Factory/ElementFactory.php Целия файл

5
 use Muzich\CoreBundle\Entity\Element;
5
 use Muzich\CoreBundle\Entity\Element;
6
 use Symfony\Component\DependencyInjection\Container;
6
 use Symfony\Component\DependencyInjection\Container;
7
 use \Exception;
7
 use \Exception;
8
+use Doctrine\ORM\EntityManager;
8
 
9
 
9
 /**
10
 /**
10
  *
11
  *
19
    */
20
    */
20
   protected $element;
21
   protected $element;
21
   protected $container;
22
   protected $container;
23
+  protected $entity_manager;
22
   
24
   
23
   /**
25
   /**
24
    *
26
    *
25
    * @param Element $element
27
    * @param Element $element
26
    * @param Container $container 
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
     $this->element   = $element;
32
     $this->element   = $element;
31
     $this->container = $container;
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 Целия файл

4
 
4
 
5
 use Muzich\CoreBundle\Factory\ElementFactory;
5
 use Muzich\CoreBundle\Factory\ElementFactory;
6
 use Muzich\CoreBundle\Entity\Element;
6
 use Muzich\CoreBundle\Entity\Element;
7
+use Muzich\CoreBundle\Util\TagLike;
7
 
8
 
8
 /**
9
 /**
9
  * 
10
  * 
186
         {
187
         {
187
           $this->element->setData(Element::DATA_ARTIST, $result['user']['username']);
188
           $this->element->setData(Element::DATA_ARTIST, $result['user']['username']);
188
         }
189
         }
189
-
190
+        
191
+        $genres = '';
190
         if (array_key_exists('genre', $result) )
192
         if (array_key_exists('genre', $result) )
191
         {
193
         {
192
           if (strlen($result['genre']))
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 Целия файл

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

+ 27 - 1
src/Muzich/CoreBundle/Tests/ElementFactory/ElementFactoryTest.php Целия файл

373
       'data_download' => null,
373
       'data_download' => null,
374
       'data_download_url' => 'http://soundcloud.com/matas/sets/library-project/download',
374
       'data_download_url' => 'http://soundcloud.com/matas/sets/library-project/download',
375
       'data_artist' => 'matas',
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
     ),$datas);
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
     // 'http://soundcloud.com/matas/above-hyperion-redux'
405
     // 'http://soundcloud.com/matas/above-hyperion-redux'
380
     $datas = $this->proceed_element_datas_api(
406
     $datas = $this->proceed_element_datas_api(
381
       $bux, 
407
       $bux, 

+ 7 - 7
src/Muzich/CoreBundle/Tests/Tag/TagReadTest.php Целия файл

49
         'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk' 
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
     $response = $TagLike->getSimilarTags('punk', $bux->getId());
53
     $response = $TagLike->getSimilarTags('punk', $bux->getId());
54
     
54
     
55
     $this->assertEquals(count($cresults), count($response['tags']));
55
     $this->assertEquals(count($cresults), count($response['tags']));
73
         'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk' 
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
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk', $bux->getId()));
77
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk', $bux->getId()));
78
     
78
     
79
     $this->assertEquals($cresults, $tags);
79
     $this->assertEquals($cresults, $tags);
85
         'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk' 
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
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('anarcho punk', $bux->getId()));
89
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('anarcho punk', $bux->getId()));
90
     
90
     
91
     $this->assertEquals($cresults, $tags);
91
     $this->assertEquals($cresults, $tags);
97
         'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk' 
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
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk anarcho', $bux->getId()));
101
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk anarcho', $bux->getId()));
102
     
102
     
103
     $this->assertEquals($cresults, $tags);
103
     $this->assertEquals($cresults, $tags);
109
         'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk' 
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
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk anar', $bux->getId()));
113
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk anar', $bux->getId()));
114
     
114
     
115
     $this->assertEquals($cresults, $tags);
115
     $this->assertEquals($cresults, $tags);
121
         'Pop-punk', 'Post-Punk', 'Punk rock', 'Ska-jazz', 'Skacore',  'Synthpunk' 
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
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('ska punk', $bux->getId()));
125
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('ska punk', $bux->getId()));
126
     
126
     
127
     $this->assertEquals($cresults, $tags);
127
     $this->assertEquals($cresults, $tags);
132
       'Horror punk'
132
       'Horror punk'
133
     );
133
     );
134
     
134
     
135
-    $TagLike = new TagLike($this->getDoctrine());
135
+    $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
136
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('horror', $bux->getId()));
136
     $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('horror', $bux->getId()));
137
     
137
     
138
     $this->assertEquals($cresults, $tags);
138
     $this->assertEquals($cresults, $tags);

+ 1 - 1
src/Muzich/CoreBundle/Tests/User/UserTest.php Целия файл

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

+ 5 - 5
src/Muzich/CoreBundle/Util/TagLike.php Целия файл

2
 
2
 
3
 namespace Muzich\CoreBundle\Util;
3
 namespace Muzich\CoreBundle\Util;
4
 
4
 
5
-use Doctrine\Bundle\DoctrineBundle\Registry;
6
 use Muzich\CoreBundle\Util\StrictCanonicalizer;
5
 use Muzich\CoreBundle\Util\StrictCanonicalizer;
6
+use Doctrine\ORM\EntityManager;
7
 
7
 
8
 /**
8
 /**
9
  * Cette classe permet d'aider a la recherche de mot similaires a un mot
9
  * Cette classe permet d'aider a la recherche de mot similaires a un mot
13
 class TagLike
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
     }
168
     }
169
 
169
 
170
     $params['uid'] = '%"'.$user_id.'"%';
170
     $params['uid'] = '%"'.$user_id.'"%';
171
-    $tags_query = $this->registry->getEntityManager()->createQuery("
171
+    $tags_query = $this->entity_manager->createQuery("
172
       SELECT t.name, t.slug, t.id FROM MuzichCoreBundle:Tag t
172
       SELECT t.name, t.slug, t.id FROM MuzichCoreBundle:Tag t
173
       $where
173
       $where
174
 
174