author | ymh <ymh.work@gmail.com> |
Fri, 30 Sep 2016 00:43:04 +0200 | |
changeset 307 | 07b44a378ad8 |
parent 304 | 20071981ba2a |
child 319 | 78990a8a069b |
permissions | -rw-r--r-- |
4 | 1 |
<?php |
2 |
||
3 |
namespace CorpusParole\Http\Controllers\Api; |
|
4 |
||
5 |
use Illuminate\Http\Request; |
|
28 | 6 |
//use Illuminate\Http\Response; |
4 | 7 |
|
8 |
use CorpusParole\Http\Requests; |
|
9 |
use CorpusParole\Http\Controllers\Controller; |
|
10 |
use CorpusParole\Repositories\DocumentRepository; |
|
163 | 11 |
use CorpusParole\Services\TranscriptManager; |
4 | 12 |
|
13 |
class DocumentController extends Controller |
|
14 |
{ |
|
15 |
/** |
|
16 |
* Create a new controller instance. |
|
17 |
*/ |
|
163 | 18 |
public function __construct(DocumentRepository $documentRepo, TranscriptManager $transcriptManager) { |
4 | 19 |
$this->documentRepository = $documentRepo; |
163 | 20 |
$this->transcriptManager = $transcriptManager; |
4 | 21 |
} |
22 |
||
23 |
/** |
|
24 |
* Display a listing of the resource. |
|
25 |
* |
|
26 |
* @return Response |
|
27 |
*/ |
|
28 |
public function index() |
|
29 |
{ |
|
20 | 30 |
$paginator = $this->documentRepository->paginateAll(); |
125 | 31 |
$res = $paginator->toArray(); |
32 |
if(array_key_exists('data', $res)) { |
|
33 |
$documents = $res['data']; |
|
34 |
unset($res['data']); |
|
130
fac22d8c2df8
add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
35 |
$res['documents'] = $documents; |
128
bc18286e55b2
remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
36 |
//$res['documents'] = $this->documentRepository->resolveLexvo($documents); |
20 | 37 |
} |
38 |
return response()->json($res); |
|
4 | 39 |
} |
40 |
||
41 |
/** |
|
42 |
* Show the form for creating a new resource. |
|
43 |
* |
|
44 |
* @return Response |
|
45 |
*/ |
|
46 |
public function create() |
|
47 |
{ |
|
48 |
// |
|
49 |
} |
|
50 |
||
51 |
/** |
|
52 |
* Store a newly created resource in storage. |
|
53 |
* |
|
54 |
* @param Request $request |
|
55 |
* @return Response |
|
56 |
*/ |
|
57 |
public function store(Request $request) |
|
58 |
{ |
|
59 |
// |
|
60 |
} |
|
61 |
||
62 |
/** |
|
63 |
* Display the specified resource. |
|
64 |
* |
|
163 | 65 |
* @param string $id |
4 | 66 |
* @return Response |
67 |
*/ |
|
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
165
diff
changeset
|
68 |
public function show(Request $request, $id) |
4 | 69 |
{ |
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
277
diff
changeset
|
70 |
$id= urldecode($id); |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
165
diff
changeset
|
71 |
$short = filter_var($request->input('short', false), FILTER_VALIDATE_BOOLEAN); |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
165
diff
changeset
|
72 |
$doc = $this->documentRepository->get($id, $short); |
4 | 73 |
if(is_null($doc)) { |
74 |
abort(404); |
|
75 |
} |
|
128
bc18286e55b2
remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
76 |
//$this->documentRepository->resolveLexvo([$doc,]); |
20 | 77 |
return response()->json(["document" => $doc]); |
4 | 78 |
} |
79 |
||
80 |
/** |
|
163 | 81 |
* Display the resource transcript |
82 |
* |
|
83 |
* @param string $id |
|
84 |
* @return Response |
|
85 |
*/ |
|
86 |
public function transcript($id) { |
|
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
277
diff
changeset
|
87 |
$id= urldecode($id); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
277
diff
changeset
|
88 |
|
163 | 89 |
$doc = $this->documentRepository->get($id); |
90 |
if(is_null($doc) || is_null($doc->getTranscript()) ) { |
|
91 |
abort(404); |
|
92 |
} |
|
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
165
diff
changeset
|
93 |
$transcript = $doc->getTranscript(); |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
165
diff
changeset
|
94 |
$transcriptUrl = $transcript->getUrl(); |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
165
diff
changeset
|
95 |
if(empty($transcriptUrl) || empty($transcript->getConformsTo())) { |
163 | 96 |
abort(404); |
97 |
} |
|
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
165
diff
changeset
|
98 |
$converter = $this->transcriptManager->getConverterUrl($transcript->getConformsTo(), $doc, $transcriptUrl); |
163 | 99 |
return response()->json($converter->convertToJson()); |
100 |
||
101 |
} |
|
102 |
||
103 |
/** |
|
4 | 104 |
* Show the form for editing the specified resource. |
105 |
* |
|
106 |
* @param int $id |
|
107 |
* @return Response |
|
108 |
*/ |
|
109 |
public function edit($id) |
|
110 |
{ |
|
111 |
// |
|
112 |
} |
|
113 |
||
114 |
/** |
|
28 | 115 |
* Update the specified document in storage. |
4 | 116 |
* |
117 |
* @param Request $request |
|
118 |
* @param int $id |
|
119 |
* @return Response |
|
120 |
*/ |
|
121 |
public function update(Request $request, $id) |
|
122 |
{ |
|
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
277
diff
changeset
|
123 |
$id= urldecode($id); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
277
diff
changeset
|
124 |
|
28 | 125 |
$data = $request->json(); |
126 |
$document = $data->get('document'); |
|
127 |
$doc = $this->documentRepository->get($id); |
|
128 |
if(is_null($doc)) { |
|
129 |
abort(404); |
|
130 |
} |
|
131 |
||
138
3079cbf80006
add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents:
130
diff
changeset
|
132 |
//for now, update contributors and subjects only |
28 | 133 |
$doc->setContributors($document['contributors']); |
138
3079cbf80006
add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents:
130
diff
changeset
|
134 |
$doc->setSubjects($document['subjects']); |
277
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
135 |
$doc->addGeoInfo()->setRefLocs($document['reflocs']); |
bd4bc1db4f40
add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
136 |
$doc->getGeoInfo()->commit(); |
138
3079cbf80006
add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents:
130
diff
changeset
|
137 |
|
3079cbf80006
add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents:
130
diff
changeset
|
138 |
$doc->setModified(); |
28 | 139 |
|
140 |
$this->documentRepository->save($doc); |
|
141 |
||
142 |
return response('', 204); |
|
4 | 143 |
} |
144 |
||
145 |
/** |
|
146 |
* Remove the specified resource from storage. |
|
147 |
* |
|
148 |
* @param int $id |
|
149 |
* @return Response |
|
150 |
*/ |
|
151 |
public function destroy($id) |
|
152 |
{ |
|
153 |
// |
|
154 |
} |
|
155 |
} |