Browse Source

Evolution #222: Demande de tags

Sevajol Bastien 12 years ago
parent
commit
85eae81498

+ 2 - 0
app/Resources/translations/userui.fr.yml View File

83
     help:     |
83
     help:     |
84
               Copier ici le lien internet (http://) pointant sur la ressource 
84
               Copier ici le lien internet (http://) pointant sur la ressource 
85
               que vous souhaitez partager.
85
               que vous souhaitez partager.
86
+  need_tags:
87
+    name:     Demander de l'aide pour tagger votre partage
86
   name:
88
   name:
87
     name:     Nom
89
     name:     Nom
88
     
90
     

+ 14 - 2
src/Muzich/CoreBundle/Controller/CoreController.php View File

229
     $element->setType('none');
229
     $element->setType('none');
230
     $form = $this->getAddForm($element);
230
     $form = $this->getAddForm($element);
231
     $form->bindRequest($this->getRequest());
231
     $form->bindRequest($this->getRequest());
232
-    
233
-    
232
+        
234
     if ($form->isValid())
233
     if ($form->isValid())
235
     {
234
     {
236
 
235
 
260
       {
259
       {
261
         $redirect_url = $this->generateUrl('home');
260
         $redirect_url = $this->generateUrl('home');
262
       }
261
       }
262
+      
263
+      // Un bug fait que le champ 'need_tags' n'est pas automatiquement renseigné pour l'élement,
264
+      // Alors on le fait en manuel ici ... zarb
265
+      $form_values = $this->getRequest()->get($form->getName());
266
+      
267
+      if (array_key_exists('need_tags', $form_values))
268
+      {
269
+        
270
+        if ($form_values['need_tags'])
271
+        {
272
+          $element->setNeedTags(true);
273
+        }
274
+      }
263
 
275
 
264
       $em->persist($element);
276
       $em->persist($element);
265
       $em->flush();
277
       $em->flush();

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

229
    */
229
    */
230
   protected $datas;
230
   protected $datas;
231
   
231
   
232
+  
233
+  /**
234
+   *
235
+   * @ORM\Column(type="boolean", nullable=true)
236
+   * @var boolean 
237
+   */
238
+  protected $need_tags = false;
239
+  
232
   /**
240
   /**
233
    * Get id
241
    * Get id
234
    *
242
    *
815
     return $this->childs;
823
     return $this->childs;
816
   }
824
   }
817
   
825
   
826
+  /**
827
+   *
828
+   * @param boolean $need 
829
+   */
830
+  public function setNeedTags($need)
831
+  {
832
+    if ($need)
833
+    {
834
+      $this->need_tags = true;
835
+    }
836
+    else
837
+    {
838
+      $this->need_tags = false;
839
+    }
840
+  }
841
+  
842
+  /**
843
+   *
844
+   * @return boolean 
845
+   */
846
+  public function getNeedTags()
847
+  {
848
+    if ($this->need_tags)
849
+    {
850
+      return true;
851
+    }
852
+    return false;
853
+  }
854
+  
818
 }
855
 }

+ 8 - 1
src/Muzich/CoreBundle/Form/Element/ElementAddForm.php View File

21
       'error_bubbling' => true
21
       'error_bubbling' => true
22
     ));
22
     ));
23
         
23
         
24
-    $builder->add('tags', 'hidden');    
24
+    $builder->add('tags', 'hidden');   
25
+    
26
+    $builder->add('need_tags', 'checkbox', array(
27
+      'required' => false,
28
+      'error_bubbling' => true
29
+    ));
30
+         
25
   }
31
   }
26
   
32
   
27
   public function setName($name)
33
   public function setName($name)
44
       'name' => '',
50
       'name' => '',
45
       'url' => '',
51
       'url' => '',
46
       'tags' => '',
52
       'tags' => '',
53
+      'need_tags' => false,
47
       //'groups' => array(),
54
       //'groups' => array(),
48
       'data_class' => 'Muzich\CoreBundle\Entity\Element'
55
       'data_class' => 'Muzich\CoreBundle\Entity\Element'
49
     );
56
     );

+ 6 - 0
src/Muzich/CoreBundle/Resources/views/Element/form.add.html.twig View File

22
 
22
 
23
   {{ form_widget(form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
23
   {{ form_widget(form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
24
 
24
 
25
+<div class="field">
26
+  {{ form_errors(form.need_tags) }}
27
+  {{ form_widget(form.need_tags) }}
28
+  {{ form_label(form.need_tags, 'element_add.need_tags.name'|trans({}, 'userui')) }}
29
+</div>
30
+
25
 {{ form_row(form._token) }}
31
 {{ form_row(form._token) }}

+ 6 - 0
src/Muzich/CoreBundle/Resources/views/Element/form.edit.html.twig View File

20
 
20
 
21
   {{ form_widget(form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
21
   {{ form_widget(form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
22
 
22
 
23
+<div class="field">
24
+  {{ form_errors(form.need_tags) }}
25
+  {{ form_widget(form.need_tags) }}
26
+  {{ form_label(form.need_tags, 'element_add.need_tags.name'|trans({}, 'userui')) }}
27
+</div>
28
+
23
 {{ form_row(form._token) }}
29
 {{ form_row(form._token) }}

+ 57 - 0
src/Muzich/CoreBundle/Tests/Controller/ElementControllerTest.php View File

1239
     
1239
     
1240
   }
1240
   }
1241
   
1241
   
1242
+  public function testAddElementNeedTags()
1243
+  {
1244
+    $this->client = self::createClient();
1245
+    $this->connectUser('joelle', 'toor');
1246
+    
1247
+    $joelle = $this->getUser();
1248
+    
1249
+    $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
1250
+    $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
1251
+      
1252
+    // L'élément n'existe pas encore
1253
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
1254
+      ->findOneByName('Musique qui dechire bis4d5456aqd')
1255
+    ;
1256
+    $this->assertTrue(is_null($element));
1257
+    
1258
+    // On commence par ajouter un tag
1259
+    $url = $this->generateUrl('element_add');
1260
+   
1261
+    $extract = $this->crawler->filter('input[name="element_add[_token]"]')
1262
+      ->extract(array('value'));
1263
+    $csrf = $extract[0];
1264
+    
1265
+    $crawler = $this->client->request(
1266
+      'POST', 
1267
+      $url, 
1268
+      array(
1269
+          'element_add' => array(
1270
+              '_token'     => $csrf,
1271
+              'name'       => 'Musique qui dechire bis4d5456aqd',
1272
+              'url'        => 'http://www.youtube.com/watch?v=WC8qb_of04E',
1273
+              'tags'       => json_encode(array($hardtek->getId(), $tribe->getId())),
1274
+              'need_tags'  => '1'
1275
+          )
1276
+        
1277
+      ), 
1278
+      array(), 
1279
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
1280
+    );
1281
+    
1282
+    $this->isResponseSuccess();
1283
+    
1284
+    $response = json_decode($this->client->getResponse()->getContent(), true);
1285
+    $this->assertEquals($response['status'], 'success');
1286
+    
1287
+    
1288
+    $element_need_tags = $this->findOneBy('Element', array(
1289
+      'name'   => 'Musique qui dechire bis4d5456aqd',
1290
+      'owner'  => $joelle->getId(),
1291
+      'need_tags' => true
1292
+    ));
1293
+    
1294
+    // L'objet est bien en base
1295
+    $this->assertTrue(!is_null($element_need_tags));
1296
+    
1297
+  }
1298
+  
1242
 }
1299
 }