server/src/app/Http/Controllers/Api/DocumentController.php
changeset 163 59c68fc4848e
parent 138 3079cbf80006
child 165 3c36874da933
equal deleted inserted replaced
162:a6cf5a06f02d 163:59c68fc4848e
     6 //use Illuminate\Http\Response;
     6 //use Illuminate\Http\Response;
     7 
     7 
     8 use CorpusParole\Http\Requests;
     8 use CorpusParole\Http\Requests;
     9 use CorpusParole\Http\Controllers\Controller;
     9 use CorpusParole\Http\Controllers\Controller;
    10 use CorpusParole\Repositories\DocumentRepository;
    10 use CorpusParole\Repositories\DocumentRepository;
       
    11 use CorpusParole\Services\TranscriptManager;
    11 
    12 
    12 class DocumentController extends Controller
    13 class DocumentController extends Controller
    13 {
    14 {
    14     /**
    15     /**
    15      * Create a new controller instance.
    16      * Create a new controller instance.
    16      */
    17      */
    17     public function __construct(DocumentRepository $documentRepo) {
    18     public function __construct(DocumentRepository $documentRepo, TranscriptManager $transcriptManager) {
    18         $this->documentRepository = $documentRepo;
    19         $this->documentRepository = $documentRepo;
       
    20         $this->transcriptManager = $transcriptManager;
    19     }
    21     }
    20 
    22 
    21     /**
    23     /**
    22      * Display a listing of the resource.
    24      * Display a listing of the resource.
    23      *
    25      *
    58     }
    60     }
    59 
    61 
    60     /**
    62     /**
    61      * Display the specified resource.
    63      * Display the specified resource.
    62      *
    64      *
    63      * @param  int  $id
    65      * @param  string  $id
    64      * @return Response
    66      * @return Response
    65      */
    67      */
    66     public function show($id)
    68     public function show($id)
    67     {
    69     {
    68         $doc = $this->documentRepository->get($id);
    70         $doc = $this->documentRepository->get($id);
    69         if(is_null($doc)) {
    71         if(is_null($doc)) {
    70             abort(404);
    72             abort(404);
    71         }
    73         }
    72         //$this->documentRepository->resolveLexvo([$doc,]);
    74         //$this->documentRepository->resolveLexvo([$doc,]);
    73         return response()->json(["document" => $doc]);
    75         return response()->json(["document" => $doc]);
       
    76     }
       
    77 
       
    78     /**
       
    79      * Display the resource transcript
       
    80      *
       
    81      * @param string $id
       
    82      * @return Response
       
    83      */
       
    84     public function transcript($id) {
       
    85         $doc = $this->documentRepository->get($id);
       
    86         if(is_null($doc) || is_null($doc->getTranscript()) ) {
       
    87             abort(404);
       
    88         }
       
    89         $transcriptDef = $doc->getTranscript();
       
    90 
       
    91         $transcriptUrl = $transcriptDef['url'];
       
    92         if(empty($transcriptUrl)) {
       
    93             abort(404);
       
    94         }
       
    95         $converter = $this->transcriptManager->getConverterUrl($transcriptDef['conforms-to'], $doc, $transcriptUrl);
       
    96         return response()->json($converter->convertToJson());
       
    97 
    74     }
    98     }
    75 
    99 
    76     /**
   100     /**
    77      * Show the form for editing the specified resource.
   101      * Show the form for editing the specified resource.
    78      *
   102      *