/** * 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; } }
/** * Send push notification through GCM server * * @param Array $registration_ids = device_ids * @return result * */ private function sendToGCM($registration_ids) { $user_notification_count = $this->getNotificationByUserTo($this->user_id_to, CONSTANTS::NOTIFICATION_STATUS_NEW, true); $type = $this->type; $activities = array(); $user_count = 0; $username_array = array(); $activity_type = 0; //Time Interval for notification groupings = 1 Day (86400 seconds) $date_range = array(KeyParser::date_from => date('Y-m-d H:i:s', time() - CONSTANTS::DAY_SECOND_VALUE), KeyParser::date_to => date('Y-m-d H:i:s')); //Build usernames_from array() if (strpos($type, 'photo')) { $activity_type = 5; } elseif (strpos($type, 'checkin')) { $activity_type = 2; } elseif (strpos($type, 'review')) { $activity_type = 1; } if ($type == CONSTANTS::NOTIFICATION_TYPE_LIKE_CHECKIN || $type == CONSTANTS::NOTIFICATION_TYPE_LIKE_REVIEW || $type == CONSTANTS::NOTIFICATION_TYPE_LIKE_PHOTO) { $activities = Like::getLikerList($activity_type, $this->type_id, false, $date_range); } else { if ($type == CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_CHECKIN || $type == CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_REVIEW || $type == CONSTANTS::NOTIFICATION_TYPE_COMMENT_ON_PHOTO) { $activities = Comments::getByType($activity_type, $this->type_id, $date_range); } else { $user_from = Users::find($this->user_id_from); $username_array[] = $user_from->getUserFullName(); } } foreach ($activities as $activity) { if ($activity->user_id == $this->user_id_to) { continue; } $user_count++; $user_fullname = Users::getFullNameById($activity->user_id); if ($user_count <= CONSTANTS::NOTIFICATION_USER_GROUP_LIMIT && !in_array($user_fullname, $username_array)) { $username_array[] = $user_fullname; } } // Build payload $payload = array(KeyParser::id => $this->id, KeyParser::usernames_from => $username_array, KeyParser::count => $user_notification_count, KeyParser::type => $this->type, KeyParser::type_id => $this->type_id, KeyParser::restaurant_id => $this->restaurant_id, KeyParser::user_id_from => $this->user_id_from, KeyParser::user_id_to => $this->user_id_to, 'typeid' => '0', 'useridfrom' => '0', 'useridto' => '0', 'restaurantid' => '0', 'message' => $this->buildMessage()); $restaurant_name = Restaurants::getRestaurantNameById($this->restaurant_id); if ($restaurant_name) { $payload[KeyParser::restaurant_name] = $restaurant_name; } $fields = array(KeyParser::registration_ids => $registration_ids, KeyParser::data => $payload); $headers = array('Authorization: key=' . GCM_API_KEY, 'Content-Type: application/json'); //Prepare cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, GCM_API_URL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); curl_close($ch); return $result; }
/** * 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; } }
/** * Returns an array of photo data * * @param Photos $data * @return array */ public static function photosFormat(Photos $data) { $viewer_id = Input::get('viewer_id'); $short_photo_url = route('short_photo_view', ['id' => $data->id]); $arr = array(); $arr[KeyParser::id] = $data->id; $arr[KeyParser::short_url] = $short_photo_url; $arr[KeyParser::restaurant_id] = $data->restaurant_id; $arr[KeyParser::type] = $data->type; $arr[KeyParser::type_id] = $data->type_id; $arr[KeyParser::user_id] = $data->user_id; $arr[KeyParser::text] = $data->text; $arr[KeyParser::url] = $data->url; $arr[KeyParser::date_uploaded] = elapsedTime($data->date_uploaded); $arr[KeyParser::status] = $data->status; $arr[KeyParser::comment_count] = Comments::getCountByType(CONSTANTS::PHOTO, $data->id); $arr[KeyParser::like_count] = Like::getCount(CONSTANTS::PHOTO, $data->id); if ($viewer_id) { $arr[KeyParser::is_liked] = Like::isLiked($viewer_id, CONSTANTS::PHOTO, $data->id); } return $arr; }
/** * Get the list of users that likes the activity * * @param request $request * @return Response */ public function likerListAction(Request $request) { $viewer_id = $request->viewer_id; $type = $request->type; $type_id = $request->type_id; $error_msg = checkTypeId($type, $type_id); if ($error_msg) { return $error_msg; } $liker_list = Like::getLikerList($type, $type_id); $json_return[KeyParser::data] = array(); if ($liker_list) { foreach ($liker_list as $index => $liker) { $user_id = $liker->user_id; $user_data = Users::find($user_id); if ($user_data) { $array = ModelFormatter::userLongFormat($user_data); $array += array(KeyParser::follower_count => Follow::getCountByUserId($user_id, CONSTANTS::FOLLOW_FOLLOWER), KeyParser::review_count => Reviews::getCountByUserId($user_id), KeyParser::is_followed_by_viewer => Follow::isFollowed($viewer_id, $user_id)); $json_return[KeyParser::data][] = $array; unset($array); } // end of check $user_date } $json_return[KeyParser::like_count] = Like::getCount($type, $type_id); } $json_return[KeyParser::page] = array(KeyParser::current => $liker_list->currentPage(), KeyParser::number => $liker_list->lastPage()); return response()->json($json_return); }
/** * 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); }
/** * Delete comment/s and likes of the comment/s by type * * @param $type * @param $type_id * @return mixed * @throws \Exception */ public function deleteCommentByType($type, $type_id) { try { $connection = $this->getConnection(); $connection->beginTransaction(); $comments = Comments::where('type', $type)->where('type_id', $type_id); if ($comments) { // TODO: Delete associated notification foreach ($comments as $comment) { $like = new Like(); $like->deleteLikes(CONSTANTS::COMMENT, $comment->id); $comment->delete(); } } else { throw new \Exception('No comments found'); } $connection->commit(); } catch (\Exception $e) { $connection->rollBack(); throw $e; } }