Browse Source

Mise en place des factory (sites).

bastien 13 years ago
parent
commit
a5bf50a0c9

+ 4 - 4
src/Muzich/CoreBundle/DataFixtures/ORM/LoadElementData.php View File

76
     $joelle  = $this->entity_manager->merge($this->getReference('user_joelle'));
76
     $joelle  = $this->entity_manager->merge($this->getReference('user_joelle'));
77
 
77
 
78
     // 'youtube', 'soundclound', 'son2teuf', 'jamendo'
78
     // 'youtube', 'soundclound', 'son2teuf', 'jamendo'
79
-    $youtube     = $this->entity_manager->merge($this->getReference('element_type_youtube'));
80
-    $soundclound = $this->entity_manager->merge($this->getReference('element_type_soundclound'));
81
-    $son2teuf    = $this->entity_manager->merge($this->getReference('element_type_son2teuf'));
82
-    $jamendo     = $this->entity_manager->merge($this->getReference('element_type_jamendo'));
79
+    $youtube     = $this->entity_manager->merge($this->getReference('element_type_youtube.com'));
80
+    $soundclound = $this->entity_manager->merge($this->getReference('element_type_soundcloud.com'));
81
+    $son2teuf    = $this->entity_manager->merge($this->getReference('element_type_son2teuf.org'));
82
+    $jamendo     = $this->entity_manager->merge($this->getReference('element_type_jamendo.com'));
83
     
83
     
