Browse Source

Evolution #27: Optimisation Ajout d'element.

bastien 13 years ago
parent
commit
fa4f1e3380

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

121
     $user = $this->getUser();
121
     $user = $this->getUser();
122
     $em = $this->getDoctrine()->getEntityManager();
122
     $em = $this->getDoctrine()->getEntityManager();
123
     
123
     
124
+    $element = new Element();
124
     $form = $this->createForm(
125
     $form = $this->createForm(
125
       new ElementAddForm(),
126
       new ElementAddForm(),
126
-      array(),
127
+      $element,
127
       array(
128
       array(
128
        'tags'   => $this->getTagsArray(),
129
        'tags'   => $this->getTagsArray(),
129
         // Ligne non obligatoire (cf. verif du contenu du form -> ticket)
130
         // Ligne non obligatoire (cf. verif du contenu du form -> ticket)
136
       $form->bindRequest($this->getRequest());
137
       $form->bindRequest($this->getRequest());
137
       if ($form->isValid())
138
       if ($form->isValid())
138
       {
139
       {
139
-        $data = $form->getData();
140
-        $element = new Element();
141
 
140
 
142
         // On utilise le gestionnaire d'élément
141
         // On utilise le gestionnaire d'élément
143
         $factory = new ElementManager($element, $em, $this->container);
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
         if ($group_slug)
146
         if ($group_slug)
148
         {
147
         {
149
           $group = $this->findGroupWithSlug($group_slug);
148
           $group = $this->findGroupWithSlug($group_slug);

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

70
    * @param array $params
70
    * @param array $params
71
    * @param User $owner
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
     $this->element->setOwner($owner);
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
     $this->determineType();
78
     $this->determineType();
81
     $this->proceedExtraFields();
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
       $this->element->setGroup($group);
87
       $this->element->setGroup($group);
90
     }
88
     }
91
   }
89
   }

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

181
   
181
   
182
   public function __construct($url = null)
182
   public function __construct($url = null)
183
   {
183
   {
184
-    $this->tags = new ArrayCollection();
184
+    //$this->tags = new ArrayCollection();
185
     $this->url = $url;
185
     $this->url = $url;
186
   }
186
   }
187
   
187
   
260
    *
260
    *
261
    * @param Group $group
261
    * @param Group $group
262
    */
262
    */
263
-  public function setGroup(Group $group)
263
+  public function setGroup($group)
264
   {
264
   {
265
       $this->group = $group;
265
       $this->group = $group;
266
   }
266
   }
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
    * @param array $ids 
342
    * @param array $ids 
342
    */
343
    */
343
   public function setTagsWithIds(EntityManager $em, $ids)
344
   public function setTagsWithIds(EntityManager $em, $ids)
344
   {
345
   {
345
     $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids)->execute();
346
     $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids)->execute();
346
-
347
+    $this->tags = null;
347
     // Pour les nouveaux ids restants
348
     // Pour les nouveaux ids restants
348
     foreach ($tags as $tag)
349
     foreach ($tags as $tag)
349
     {      
350
     {      

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

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

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

26
     
26
     
27
     $youtube_width = '425';
27
     $youtube_width = '425';
28
     $youtube_height = '350';
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
     $element = new Element();
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
     $factory = new ElementManager($element, $r->getEntityManager(), $this->_container);
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
     $url = 'http://www.youtube.com/v/WC8qb_of04E&rel=1';
38
     $url = 'http://www.youtube.com/v/WC8qb_of04E&rel=1';
47
     
39
     
48
     $this->assertEquals($element->getName(), 'Mon bel element');
40
     $this->assertEquals($element->getName(), 'Mon bel element');
49
     $this->assertEquals($element->getUrl(), 'http://www.youtube.com/watch?v=WC8qb_of04E');
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
     $this->assertEquals($element->getEmbed(), 
43
     $this->assertEquals($element->getEmbed(), 
52
       '<object width="'.$youtube_width.'" height="'.$youtube_height.'" >'
44
       '<object width="'.$youtube_width.'" height="'.$youtube_height.'" >'
53
      .'<param name="movie" value="'.$url.'"></param><param name="wmode" value="transparent">'
45
      .'<param name="movie" value="'.$url.'"></param><param name="wmode" value="transparent">'

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

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