Browse Source

Evolution #27: Optimisation Ajout d'element.

bastien 12 years ago
parent
commit
fa4f1e3380

+ 4 - 5
src/Muzich/CoreBundle/Controller/CoreController.php View File

@@ -121,9 +121,10 @@ class CoreController extends Controller
121 121
     $user = $this->getUser();
122 122
     $em = $this->getDoctrine()->getEntityManager();
123 123
     
124
+    $element = new Element();
124 125
     $form = $this->createForm(
125 126
       new ElementAddForm(),
126
-      array(),
127
+      $element,
127 128
       array(
128 129
        'tags'   => $this->getTagsArray(),
129 130
         // Ligne non obligatoire (cf. verif du contenu du form -> ticket)
@@ -136,14 +137,12 @@ class CoreController extends Controller
136 137
       $form->bindRequest($this->getRequest());
137 138
       if ($form->isValid())
138 139
       {
139
-        $data = $form->getData();
140
-        $element = new Element();
141 140
 
142 141
         // On utilise le gestionnaire d'élément
143 142
         $factory = new ElementManager($element, $em, $this->container);
144
-        $factory->proceedFill($data, $user);
143
+        $factory->proceedFill($user);
145 144
         
146
-        // Si on a précisé un groupe
145
+        // Si on a précisé un groupe dans lequel mettre l'element
147 146
         if ($group_slug)
148 147
         {
149 148
           $group = $this->findGroupWithSlug($group_slug);

+ 6 - 8
src/Muzich/CoreBundle/ElementFactory/ElementManager.php View File

@@ -70,22 +70,20 @@ class ElementManager
70 70
    * @param array $params
71 71
    * @param User $owner
72 72
    */
73
-  public function proceedFill($params, User $owner)
73
+  public function proceedFill(User $owner)
74 74
   {
75
-    $this->element->setName($params['name']);
76
-    $this->element->setUrl($params['url']);
77 75
     $this->element->setOwner($owner);
78
-    $this->element->setTagsWithIds($this->em, $params['tags']);
79
-    $this->setGroup($params);
76
+    $this->element->setTagsWithIds($this->em, $this->element->getTags());
77
+    $this->setGroup();
80 78
     $this->determineType();
81 79
     $this->proceedExtraFields();
82 80
   }
83 81
   
84
-  protected function setGroup($params)
82
+  protected function setGroup()
85 83
   {
86
-    if ($params['group'])
84
+    if ($this->element->getGroup())
87 85
     {
88
-      $group = $this->em->getRepository('MuzichCoreBundle:Group')->findOneById($params['group']);
86
+      $group = $this->em->getRepository('MuzichCoreBundle:Group')->findOneById($this->element->getGroup());
89 87
       $this->element->setGroup($group);
90 88
     }
91 89
   }

+ 5 - 4
src/Muzich/CoreBundle/Entity/Element.php View File

@@ -181,7 +181,7 @@ class Element
181 181
   
182 182
   public function __construct($url = null)
183 183
   {
184
-    $this->tags = new ArrayCollection();
184
+    //$this->tags = new ArrayCollection();
185 185
     $this->url = $url;
186 186
   }
187 187
   
@@ -260,7 +260,7 @@ class Element
260 260
    *
261 261
    * @param Group $group
262 262
    */
263
-  public function setGroup(Group $group)
263
+  public function setGroup($group)
264 264
   {
265 265
       $this->group = $group;
266 266
   }
@@ -336,14 +336,15 @@ class Element
336 336
   }
337 337
   
338 338
   /**
339
-   * Ajoute des relation vers des tags.
339
+   * Etablie des relation vers des tags.
340
+   * (Supprime les anciens tags, au niveau de l'objet seulement)
340 341
    * 
341 342
    * @param array $ids 
342 343
    */
343 344
   public function setTagsWithIds(EntityManager $em, $ids)
344 345
   {
345 346
     $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids)->execute();
346
-
347
+    $this->tags = null;
347 348
     // Pour les nouveaux ids restants
348 349
     foreach ($tags as $tag)
349 350
     {      

+ 1 - 1
src/Muzich/CoreBundle/Repository/ElementRepository.php View File

@@ -132,7 +132,7 @@ class ElementRepository extends EntityRepository
132 132
       $where_user
133 133
       $where_group
134 134
       $where_favorite
135
-      ORDER BY e.created, e.name DESC "
135
+      ORDER BY e.created DESC, e.name DESC"
136 136
     ;
137 137
     $params['uid'] = $user_id;
138 138
     

+ 6 - 14
src/Muzich/CoreBundle/Tests/ElementFactory/ElementFactoryTest.php View File

@@ -26,28 +26,20 @@ class ElementFactoryTest extends UnitTest
26 26
     
27 27
     $youtube_width = '425';
28 28
     $youtube_height = '350';
29
-    
30
-    $data = array(
31
-      'name'    => 'Mon bel element',
32
-      'url'     => 'http://www.youtube.com/watch?v=WC8qb_of04E',
33
-      'tags'    => array($hardtek->getId(), $tribe->getId()),
34
-      'group'   => ''
35
-    );
36
-    
29
+        
37 30
     $element = new Element();
31
+    $element->setName('Mon bel element');
32
+    $element->setTags(array($hardtek->getId(), $tribe->getId()));
33
+    $element->setUrl('http://www.youtube.com/watch?v=WC8qb_of04E');
38 34
     
39 35
     $factory = new ElementManager($element, $r->getEntityManager(), $this->_container);
40
-    $factory->proceedFill($data, $bux);
41
-    
42
-    $tags = new ArrayCollection();
43
-    $tags->add($hardtek);
44
-    $tags->add($tribe);
36
+    $factory->proceedFill($bux);
45 37
     
46 38
     $url = 'http://www.youtube.com/v/WC8qb_of04E&rel=1';
47 39
     
48 40
     $this->assertEquals($element->getName(), 'Mon bel element');
49 41
     $this->assertEquals($element->getUrl(), 'http://www.youtube.com/watch?v=WC8qb_of04E');
50
-    $this->assertEquals($element->getTags(), $tags);
42
+    $this->assertEquals($element->getTags(), array($hardtek, $tribe));
51 43
     $this->assertEquals($element->getEmbed(), 
52 44
       '<object width="'.$youtube_width.'" height="'.$youtube_height.'" >'
53 45
      .'<param name="movie" value="'.$url.'"></param><param name="wmode" value="transparent">'

+ 4 - 4
src/Muzich/CoreBundle/Tests/Searcher/ElementSearcherTest.php View File

@@ -71,7 +71,7 @@ class ElementSearcherTest extends UnitTest
71 71
       ->createQuery("SELECT e
72 72
       FROM MuzichCoreBundle:Element e
73 73
       WHERE e.owner = :suid
74
-      ORDER BY e.created DESC")
74
+      ORDER BY e.created DESC, e.name DESC")
75 75
       ->setParameter('suid', $jean->getId())
76 76
       ->setMaxResults(20)
77 77
       ->getResult()
@@ -102,7 +102,7 @@ class ElementSearcherTest extends UnitTest
102 102
       FROM MuzichCoreBundle:Element e
103 103
       JOIN e.elements_favorites fav2
104 104
       WHERE fav2.user = :fuid
105
-      ORDER BY e.created, e.name DESC")
105
+      ORDER BY e.created DESC, e.name DESC")
106 106
       ->setParameter('fuid', $paul->getId())
107 107
       ->setMaxResults(20)
108 108
       ->getResult()
@@ -136,7 +136,7 @@ class ElementSearcherTest extends UnitTest
136 136
       FROM MuzichCoreBundle:Element e 
137 137
       LEFT JOIN e.tags t 
138 138
       WHERE (t.id = :tidHardtek OR t.id = :tidTribe)
139
-      ORDER BY e.created, e.name DESC")
139
+      ORDER BY e.created DESC, e.name DESC")
140 140
       ->setParameters(array(
141 141
         'tidHardtek' => $hardtek->getId(),
142 142
         'tidTribe'   => $tribe->getId()
@@ -178,7 +178,7 @@ class ElementSearcherTest extends UnitTest
178 178
 //      JOIN e.owner eu  LEFT JOIN eu.followers_users f LEFT JOIN g.followers gf
179 179
 //      WHERE (t.id = :tidHardtek OR t.id = :tidTribe)
180 180
 //       AND (f.follower = :userid OR gf.follower = :useridg)
181
-//      ORDER BY e.created, e.name DESC")
181
+//      ORDER BY e.created DESC, e.name DESC")
182 182
 //      ->setParameters(array(
183 183
 //        'tidHardtek' => $hardtek->getId(),
184 184
 //        'tidTribe'   => $tribe->getId(),