server/src/app/Http/Controllers/Api/DocumentController.php
changeset 163 59c68fc4848e
parent 138 3079cbf80006
child 165 3c36874da933
--- a/server/src/app/Http/Controllers/Api/DocumentController.php	Sat May 28 11:49:38 2016 +0200
+++ b/server/src/app/Http/Controllers/Api/DocumentController.php	Sun May 29 16:50:17 2016 +0200
@@ -8,14 +8,16 @@
 use CorpusParole\Http\Requests;
 use CorpusParole\Http\Controllers\Controller;
 use CorpusParole\Repositories\DocumentRepository;
+use CorpusParole\Services\TranscriptManager;
 
 class DocumentController extends Controller
 {
     /**
      * Create a new controller instance.
      */
-    public function __construct(DocumentRepository $documentRepo) {
+    public function __construct(DocumentRepository $documentRepo, TranscriptManager $transcriptManager) {
         $this->documentRepository = $documentRepo;
+        $this->transcriptManager = $transcriptManager;
     }
 
     /**
@@ -60,7 +62,7 @@
     /**
      * Display the specified resource.
      *
-     * @param  int  $id
+     * @param  string  $id
      * @return Response
      */
     public function show($id)
@@ -74,6 +76,28 @@
     }
 
     /**
+     * Display the resource transcript
+     *
+     * @param string $id
+     * @return Response
+     */
+    public function transcript($id) {
+        $doc = $this->documentRepository->get($id);
+        if(is_null($doc) || is_null($doc->getTranscript()) ) {
+            abort(404);
+        }
+        $transcriptDef = $doc->getTranscript();
+
+        $transcriptUrl = $transcriptDef['url'];
+        if(empty($transcriptUrl)) {
+            abort(404);
+        }
+        $converter = $this->transcriptManager->getConverterUrl($transcriptDef['conforms-to'], $doc, $transcriptUrl);
+        return response()->json($converter->convertToJson());
+
+    }
+
+    /**
      * Show the form for editing the specified resource.
      *
      * @param  int  $id