Browse Source

Refactorisation soundcloud et jamendo dans proceedDatas. /!\ LEs autree factory ne sont pas traité pour le moment.

Sevajol Bastien 11 years ago
parent
commit
c1f5917725

+ 47 - 40
src/Muzich/CoreBundle/Factory/Elements/Jamendocom.php View File

38
     }
38
     }
39
   }
39
   }
40
   
40
   
41
-  public function retrieveDatas()
41
+  
42
+  public function proceedDatas()
42
   {
43
   {
43
-    $type = $this->element->getData(Element::DATA_TYPE);
44
-    $ref_id = $this->element->getData(Element::DATA_REF_ID);
45
-    
46
-    // Récupération de données avec l'API
47
-    $api_url = null;
48
-    switch ($type)
44
+    $this->retrieveDatas();
45
+    // TODO: A t-on toujours besoin du code embed ou on génrère le player générique a la volée ?
46
+    $this->proceedEmbedCode();
47
+    $this->proceedThumbnailUrl();
48
+  }
49
+  
50
+  protected function getApiUrl()
51
+  {
52
+    switch ($this->url_analyzer->getType())
49
     {
53
     {
50
       case Element::TYPE_ALBUM:
54
       case Element::TYPE_ALBUM:
51
-        $api_url = "http://api.jamendo.com/get2/"
52
-          ."id+name+url+image+artist_name+artist_url/album/json/?album_id=".$ref_id;
53
-        $api_tag_url = "http://api.jamendo.com/get2/name+weight/tag/json/album_tag/?album_id=".$ref_id;
55
+        return "http://api.jamendo.com/get2/id+name+url+image+artist_name+artist_url/album/json/?album_id="
56
+          .$this->url_analyzer->getRefId();
54
       break;
57
       break;
55
-    
56
       case Element::TYPE_TRACK:
58
       case Element::TYPE_TRACK:
57
-        $api_url = "http://api.jamendo.com/get2/"
58
-          ."id+name+url+image+artist_name+artist_url+track_name/album/json/?track_id=".$ref_id;
59
-        $api_tag_url = "http://api.jamendo.com/get2/name+weight/tag/json/track_tag/?track_id=".$ref_id;
59
+        return "http://api.jamendo.com/get2/id+name+url+image+artist_name+artist_url+track_name/album/json/?track_id="
60
+          .$this->url_analyzer->getRefId();
60
       break;
61
       break;
61
     }
62
     }
62
-    
63
-    if ($api_url)
63
+  }
64
+  
65
+  protected function getApiTagUrl()
66
+  {
67
+    return "http://api.jamendo.com/get2/name+weight/tag/json/album_tag/?".$this->url_analyzer->getType()."_id="
68
+      .$this->url_analyzer->getRefId();
69
+  }
70
+  
71
+  public function retrieveDatas()
72
+  {
73
+    if (($response = $this->getApiConnector()->getResponseForUrl($this->getApiUrl())))
64
     {
74
     {
65
-      if (($response = $this->getApiConnector()->getResponseForUrl($api_url)))
75
+      // Check si tout se passe bien si pas de retour de l'api
76
+      $this->getApiConnector()->setElementDatasWithResponse($response, array(
77
+        Element::DATA_THUMB_URL      => array(0 => 'image'),
78
+        Element::DATA_ARTIST         => array(0 => 'artist_name'),
79
+      ));
80
+      
81
+      if ($this->url_analyzer->getType() == Element::TYPE_ALBUM)
66
       {
82
       {
67
-        // Check si tout se passe bien si pas de retour de l'api
68
-        $this->getApiConnector()->setElementDatasWithResponse($response, array(
69
-          Element::DATA_THUMB_URL      => array(0 => 'image'),
70
-          Element::DATA_ARTIST         => array(0 => 'artist_name'),
71
-        ));
72
-        
73
-        if ($this->url_analyzer->getType() == Element::TYPE_ALBUM)
74
-        {
75
-          $this->element->setData(Element::DATA_TITLE, $response->get(array(0 => 'name')));
76
-        }
77
-        if ($this->url_analyzer->getType() == Element::TYPE_TRACK)
83
+        $this->element->setData(Element::DATA_TITLE, $response->get(array(0 => 'name')));
84
+      }
85
+      if ($this->url_analyzer->getType() == Element::TYPE_TRACK)
86
+      {
87
+        $this->element->setData(Element::DATA_TITLE, $response->get(array(0 => 'track_name')));
88
+      }
89
+      
90
+      if (($response = $this->getApiConnector()->getResponseForUrl($this->getApiTagUrl())))
91
+      {
92
+        // TODO: Check si tout ce passe bien avec pas de tags en retour de l'api
93
+        $tags = array();
94
+        foreach ($result->getContent() as $tag)
78
         {
95
         {
79
-          $this->element->setData(Element::DATA_TITLE, $response->get(array(0 => 'track_name')));
96
+          $tags[] = $tag['name'];
80
         }
97
         }
81
         
98
         
82
-        if (($response = $this->getApiConnector()->getResponseForUrl($api_url)))
83
-        {
84
-          // TODO: Check si tout ce passe bien avec pas de tags en retour de l'api
85
-          $tags = array();
86
-          foreach ($result->getContent() as $tag)
87
-          {
88
-            $tags[] = $tag['name'];
89
-          }
90
-          
91
-          $this->element->setData(Element::DATA_TAGS, $tags);
92
-        }
99
+        $this->element->setData(Element::DATA_TAGS, $tags);
93
       }
100
       }
94
     }
101
     }
95
     
102
     

+ 5 - 5
src/Muzich/CoreBundle/Factory/Elements/Soundcloudcom.php View File

17
     $this->url_matchs = UrlMatchs::$soundcloud;
17
     $this->url_matchs = UrlMatchs::$soundcloud;
18
   }
18
   }
