Example #1
0
 /**
  * Delete Review
  * @param $id
  * @throws $e
  */
 public function deleteReview($id)
 {
     $connection = $this->getConnection();
     try {
         $connection->beginTransaction();
         $review = Reviews::find($id);
         if ($review) {
             //delete review
             $review->delete();
             //delete activities
             $activities = new Activities();
             $activities->deleteActivity(CONSTANTS::REVIEW, $id);
             //delete comments
             $comments = new Comments();
             $comments->deleteCommentByType(CONSTANTS::REVIEW, $id);
             //delete likes
             $like = new Like();
             $like->deleteLikes(CONSTANTS::REVIEW, $id);
         } else {
             throw new \Exception('No review found');
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }
Example #2
0
 /**
  * Delete a Photo
  * route: /photos/delete{id}
  *
  * @param Request $request
  * @return Response
  */
 public function photoDeleteAction(Request $request)
 {
     $path = API_UPLOAD_DIR . '/';
     $data = $request->json()->get('Photo');
     $failed_ids = array();
     $succeeded_ids = array();
     foreach ($data['id'] as $photo_id) {
         $photo = Photos::find($photo_id);
         if (!$photo || $photo->user_id != $data['user_id']) {
             $failed_ids[] = $photo_id;
             continue;
         }
         $filename = $photo->url;
         $fullpath = $path . $filename;
         try {
             DB::beginTransaction();
             if (FILE::exists($fullpath)) {
                 // Delete an array of files
                 //$files = array($file1, $file2);
                 FILE::delete($fullpath);
             }
             // end if Exists
             $comment = new Comments();
             $comment->deleteCommentByType(CONSTANTS::PHOTO, $photo->id);
             $like = new Like();
             $like->deleteLikes(CONSTANTS::PHOTO, $photo->id);
             $activity = new Activities();
             $activity->deleteActivity(CONSTANTS::PHOTO_UPLOAD_RESTAURANT, $photo->id);
             $photo->delete();
             DB::commit();
             $succeeded_ids[] = $photo_id;
         } catch (\Exception $e) {
             DB::rollback();
             return showErrorResponse('Error deleting photo');
         }
     }
     $json_return[KeyParser::data] = array(KeyParser::success => $succeeded_ids, KeyParser::failed => $failed_ids);
     return response()->json($json_return);
 }
Example #3
0
 /**
  * Delete Checkin
  * @param $id
  * @throws $e
  */
 public function deleteCheckin($id)
 {
     $connection = $this->getConnection();
     try {
         $connection->beginTransaction();
         $checkin = CheckIns::find($id);
         if ($checkin) {
             //delete checkin
             $checkin->delete();
             //delete activities
             $activities = new Activities();
             $activities->deleteActivity(CONSTANTS::CHECKIN, $id);
             //delete comments
             $comments = new Comments();
             $comments->deleteCommentByType(CONSTANTS::CHECKIN, $id);
             //delete likes
             $like = new Like();
             $like->deleteLikes(CONSTANTS::CHECKIN, $id);
         } else {
             throw new \Exception('No checkin found');
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }
Example #4
0
 /**
  * Delete bookmark/s and activity when it was bookmarked
  *
  * @param $id
  * @return mixed
  * @throws \Exception
  */
 public function deleteBookmark($id)
 {
     $connection = $this->getConnection();
     try {
         $connection->beginTransaction();
         $bookmark = self::find($id);
         if ($bookmark) {
             $activity = new Activities();
             $activity->deleteActivity(CONSTANTS::BOOKMARK, $id);
             $bookmark->delete();
         } else {
             throw new \Exception('No bookmark found');
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }