Example #1
0
/**
 * updates or removes favorited item 
 *
 * @author Steve Ryan, steve@2pisystems.com, 2015
 **/
function ajaxEditFavorites_ALL(Web $w)
{
    $id = $w->request("id");
    $class = $w->request("class");
    $user = $w->Auth->user();
    $cmd = $w->request("cmd");
    if (!empty($id) && !empty($class) && !empty($user) && !empty($cmd)) {
        if ($cmd == "add") {
            $favorite = new Favorite($w);
            $favorite->object_class = $class;
            $favorite->object_id = $id;
            $favorite->user_id = $user->id;
            $favorite->insertOrUpdate();
            echo $w->Favorite->getFavoriteButton($id, $class);
        } else {
            if ($cmd == "remove") {
                $favorite = $w->Favorite->getDataByObject($id, $class);
                if (get_class($favorite) == "Favorite" && $favorite->id > 0) {
                    $favorite->delete();
                }
                echo $w->Favorite->getFavoriteButton($id, $class);
            } else {
                echo "Invalid request";
            }
        }
    } else {
        echo "Invalid request";
    }
}
Example #2
0
 function check_favorite()
 {
     $isin = isset($_REQUEST['isin']) ? $_REQUEST['isin'] : $_REQUEST['id'];
     if ($isin) {
         $conn = $this->get_connection();
         $favorite_factory = new Favorite();
         $favorites = $favorite_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($_COOKIE['username'])}' " . "AND `isin` = '{$conn->escape($isin)}'"));
         $this->is_favorite = count($favorites) > 0;
         $this->favorite = $favorites[0];
     }
 }
Example #3
0
 public function get_remove_from_favorites($page_id)
 {
     if (Favorite::remove($page_id)) {
         return Redirect::to("page/{$page_id}")->with('removed', true);
     }
     return Response::error('500');
 }
 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();
 }
Example #5
0
 public function run()
 {
     $faker = Faker::create();
     $topics = Node::lists('id');
     foreach (range(1, 100) as $index) {
         Favorite::create(['user_id' => 1, 'topic_id' => $faker->randomElement($topics)]);
     }
 }
 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;
 }
 public function run()
 {
     Favorite::create(['type_favorite' => '1', 'model_id' => '1', 'model_name' => 'Product', 'follow_id' => '1']);
     Favorite::create(['type_favorite' => '1', 'model_id' => '2', 'model_name' => 'Product', 'follow_id' => '1']);
     Favorite::create(['type_favorite' => '1', 'model_id' => '1', 'model_name' => 'Product', 'follow_id' => '2']);
     Favorite::create(['type_favorite' => '2', 'model_id' => '2', 'model_name' => 'User', 'follow_id' => '1']);
     Favorite::create(['type_favorite' => '2', 'model_id' => '3', 'model_name' => 'User', 'follow_id' => '1']);
     Favorite::create(['type_favorite' => '2', 'model_id' => '1', 'model_name' => 'User', 'follow_id' => '2']);
 }
 /**
  * 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);
 }
Example #9
0
 public static function syncFavorites($userid, $favorites)
 {
     if (isset($favorites->deleted) && is_array($favorites->deleted)) {
         self::deleteFavorites($userid, $favorites->deleted);
     }
     if (isset($favorites->added) && is_array($favorites->added)) {
         self::addFavorites($userid, $favorites->added);
     }
     $syncedfavorites = Favorite::fetchAll($userid, true);
     self::send($syncedfavorites);
 }
 /**
  * Executes the widget
  */
 public function run()
 {
     $currentUserFavorited = false;
     $favorites = Favorite::GetFavorites(get_class($this->object), $this->object->id);
     foreach ($favorites as $favorite) {
         if ($favorite->getUser()->id == Yii::app()->user->id) {
             $currentUserFavorited = true;
         }
     }
     $this->render('favoriteLink', array('favorites' => $favorites, 'currentUserFavorited' => $currentUserFavorited, 'id' => $this->object->getUniqueId()));
 }
Example #11
0
 public function run()
 {
     $object_id = $this->model->id;
     $model_id = get_class($this->model);
     $count = Favorite::model()->countByAttributes(array('object_id' => $object_id, 'model_id' => $model_id));
     $added = false;
     if (!Yii::app()->user->isGuest) {
         $added = Favorite::model()->exists("user_id = " . Yii::app()->user->id . " AND object_id = {$object_id} AND model_id = '{$model_id}'");
     }
     $this->render('FavoriteWidget', array('model_id' => $model_id, 'object_id' => $object_id, 'model' => $this->model, 'count' => $count, 'added' => $added, 'guest_msg' => t('Только зарегистрированные пользователи могут добавлять посты в избранное'), 'user_msg' => t('Добавить в избранное'), 'count_msg' => t('Количество пользователей, добавивших пост в избранное')));
 }
 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);
 }
Example #14
0
 public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Favorite::isUserFavoritedTopic(Auth::user(), $topic)) {
         Auth::user()->favoriteTopics()->detach($topic->id);
     } else {
         Auth::user()->favoriteTopics()->attach($topic->id);
         Notification::notify('topic_favorite', Auth::user(), $topic->user, $topic);
     }
     Flash::success(lang('Operation succeeded.'));
     return Redirect::route('topics.show', $topic->id);
 }
 /**
  * Remove entry in favorite table
  */
 public function actionUnFavorite()
 {
     $this->forcePostRequest();
     if (!Yii::app()->user->isGuest) {
         $attributes = array('object_model' => $this->contentModel, 'object_id' => $this->contentId, 'created_by' => Yii::app()->user->id);
         $favorite = Favorite::model()->findByAttributes($attributes);
         if ($favorite != null) {
             $favorite->delete();
         }
     }
     $this->actionShowFavorites();
 }
