/**
  * @param $id
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function delete($id)
 {
     try {
         if (Annotation::destroy($id)) {
             return response('', 204);
         }
     } catch (\Exception $e) {
         return response()->json(['status' => 'error', 'message' => $e->getMessage()], 400);
     }
     return response()->json(['status' => 'error', 'message' => 'Could not find the annotation.'], 400);
 }
 public function getRestoreDoc($docId)
 {
     $doc = Doc::withTrashed()->find($docId);
     if ($doc->publish_state == Doc::PUBLISH_STATE_DELETED_ADMIN) {
         if (!Auth::user()->hasRole('admin')) {
             return Response('Unauthorized.', 403);
         }
     }
     if (!$doc->canUserEdit(Auth::user())) {
         return Response('Unauthorized.', 403);
     }
     DocMeta::withTrashed()->where('doc_id', $docId)->restore();
     DocContent::withTrashed()->where('doc_id', $docId)->restore();
     Annotation::withTrashed()->where('doc_id', $docId)->restore();
     Comment::withTrashed()->where('doc_id', $docId)->restore();
     $doc->restore();
     $doc->publish_state = Doc::PUBLISH_STATE_UNPUBLISHED;
     $doc->save();
     return Response::json($doc);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $annotation = Annotation::find($id);
     $annotation->delete();
     return redirect('annotations');
 }
 public function postComments($docId, $annotationId)
 {
     $comment = Input::get('comment');
     $annotation = Annotation::where('doc_id', '=', $docId)->where('id', '=', $annotationId)->first();
     $annotation->link = $annotation->getLink();
     $annotation->type = 'annotation';
     $result = $annotation->addOrUpdateComment($comment);
     // TODO: Hack to allow notification events.  Needs cleaned up.
     $result->doc_id = $docId;
     $result->link = $result->getLink($docId);
     Event::fire(MadisonEvent::DOC_SUBCOMMENT, array('subcomment' => $result, 'parent' => $annotation));
     return Response::json($result);
 }