Browse Source

Anomalie #45: Ajout d'un élément: err 500

bastien 13 years ago
parent
commit
2e33a1597f

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

@@ -353,12 +353,15 @@ class Element
353 353
    */
354 354
   public function setTagsWithIds(EntityManager $em, $ids)
355 355
   {
356
-    $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids)->execute();
357 356
     $this->tags = null;
358
-    // Pour les nouveaux ids restants
359
-    foreach ($tags as $tag)
360
-    {      
361
-      $this->addTag($tag);
357
+    if (count($ids))
358
+    {
359
+      $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids)->execute();
360
+      // Pour les nouveaux ids restants
361
+      foreach ($tags as $tag)
362
+      {      
363
+        $this->addTag($tag);
364
+      }
362 365
     }
363 366
   }
364 367
   

+ 19 - 17
src/Muzich/CoreBundle/Validator/TagsValidator.php View File

@@ -18,25 +18,27 @@ class TagsValidator extends ConstraintValidator
18 18
   
19 19
   public function isValid($value, Constraint $constraint)
20 20
   {
21
-    if (array_diff($value, array_unique($value)))
21
+    if (count($value))
22 22
     {
23
-      $this->setMessage('Tags saisies incorrects');
24
-      return false;
25
-    }
26
-    
27
-    $count = $this->entityManager
28
-      ->createQuery("SELECT COUNT(t)
29
-        FROM MuzichCoreBundle:Tag t
30
-        WHERE t IN (:tids)")
31
-      ->setParameter('tids', $value)
32
-    ->getSingleScalarResult();
33
-    
34
-    if ($count != count ($value))
35
-    {
36
-      $this->setMessage('Tags saisies incorrects');
37
-      return false;
23
+      if (array_diff($value, array_unique($value)))
24
+      {
25
+        $this->setMessage('Tags saisies incorrects');
26
+        return false;
27
+      }
28
+
29
+      $count = $this->entityManager
30
+        ->createQuery("SELECT COUNT(t)
31
+          FROM MuzichCoreBundle:Tag t
32
+          WHERE t IN (:tids)")
33
+        ->setParameter('tids', $value)
34
+      ->getSingleScalarResult();
35
+
36
+      if ($count != count ($value))
37
+      {
38
+        $this->setMessage('Tags saisies incorrects');
39
+        return false;
40
+      }
38 41
     }
39
-    
40 42
     return true;
41 43
   }
42 44
 }