public function storeFavorite()
 {
     $fav = new Favorite();
     $fav->user_id = userId();
     $fav->job_id = Input::get('job_id');
     $create = $fav->save();
     return Response::json(['data' => $fav], 200);
 }
Esempio n. 2
0
 public static function store($favoriteId)
 {
     $user = self::get_user_logged_in();
     if ($user == null) {
         Redirect::to('/login');
     }
     $favorite = new Favorite(array('applicant_id' => $user->id, 'degree_id' => $favoriteId));
     $favorite->save();
     Redirect::to('/search', array('message' => 'Degree saved to favorites!'));
 }
 public function addFavorite($id)
 {
     if (Auth::check()) {
         $favorite = new Favorite();
         $favorite->user_id = Auth::User()->id;
         $favorite->post_id = $id;
         $favorite->save();
     } else {
         return Redirect::to('login_index');
     }
 }
 /**
  * Create a new entry in favorite table
  */
 public function actionFavorite()
 {
     $this->forcePostRequest();
     $attributes = array('object_model' => $this->contentModel, 'object_id' => $this->contentId, 'created_by' => Yii::app()->user->id);
     $favorite = Favorite::model()->findByAttributes($attributes);
     if ($favorite == null && !Yii::app()->user->isGuest) {
         // Create Favorite Object
         $favorite = new Favorite();
         $favorite->object_model = $this->contentModel;
         $favorite->object_id = $this->contentId;
         $favorite->save();
     }
     $this->actionShowFavorites();
 }
 public function favorite()
 {
     $video_id = Input::get('video_id');
     $favorite = Favorite::where('user_id', '=', Auth::user()->id)->where('video_id', '=', $video_id)->first();
     if (isset($favorite->id)) {
         $favorite->delete();
     } else {
         $favorite = new Favorite();
         $favorite->user_id = Auth::user()->id;
         $favorite->video_id = $video_id;
         $favorite->save();
         echo $favorite;
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Favorite();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Favorite'])) {
         $model->attributes = $_POST['Favorite'];
         if ($model->save()) {
             echo CJSON::encode(array('status' => true));
         } else {
             echo CJSON::encode(array('status' => false));
         }
         Yii::app()->end();
     }
     throw new CHttpException(400, 'Такой страницы нет');
 }
 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);
 }
Esempio n. 8
0
 /**
  *  @fn toggle_favorite
  *  @short Toggles a favorite instrument
  *  @details Action to toggle an instrument as favorite, handles the postback
  *  action to save the model.
  */
 public function toggle_favorite()
 {
     if ($this->request->is_post()) {
         $_POST['isin'] = $_REQUEST['id'];
         if ($this->is_favorite) {
             $this->favorite->delete();
             unset($this->favorite);
             $this->is_favorite = FALSE;
         } else {
             $_POST['isin'] = $_REQUEST['id'];
             $favorite = new Favorite(array('utente' => $_COOKIE['username'], 'isin' => $_POST['isin']));
             $favorite->save();
             $this->is_favorite = TRUE;
         }
         die("{\"isin\":\"{$_REQUEST['id']}\",\"favorite\":" . ($this->is_favorite ? 'true' : 'false') . "}");
     } else {
         HTTP::error(400);
     }
 }