public function remove($id) { $fav = Favorite::where('StudentID', Auth::user()->StudentID)->where('FavoriteID', $id)->where('favorite', '1')->first(); $fav->favorite = 0; $fav->updated_at = date_timestamp_get(date_create()); $fav->save(); }
public static function checkFavoriteLike($modelName, $modelId, $type, $followId) { $check = Favorite::where('model_name', $modelName)->where('model_id', $modelId)->where('type_favorite', $type)->where('follow_id', $followId)->first(); if (isset($check)) { return true; } return false; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $input = Input::all(); $sessionId = Common::checkSessionLogin($input); $favorite = Favorite::where('model_name', 'Product')->where('model_id', $id)->where('follow_id', $input['user_id'])->where('type_favorite', TYPE_FAVORITE_SAVE)->first(); if (isset($favorite)) { $favorite->delete(); } return Common::returnData(200, DELETE_SUCCESS, $input['user_id'], $sessionId); }
public function action($id) { $input = Input::all(); $sessionId = Common::checkSessionLogin($input); $check = CommonFavorite::checkFavoriteLike('Category', $id, TYPE_FAVORITE_CATE, $input['user_id']); if ($check) { Favorite::where('model_name', 'Category')->where('model_id', $id)->where('follow_id', $input['user_id'])->where('type_favorite', TYPE_FAVORITE_CATE)->delete(); } else { Favorite::create(['model_name' => 'Category', 'model_id' => $id, 'follow_id' => $input['user_id'], 'type_favorite' => TYPE_FAVORITE_CATE]); } return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId); }
public function index($username) { $user = User::where('username', '=', $username)->first(); $favorites = Favorite::where('user_id', '=', $user->id)->orderBy('created_at', 'desc')->get(); $favorite_array = array(); foreach ($favorites as $key => $fave) { array_push($favorite_array, $fave->video_id); } $videos = Video::where('active', '=', '1')->whereIn('id', $favorite_array)->take(9)->get(); $data = array('user' => $user, 'type' => 'profile', 'videos' => $videos, 'menu' => Menu::orderBy('order', 'ASC')->get(), 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all()); return View::make('Theme::user', $data); }
public function showFavorites() { if (Auth::check()) { $favorites = Favorite::where('user_id', '==', Auth::User()->id)->get(); $posts = array(); $i = 0; foreach ($favorites as $favorite) { $posts[i] = Post::where('post_id', '==', $favorite->post_id)->get(); return Post::where('post_id', '==', $favorite->post_id)->get(); } return View::Make('favorites', ['posts' => $posts]); } else { return Redirect::to('login_index'); } }
/** * Display the specified video. * * @param int $id * @return Response */ public function index($id) { $video = Video::with('tags')->findOrFail($id); //Make sure video is active if (!Auth::guest() && Auth::user()->role == 'admin' || $video->active) { $favorited = false; if (!Auth::guest()) { $favorited = Favorite::where('user_id', '=', Auth::user()->id)->where('video_id', '=', $video->id)->first(); } $view_increment = $this->handleViewCount($id); $data = array('video' => $video, 'menu' => Menu::orderBy('order', 'ASC')->get(), 'view_increment' => $view_increment, 'favorited' => $favorited, 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all()); return View::make('Theme::video', $data); } else { return Redirect::to('videos')->with(array('note' => 'Sorry, this video is no longer active.', 'note_type' => 'error')); } }
public function action($id) { $input = Input::all(); $sessionId = Common::checkSessionLogin($input); $favorite = Favorite::where('model_name', 'User')->where('model_id', $id)->where('follow_id', $input['user_id'])->where('type_favorite', TYPE_FAVORITE_LIKE)->first(); if (!isset($favorite)) { Favorite::create(['model_name' => 'User', 'model_id' => $id, 'follow_id' => $input['user_id'], 'type_favorite' => TYPE_FAVORITE_LIKE]); } // else { // Favorite::where('model_name', 'User') // ->where('model_id', $id) // ->where('follow_id', $input['user_id']) // ->where('type_favorite', TYPE_FAVORITE_LIKE) // ->delete(); // } return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId); }
public function show_favorites() { if (!Auth::guest()) { $page = Input::get('page'); if (empty($page)) { $page = 1; } $favorites = Favorite::where('user_id', '=', Auth::user()->id)->orderBy('created_at', 'desc')->get(); $favorite_array = array(); foreach ($favorites as $key => $fave) { array_push($favorite_array, $fave->video_id); } $videos = Video::where('active', '=', '1')->whereIn('id', $favorite_array)->paginate(12); $data = array('videos' => $videos, 'page_title' => ucfirst(Auth::user()->username) . '\'s Favorite Videos', 'current_page' => $page, 'page_description' => 'Page ' . $page, 'menu' => Menu::orderBy('order', 'ASC')->get(), 'pagination_url' => '/favorites', 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all()); return View::make('Theme::video-list', $data); } else { return Redirect::to('videos'); } }
public static function isUserFavoritedTopic(User $user, Topic $topic) { return Favorite::where('user_id', $user->id)->where('topic_id', $topic->id)->first(); }
public static function user($id) { $fav = Favorite::where('StudentID', Auth::user()->StudentID)->where('FavoriteID', $id)->where('favorite', 1)->first(); return count($fav) ? true : false; }
public function favorites() { $jobs = Favorite::where('user_id', 1)->with('Job')->get()->toArray(); return Response::json(['data' => $jobs], 200); }
private function getByPost($id, $user_id) { return Favorite::where('post_id', $id)->where('user_id', $user_id)->first(); }
public function postAddfavorite() { $user_id = Auth::user()->id; $title_id = Input::get('title_id'); $action = Input::get('action'); $user = User::find($user_id); if ($action == "add") { $alreadyFavorited = Favorite::where('title_id', '=', $title_id)->where('user_id', '=', $user_id)->get()->toArray(); if (count($alreadyFavorited) > 0) { return $this->makeSuccessArray(true, array("msg" => "This title is already in your favorites", "alreadyfaved" => true)); } $id = DB::table('favorites')->insertGetId(array('title_id' => $title_id, 'user_id' => $user_id)); $report = Report::create(array('date' => time(), 'action_type' => 2, 'action_user_id' => $user_id, 'object_id' => $title_id, 'report_type' => 1, 'aux_object' => $user['region_id'])); $report = Report::create(array('date' => time(), 'action_type' => 2, 'action_user_id' => $user_id, 'object_id' => $title_id, 'report_type' => 3, 'aux_object' => $user['region_id'])); } else { $id = $affectedRows = Favorite::where('title_id', '=', $title_id)->where('user_id', '=', $user_id)->delete(); } if ($id) { return $this->makeSuccessArray(true, array("alreadyfaved" => false)); } else { return $this->makeSuccessArray(false, array("msg" => "There was a temporary glitch while favoriting/unfavoriting title, please try again in a moment", "alreadyfaved" => false, "db_log" => DB::getQueryLog())); } }
public static function checkProductSaved($modelId, $followId) { $check = Favorite::where('model_name', 'Product')->where('model_id', $modelId)->where('follow_id', $followId)->where('type_favorite', TYPE_FAVORITE_SAVE)->first(); if ($check) { return true; } return false; }