Forráskód Böngészése

支持一次提交多个单词

visuddhinanda 2 éve
szülő
commit
7735c8b237
1 módosított fájl, 20 hozzáadás és 9 törlés
  1. 20 9
      app/Http/Controllers/WbwController.php

+ 20 - 9
app/Http/Controllers/WbwController.php

@@ -130,16 +130,27 @@ class WbwController extends Controller
                 }
             }
         }
-        $wbwData = "";
-        foreach ($request->get('data') as $key => $word) {
-            $xml = Tools::JsonToXml($word);
-            $xml = str_replace('<?xml version="1.0"?>','',$xml);
-            $wbwData .= $xml;
+
+        $count=0;
+        foreach ($request->get('data') as $row) {
+            $wbw = Wbw::where('block_uid',$wbwBlockId)
+                        ->where('wid',$row['sn'])
+                        ->first();
+            if($wbw){
+                $wbwData = "";
+                foreach ($row['words'] as $word) {
+                    $xml = Tools::JsonToXml($word);
+                    $xml = str_replace('<?xml version="1.0"?>','',$xml);
+                    $wbwData .= $xml;
+                }
+                $wbw->data = $wbwData;
+                $wbw->status = 5;
+                $wbw->save();
+                $count++;
+            }
         }
-        $wbw->data = $wbwData;
-        $wbw->status = 5;
-        $wbw->save();
-        return $this->ok(1);
+
+        return $this->ok($count);
     }
 
     /**