19
   
19
   
20
-  public function retrieveDatas()
20
+  public function proceedDatas()
21
   {
21
   {
22
-    if ($this->url_analyzer->haveMatch())
23
-    {
24
-      $this->setElementDatasWithApi();
25
-    }
22
+    $this->setElementDatasWithApi();
23
+    // TODO: Embed code ne devrais plus être necessaire (on créer les lecteurs avec JS)
24
+    $this->proceedEmbedCode();
25
+    $this->proceedThumbnailUrl();
26
   }
26
   }
27
   
27
   
28
   protected function setElementDatasWithApi()
28
   protected function setElementDatasWithApi()

+ 6 - 5
src/Muzich/CoreBundle/Managers/ElementManager.php View File

137
       $site_factory = $this->getFactory();
137
       $site_factory = $this->getFactory();
138
       // On récupères les datas de l'élément
138
       // On récupères les datas de l'élément
139
       $site_factory->setUrlDatas();
139
       $site_factory->setUrlDatas();
140
-      $site_factory->retrieveDatas();
141
-      // On procède a la construction de nos informations
142
-      $site_factory->proceedEmbedCode();
143
-      $site_factory->proceedThumbnailUrl();
140
+      if ($site_factory->url_analyzer->haveMatch())
141
+      {
142
+        $site_factory->proceedDatas();
143
+      }
144
+      
144
     }
145
     }
145
     
146
     
146
   }
147
   }
177
         return new Spotifycom($this->element, $this->container, $this->em);
178
         return new Spotifycom($this->element, $this->container, $this->em);
178
       break;
179
       break;
179
       default:
180
       default:
180
-        throw new \Exception("La Factory n'est pas prise en charge pour ce type.");
181
+        throw new \Exception("La Factory n'est pas prise en charge pour le type \"".$this->element->getType()."\".");
181
       break;
182
       break;
182
     }
183
     }
183
     
184