84
     $this->createElement('youtube_heretik_1', 'Heretik System Popof - Resistance', 
84
     $this->createElement('youtube_heretik_1', 'Heretik System Popof - Resistance', 
85
       'http://www.youtube.com/watch?v=tq4DjQK7nsM',
85
       'http://www.youtube.com/watch?v=tq4DjQK7nsM',

+ 3 - 3
src/Muzich/CoreBundle/DataFixtures/ORM/LoadElementTypeData.php View File

39
   public function load($entity_manager)
39
   public function load($entity_manager)
40
   {
40
   {
41
     $this->entity_manager = $entity_manager;
41
     $this->entity_manager = $entity_manager;
42
-
42
+    
43
     foreach (array(
43
     foreach (array(
44
-      'youtube' => 'Youtube', 'soundclound' => 'SoundCloud', 
45
-      'son2teuf' => 'Son2Teuf', 'jamendo' => 'jamendo'
44
+      'youtube.com' => 'Youtube', 'soundcloud.com' => 'SoundCloud', 
45
+      'son2teuf.org' => 'Son2Teuf', 'jamendo.com' => 'jamendo'
46
       ) as $id => $name)
46
       ) as $id => $name)
47
     {
47
     {
48
       $this->createElementType($id, $name);
48
       $this->createElementType($id, $name);

+ 26 - 4
src/Muzich/CoreBundle/ElementFactory/ElementFactory.php View File

6
 use Muzich\CoreBundle\Entity\User;
6
 use Muzich\CoreBundle\Entity\User;
7
 use Doctrine\ORM\EntityManager;
7
 use Doctrine\ORM\EntityManager;
8
 
8
 
9
+use Muzich\CoreBundle\ElementFactory\Site\YoutubeFactory;
10
+
9
 /**
11
 /**
10
  * 
12
  * 
11
  *
13
  *
14
 class ElementFactory
16
 class ElementFactory
15
 {
17
 {
16
   
18
   
17
-  const TYPE_UNKNOW = 'unknow';
18
-  
19
   protected $types = array(
19
   protected $types = array(
20
-    'youtube', 'soundclound', 'son2teuf', 'jamendo'
20
+    'youtube.com'    => 'YoutubeFactory', 
21
+    'soundcloud.com' => 'SoundCloudFactory', 
22
+    'son2teuf.org'   => 'Son2TeufFactory', 
23
+    'jamendo.com'    => 'JamendoFactory'
21
   );
24
   );
22
   
25
   
23
   protected $em;
26
   protected $em;
75
    */
78
    */
76
   protected function determineType()
79
   protected function determineType()
77
   {
80
   {
78
-    $this->element->setType(null);
81
+    preg_match("/^(http:\/\/)?([^\/]+)/i", $this->element->getUrl(), $chaines);
82
+    $host = $chaines[2];
83
+    // Repérer les derniers segments
84
+    preg_match("/[^\.\/]+\.[^\.\/]+$/",$host,$chaines);
85
+    
86
+    $type = null;
87
+    if (array_key_exists($chaines[0], $this->types))
88
+    {
89
+      $type = $this->em->getRepository('MuzichCoreBundle:ElementType')->find($chaines[0]);
90
+    }
91
+    
92
+    $this->element->setType($type);
79
   }
93
   }
80
   
94
   
81
   /**
95
   /**
89
     // Instanciation d'un objet factory correspondant au type, par exemple
103
     // Instanciation d'un objet factory correspondant au type, par exemple
90
     // YoutubeFactory, qui répondant a une implementation retournera ces infos.
104
     // YoutubeFactory, qui répondant a une implementation retournera ces infos.
91
   
105
   
106
+    if ($this->element->getType())
107
+    {
108
+      $factory_name = $this->types[$this->element->getType()->getId()];
109
+      
110
+      $site_factory = new YoutubeFactory($this->element);
111
+      $this->element->getEmbed($site_factory->getEmbedCode());
112
+    }
113
+    
92
   }
114
   }
93
     
115
     
94
 }
116
 }

+ 28 - 0
src/Muzich/CoreBundle/ElementFactory/Site/BaseFactory.php View File

1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+use Muzich\CoreBundle\Entity\Element;
6
+
7
+/**
8
+ *
9
+ * @author bux
10
+ */
11
+class BaseFactory implements FactoryInterface
12
+{
13
+  
14
+  protected $element;
15
+  
16
+  public function __construct(Element $element)
17
+  {
18
+    $this->element = $element;
19
+  }
20
+  
21
+  public function getEmbedCode()
22
+  {
23
+    return null;
24
+  }
25
+  
26
+}
27
+
28
+?>

+ 16 - 0
src/Muzich/CoreBundle/ElementFactory/Site/FactoryInterface.php View File

1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+use Muzich\CoreBundle\Entity\Element;
6
+
7
+interface FactoryInterface
8
+{
9
+  
10
+  public function __construct(Element $element);
11
+  
12
+  public function getEmbedCode();
13
+  
14
+}
15
+
16
+?>

+ 15 - 0
src/Muzich/CoreBundle/ElementFactory/Site/JamendoFactory.php View File

1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+/**
6
+ * 
7
+ *
8
+ * @author bux
9
+ */
10
+class JamendoFactory extends BaseFactory
11
+{
12
+  
13
+}
14
+
15
+?>

+ 15 - 0
src/Muzich/CoreBundle/ElementFactory/Site/Son2TeufFactory.php View File

1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+/**
6
+ * 
7
+ *
8
+ * @author bux
9
+ */
10
+class Son2TeufFactory extends BaseFactory
11
+{
12
+  
13
+}
14
+
15
+?>

+ 15 - 0
src/Muzich/CoreBundle/ElementFactory/Site/SoundCloudFactory.php View File

1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+/**
6
+ * 
7
+ *
8
+ * @author bux
9
+ */
10
+class SoundCloudFactory extends BaseFactory
11
+{
12
+  
13
+}
14
+
15
+?>

+ 15 - 0
src/Muzich/CoreBundle/ElementFactory/Site/YoutubeFactory.php View File

1
+<?php
2
+
3
+namespace Muzich\CoreBundle\ElementFactory\Site;
4
+
5
+/**
6
+ * 
7
+ *
8
+ * @author bux
9
+ */
10
+class YoutubeFactory extends BaseFactory
11
+{
12
+  
13
+}
14
+
15
+?>

+ 20 - 0
src/Muzich/CoreBundle/Entity/Element.php View File

267
   }
267
   }
268
 
268
 
269
   /**
269
   /**
270
+   * Set embed
271
+   *
272
+   * @param string $code
273
+   */
274
+  public function setEmbed($code)
275
+  {
276
+      $this->embed = $code;
277
+  }
278
+
279
+  /**
280
+   * Get embed
281
+   *
282
+   * @return string 
283
+   */
284
+  public function getEmbed()
285
+  {
286
+      return $this->embed;
287
+  }
288
+
289
+  /**
270
    * Set created
290
    * Set created
271
    *
291
    *
272
    * @param date $created
292
    * @param date $created

+ 1 - 1
src/Muzich/CoreBundle/Entity/ElementType.php View File

19
   
19
   
20
   /**
20
   /**
21
    * @ORM\Id
21
    * @ORM\Id
22
-   * @ORM\Column(type="string", length=12)
22
+   * @ORM\Column(type="string", length=18)
23
    * @var type string
23
    * @var type string
24
    */
24
    */
25
   protected $id;
25
   protected $id;