public function more(\Illuminate\Http\Request $request) { $tagname = $request->tagname; $limit = $request->limit; $offset = $request->offset; if ($tagname == "Posts") { // return $offset; $cont = Content::where('userid', '=', Auth::user()->id)->where('isvisible', '=', '1')->take($limit)->skip($offset)->get(); // $cont[0]->like=1; // return $cont; $id = 0; $cont[$id]->like = -1; $cont[$id]->comment = -1; $cont[$id]->report = -1; foreach ($cont as $c) { // use any of 2 methods both works // $userActions = Useraction::whereRaw('userid = ? and crefid = ?',[Auth::user()->id,$c->id])->get(); $userActions = Useraction::where('userid', '=', Auth::user()->id)->where('crefid', '=', $c->id)->get(); foreach ($userActions as $u) { if ($u->actiontype == "Like") { $cont[$id]->like = 1; } if ($u->actiontype == "Comment") { $cont[$id]->comment = 1; } if ($u->actiontype == "Flag") { $cont[$id]->report = 1; } } $id++; } } elseif ($tagname == "Comments") { $commentsAction = Useraction::where('userid', '=', Auth::user()->id)->where('actiontype', '=', "Comment")->groupBy('crefid')->take($limit)->skip($offset)->get(); // return $commentsAction; $k = 0; foreach ($commentsAction as $com) { $comments[$k] = Content::where('id', '=', $com->crefid)->where('isvisible', '=', '1')->first(); if ($comments[$k] != "") { $comments[$k]->comment = 1; $comments[$k]->like = -1; $comments[$k]->report = -1; if (!Useraction::where('crefid', '=', $com->crefid)->where('actiontype', '=', "Like")->get()->isEmpty()) { $comments[$k]->like = 1; } if (!Useraction::where('crefid', '=', $com->crefid)->where('actiontype', '=', "Flag")->get()->isEmpty()) { $comments[$k]->report = 1; } $k++; } } $cont = $comments; // return "limit=".$limit." offset=".$offset; } elseif ($tagname == "Favourites") { $favouritesAction = Useraction::where('userid', '=', Auth::user()->id)->where('actiontype', '=', "Like")->take($limit)->skip($offset)->get(); $j = 0; foreach ($favouritesAction as $f) { $fav[$j] = Content::where('id', '=', $f->crefid)->where('isvisible', '=', '1')->first(); if ($fav[$j] = "") { $fav[$j]->like = 1; $fav[$j]->comment = -1; $fav[$j]->report = -1; // $hasCommented=; if (!Useraction::where('crefid', '=', $f->crefid)->where('actiontype', '=', "Comment")->groupBy('crefid')->get()->isEmpty()) { $fav[$j]->comment = 1; } if (!Useraction::where('crefid', '=', $f->crefid)->where('actiontype', '=', "Flag")->groupBy('crefid')->get()->isEmpty()) { $fav[$j]->report = 1; } $j++; } } $cont = $fav; } // return $cont; return View::make('user.moreContent', compact('cont')); }
public function report(\Illuminate\Http\Request $request) { // $request->likeValue; $cont = Content::find($request->contentId); Content::where('id', '=', $request->contentId)->update(['redflag' => $cont->redflag + $request->reportValue]); if ($request->reportValue == 1) { Content::where('id', '=', $request->contentId)->update(['pscore' => $cont->pscore - 20]); } else { Content::where('id', '=', $request->contentId)->update(['pscore' => $cont->pscore + 20]); } if (Auth::user()) { if ($request->reportValue == 1) { Auth::user()->update(['mplaypoints' => Auth::user()->mplaypoints + 20]); Auth::user()->update(['loyaltypoints' => Auth::user()->loyaltypoints + 20]); } else { Auth::user()->update(['mplaypoints' => Auth::user()->mplaypoints - 20]); Auth::user()->update(['loyaltypoints' => Auth::user()->loyaltypoints - 20]); } $userAction = Useraction::where('userid', '=', Auth::user()->id)->where('crefid', '=', $request->contentId)->where('actiontype', '=', 'Flag')->orWhere('actiontype', '=', 'Unflag')->get(); // return $userAction; if (!$userAction->isEmpty()) { $newActionType = ""; if ($userAction[0]->actiontype == "Flag") { $newActionType = "Unflag"; } else { $newActionType = "Flag"; } Useraction::where('id', '=', $userAction[0]->id)->update(['actiontype' => $newActionType]); } else { $userAction = new Useraction(); $userAction->crefid = $request->contentId; $userAction->actiontype = "Flag"; $userAction->creftype = "M"; $userAction->userid = Auth::user()->id; $userAction->save(); return $userAction; } // Auth::user()->action()->save($userAction); } }