Example #16
0
 public static function getUserFavorites()
 {
     $user = self::get_user_logged_in();
     $favorites = array();
     if ($user) {
         $unprocessedFavorites = Favorite::findByUser($user->id);
         foreach ($unprocessedFavorites as $favorite) {
             $favorites[] = $favorite->degree_id;
         }
     }
     return $favorites;
 }
 /**
  * Favorites Count for specific model
  */
 public static function GetFavorites($objectModel, $objectId)
 {
     $cacheId = "favorites_" . $objectModel . "_" . $objectId;
     $cacheValue = Yii::app()->cache->get($cacheId);
     if ($cacheValue === false) {
         $newCacheValue = Favorite::model()->findAllByAttributes(array('object_model' => $objectModel, 'object_id' => $objectId));
         Yii::app()->cache->set($cacheId, $newCacheValue, HSetting::Get('expireTime', 'cache'));
         return $newCacheValue;
     } else {
         return $cacheValue;
     }
 }
 public function actionCreateOrDelete()
 {
     if (!isset($_POST['Favorite'])) {
         $this->badRequest();
     }
     $response = array();
     $attributes = array('user_id' => Yii::app()->user->id, 'object_id' => $_POST['Favorite']['object_id'], 'model_id' => $_POST['Favorite']['model_id']);
     $favorite = Favorite::model()->findByAttributes($attributes);
     if ($favorite) {
         $response['action'] = 'delete';
         Favorite::model()->deleteAllByAttributes($attributes);
     } else {
         $response['action'] = 'create';
         $favorite = new Favorite();
         $favorite->attributes = $attributes;
         if (!$favorite->save()) {
             $response['errors'] = $favorite->errors_flat_array;
         }
     }
     $response['count'] = Favorite::model()->countByAttributes(array('object_id' => $favorite->object_id, 'model_id' => $favorite->model_id));
     echo CJSON::encode($response);
 }
 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'));
     }
 }
Example #21
0
 public static function find_popular($link_class = "Itunes", $user_id = 0)
 {
     $sql = "SELECT l.* FROM " . $link_class::get_table_name() . " l";
     $sql .= " JOIN popular p ON p.id = l.id AND p.type = '" . $link_class::get_table_name() . "' LIMIT 18";
     $links = $link_class::find_by_sql($sql);
     $movies = array();
     foreach ($links as $link) {
         $movie = self::find_by_id($link->id);
         $movie->link = $link;
         if ($user_id > 0 && Favorite::find($user_id, $link->id)) {
             $movie->favorited = true;
         }
         $movies[] = $movie;
     }
     return !empty($movies) ? $movies : false;
 }
 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 saved($id)
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     $check = CommonFavorite::checkFavoriteLike('Product', $id, TYPE_FAVORITE_SAVE, $input['user_id']);
     if (!$check) {
         Favorite::create(['model_name' => 'Product', 'model_id' => $id, 'follow_id' => $input['user_id'], 'type_favorite' => TYPE_FAVORITE_SAVE]);
     }
     // else {
     // 	Favorite::where('model_name', 'Product')
     // 		->where('model_id', $id)
     // 		->where('follow_id', $input['user_id'])
     // 		->where('type_favorite', TYPE_FAVORITE_SAVE)
     // 		->delete();
     // }
     return Common::returnData(200, SUCCESS, $input['user_id'], $input['session_id']);
 }
 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');
     }
 }
Example #25
0
 /**
  * STATIC Get the number of faved items per model
  * @return string $archived {true, false, both}
  * @return array $favorites
  */
 static function getAllCount($archives = true)
 {
     $_this = Common::getModel('Favorite');
     // Get potential models from list
     $models = @array_keys(Configure::read('App.favorites.models'), true);
     // default condition
     $conditions = array('conditions' => array('model' => $models, 'user_id' => User::get('id')), 'fields' => array('model', 'COUNT(model) as count'), 'group' => array('Favorite.model'));
     // Bind the models if the search depends on record's status
     if ($archives != 'both' && is_bool($archives)) {
         Favorite::__bindArchivableModels(&$_this, &$models, &$conditions, $archives);
     }
     // Search for faved records
     $favorites = $_this->find('all', $conditions);
     //pr($favorites);
     //tidy up
     foreach ($favorites as $i => $fav) {
         $favorites[$i]['Favorite']['count'] = $fav[0]['count'];
         unset($favorites[$i][0]);
     }
     return $favorites;
 }
Example #26
0
 public static function isUserFavoritedTopic(User $user, Topic $topic)
 {
     return Favorite::where('user_id', $user->id)->where('topic_id', $topic->id)->first();
 }
 public function favorites()
 {
     $favorites = Favorite::with('users')->where('StudentID', Auth::user()->StudentID)->where('favorite', 1)->get();
     return View::make('validated.favorites', compact('favorites'));
 }
Example #28
0
 public function actionUnfavorite()
 {
     $appID = $_POST['id'];
     if (empty($appID)) {
         throw new THttpException('操作失败');
     }
     $app = AppInfoList::model()->findByPk($appID);
     if (empty($app) || $app->Status > 0) {
         throw new THttpException('操作失败');
     }
     $userID = Yii::app()->user->id;
     $user = User::model()->findByPk($userID);
     if (empty($user)) {
         throw new THttpException('操作失败');
     }
     try {
         if (Favorite::favoriteBoolean($appID, $userID, false)) {
             echo new ReturnInfo(RET_SUC, 'success');
         }
     } catch (Exception $e) {
         throw new THttpException('操作失败');
     }
 }
 public static function user($id)
 {
     $fav = Favorite::where('StudentID', Auth::user()->StudentID)->where('FavoriteID', $id)->where('favorite', 1)->first();
     return count($fav) ? true : false;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Favorite::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }