Pārlūkot izejas kodu

Evolution #222: Demande de tags

Sevajol Bastien 12 gadus atpakaļ
vecāks
revīzija
85eae81498

+ 2 - 0
app/Resources/translations/userui.fr.yml Parādīt failu

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

+ 14 - 2
src/Muzich/CoreBundle/Controller/CoreController.php Parādīt failu

@@ -229,8 +229,7 @@ class CoreController extends Controller
229 229
     $element->setType('none');
230 230
     $form = $this->getAddForm($element);
231 231
     $form->bindRequest($this->getRequest());
232
-    
233
-    
232
+        
234 233
     if ($form->isValid())
235 234
     {
236 235
 
@@ -260,6 +259,19 @@ class CoreController extends Controller
260 259
       {
261 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 276
       $em->persist($element);
265 277
       $em->flush();

+ 37 - 0
src/Muzich/CoreBundle/Entity/Element.php Parādīt failu

@@ -229,6 +229,14 @@ class Element
229 229
    */
230 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 241
    * Get id
234 242
    *
@@ -815,4 +823,33 @@ class Element
815 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 Parādīt failu

@@ -21,7 +21,13 @@ class ElementAddForm extends AbstractType
21 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 33
   public function setName($name)
@@ -44,6 +50,7 @@ class ElementAddForm extends AbstractType
44 50
       'name' => '',
45 51
       'url' => '',
46 52
       'tags' => '',
53
+      'need_tags' => false,
47 54
       //'groups' => array(),
48 55
       'data_class' => 'Muzich\CoreBundle\Entity\Element'
49 56
     );

+ 6 - 0
src/Muzich/CoreBundle/Resources/views/Element/form.add.html.twig Parādīt failu

@@ -22,4 +22,10 @@
22 22
 
23 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 31
 {{ form_row(form._token) }}

+ 6 - 0
src/Muzich/CoreBundle/Resources/views/Element/form.edit.html.twig Parādīt failu

@@ -20,4 +20,10 @@
20 20
 
21 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 29
 {{ form_row(form._token) }}

+ 57 - 0
src/Muzich/CoreBundle/Tests/Controller/ElementControllerTest.php Parādīt failu

@@ -1239,4 +1239,61 @@ class ElementControllerTest extends FunctionalTest
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
 }