/**
  * action favori enregistré en session
  * stockage temporel
  */
 public function favori($id, $action)
 {
     //recuperation du commentaire concerné
     $comment = Comments::find($id);
     //recuperation de la variable favori en session
     //et fixation d'un tableau par defaut
     //si rien en session favori
     $favoris = session("favoris", []);
     //si l'action est 'favori'
     if ($action == "favori") {
         //j'ajoute le commentaire dans le tableau des favoris
         //en créant une clé qui a la valeur de l'id du commentaire
         //pour pouvoir le retrouver
         $favoris[$id] = $comment->id;
         Session::flash('warning', "Le commentaire {$comment->id} est désormais en favori");
     } else {
         //suppression du favori dans le tableau
         unset($favoris[$id]);
         Session::flash('warning', "Le commentaire {$comment->id} n'est désormais plus en favori");
     }
     //enregistrement en session du nouveau tableau des favoris
     Session::put("favoris", $favoris);
     //redirection
     return Redirect::route('comments_index');
 }
 /**
  *
  */
 public function update(Request $request)
 {
     $field = 'content';
     $id = $request->id;
     $value = $request->value;
     $comment = Comments::find($id);
     $comment->update([$field => $value]);
     //        Session::flash('success', "Le commentaire a bien été mis à jour");
     //        return Redirect::route('comments.index');
 }
Example #3
0
function checkTypeId($type, $type_id)
{
    switch ($type) {
        case CONSTANTS::REVIEW:
            $object = Reviews::find($type_id);
            $message = "Review does not exist";
            $error_code = CONSTANTS::ERROR_CODE_REVIEW_MISSING;
            break;
        case CONSTANTS::CHECKIN:
            $object = CheckIns::find($type_id);
            $message = "Checkin does not exist";
            $error_code = CONSTANTS::ERROR_CODE_CHECKIN_MISSING;
            break;
        case CONSTANTS::BOOKMARK:
            $object = Bookmarks::find($type_id);
            $message = "Bookmark does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case CONSTANTS::COMMENT:
            $object = Comments::find($type_id);
            $message = "Comment does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case CONSTANTS::PHOTO:
            $object = Photos::find($type_id);
            $message = "Photo does not exist";
            $error_code = CONSTANTS::ERROR_CODE_PHOTO_MISSING;
            break;
        case CONSTANTS::RESTAURANT:
            $object = Restaurants::find($type_id);
            $message = "Restaurant does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case 'user':
            $object = Users::find($type_id);
            $message = "User does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        default:
            return showErrorResponse('Invalid type', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_INVALID_TYPE);
    }
    if (!$object) {
        return showErrorResponse($message, HTTP_ACCEPTED, $error_code);
    }
    return false;
}
Example #4
0
 /**
  * Delete comment
  *
  * @param $id
  * @return Response
  */
 public function deleteCommentAction($id)
 {
     $comment = Comments::find($id);
     if (!$comment) {
         return showErrorResponse('Comment not found');
     }
     $comment_type = $comment->type;
     $comment_type_id = $comment->type_id;
     try {
         $comment->deleteComment();
         $json_return[KeyParser::data] = array(KeyParser::id => $id, KeyParser::is_success => CONSTANTS::DELETE_SUCCESS);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     $comments = Comments::getByTypePaginate($comment_type, $comment_type_id);
     foreach ($comments as $comment) {
         $user = Users::find($comment->user_id);
         $json_return[KeyParser::comments][] = array(KeyParser::comment => ModelFormatter::commentFormat($comment), KeyParser::user => ModelFormatter::userFormat($user));
     }
     $json_return[KeyParser::comment_count] = Comments::getCountByType($comment_type, $comment_type_id);
     $json_return[KeyParser::page] = array(KeyParser::current => $comments->currentPage(), KeyParser::number => $comments->lastPage());
     return response()->json($json_return);
 }