Example #1
0
 /**
  *	Method to handle posting support/oppose clicks on a document.
  *
  * @param int $doc
  *
  * @return json array
  */
 public function postSupport($doc)
 {
     $input = Input::get();
     $supported = (bool) $input['support'];
     $docMeta = DocMeta::withTrashed()->where('user_id', Auth::user()->id)->where('meta_key', '=', 'support')->where('doc_id', '=', $doc)->first();
     if (!isset($docMeta)) {
         $docMeta = new DocMeta();
         $docMeta->doc_id = $doc;
         $docMeta->user_id = Auth::user()->id;
         $docMeta->meta_key = 'support';
         $docMeta->meta_value = (string) $supported;
         $docMeta->save();
     } elseif ($docMeta->meta_value == (string) $supported && !$docMeta->trashed()) {
         $docMeta->delete();
         $supported = null;
     } else {
         if ($docMeta->trashed()) {
             $docMeta->restore();
         }
         $docMeta->doc_id = $doc;
         $docMeta->user_id = Auth::user()->id;
         $docMeta->meta_key = 'support';
         $docMeta->meta_value = (string) (bool) $input['support'];
         $docMeta->save();
     }
     $supports = DocMeta::where('meta_key', '=', 'support')->where('meta_value', '=', '1')->where('doc_id', '=', $doc)->count();
     $opposes = DocMeta::where('meta_key', '=', 'support')->where('meta_value', '=', '')->where('doc_id', '=', $doc)->count();
     return Response::json(array('support' => $supported, 'supports' => $supports, 'opposes' => $opposes));
 }
 public function postIntroText($doc)
 {
     $introText = DocMeta::where('meta_key', '=', 'intro-text')->where('doc_id', '=', $doc)->first();
     if (!$introText) {
         $introText = new DocMeta();
         $introText->doc_id = $doc;
         $introText->meta_key = 'intro-text';
     }
     $text = Input::get('intro-text');
     $introText->meta_value = $text;
     $introText->save();
     $response['messages'][0] = array('text' => 'Intro Text Saved.', 'severity' => 'info');
     return Response::json($response);
 }