Browse Source

Ajout d'un attribut slug a l'entité Tag.

bastien 12 years ago
parent
commit
ad48a5968a

+ 8 - 0
src/Muzich/CoreBundle/DataFixtures/ORM/LoadTagData.php View File

@@ -39,6 +39,14 @@ class LoadTagData  extends AbstractFixture implements OrderedFixtureInterface, C
39 39
   {
40 40
     $this->entity_manager = $entity_manager;
41 41
 
42
+//    // Slug stuff
43
+//    $evm = new \Doctrine\Common\EventManager();
44
+//    // ORM and ODM
45
+//    $sluggableListener = new \Gedmo\Sluggable\SluggableListener();
46
+//    $evm->addEventSubscriber($sluggableListener);
47
+//    // now this event manager should be passed to entity manager constructor
48
+//    $entity_manager->getEventManager()->addEventSubscriber($sluggableListener);
49
+    
42 50
     $tags_names = array(
43 51
         
44 52
     '2 Step',

+ 18 - 0
src/Muzich/CoreBundle/Entity/Tag.php View File

@@ -4,6 +4,7 @@ namespace Muzich\CoreBundle\Entity;
4 4
 
5 5
 use Doctrine\ORM\Mapping as ORM;
6 6
 use \Doctrine\Common\Collections\ArrayCollection;
7
+use Gedmo\Mapping\Annotation as Gedmo;
7 8
 
8 9
 /**
9 10
  * Cet entité représente le Tag.
@@ -11,6 +12,7 @@ use \Doctrine\Common\Collections\ArrayCollection;
11 12
  * @ORM\Entity
12 13
  * @ORM\Table(name="tag")
13 14
  * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\TagRepository")
15
+ * @ORM\HasLifecycleCallbacks()
14 16
  */
15 17
 class Tag
16 18
 {
@@ -55,6 +57,12 @@ class Tag
55 57
   protected $name;
56 58
   
57 59
   /**
60
+   * @Gedmo\Slug(fields={"name"})
61
+   * @ORM\Column(length=64, nullable=true)
62
+   */
63
+  protected $slug;
64
+  
65
+  /**
58 66
    * Compteur total d'utilisation. Utilisé pour faire ressortir les 
59 67
    * tags les plus utilisés.
60 68
    * 
@@ -106,6 +114,16 @@ class Tag
106 114
   {
107 115
       return $this->name;
108 116
   }
117
+  
118
+  public function getSlug()
119
+  {
120
+    return $this->slug;
121
+  }
122
+  
123
+  public function setSlug($slug)
124
+  {
125
+    $this->slug = $slug;
126
+  }
109 127
 
110 128
   /**
111 129
    * Add elements

+ 42 - 0
src/Muzich/CoreBundle/Managers/TagManager.php View File

@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Managers;
4
+
5
+use Muzich\CoreBundle\Entity\Tag;
6
+use Doctrine\ORM\EntityManager;
7
+use Symfony\Component\DependencyInjection\Container;
8
+
9
+/**
10
+ * 
11
+ *
12
+ * @author bux
13
+ */
14
+class TagManager
15
+{
16
+  
17
+  protected $em;
18
+  
19
+  public function __construct(EntityManager $em)
20
+  {
21
+    $this->em = $em;
22
+    
23
+    // Slug stuff
24
+    $evm = new \Doctrine\Common\EventManager();
25
+    // ORM and ODM
26
+    $sluggableListener = new \Gedmo\Sluggable\SluggableListener();
27
+    $evm->addEventSubscriber($sluggableListener);
28
+    // now this event manager should be passed to entity manager constructor
29
+    $this->em->getEventManager()->addEventSubscriber($sluggableListener);
30
+  }
31
+  
32
+  public function flush()
33
+  {
34
+    $this->em->flush();
35
+  }
36
+  
37
+  public function persist(Tag $tag)
38
+  {
39
+    $this->em->persist($tag);
40
+  }
41
+  
42
+}