Example #1
0
 /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $users = new MUser();
     echo $users->add();
     echo '-------';
     exit;
     //return view('home');
 }
Example #2
0
 /**
  * Update the specified resource in storage.
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['name' => 'required', 'email' => 'required']);
     if (Users::where('id', $id)->update(['name' => $request['name'], 'email' => $request['email']])) {
         return Redirect::to('admin/user/' . $id . '/edit');
     } else {
         return Redirect::back()->withInput()->withErrors('更新失败!');
     }
 }
Example #3
0
 /**
  * Displays individual restaurant information
  * route: /restaurants/{restaurant_id}/{viewer_id?}
  *
  * @param id - restaurant ID
  * @param viewer_id - user ID of the viewer (Optional)
  * @return Response
  */
 public function viewAction($id)
 {
     $viewer_id = Input::get('viewer_id', null);
     $restaurant = Restaurants::find($id);
     $data = array();
     if ($restaurant) {
         $restaurant->view_count++;
         $restaurant->save();
         $restaurant_categories = RestaurantsCategory::getByRestaurantId($id);
         $photos = Photos::getByRestaurantId($id);
         $is_bookmarked = Bookmarks::isBookmarked($viewer_id, $restaurant->id);
         $data[KeyParser::restaurant] = ModelFormatter::restaurantViewFormat($restaurant, $is_bookmarked);
         foreach ($photos as $photo) {
             $data[KeyParser::photos][] = ModelFormatter::photosFormat($photo);
         }
         $data[KeyParser::categories] = Categories::getFormattedRestaurantCategories($restaurant->id);
         Categories::getFormattedRestaurantCategories($restaurant->id);
         $latest_activity = Activities::getLatestRestaurantActivity($id);
         if ($latest_activity) {
             $data[KeyParser::activity] = ModelFormatter::activityRestaurantViewFormat($latest_activity);
             $data[KeyParser::user] = Users::getStatistics($id);
             $data += Activities::getActivityType($latest_activity->type, $latest_activity->type_id);
         }
     }
     $recently_viewed = array();
     if ($viewer_id) {
         $where = array('user_id' => $viewer_id, 'restaurant_id' => $id);
         $rv = LogRecentlyViewed::where($where)->get()->first();
         if ($rv) {
             $rv->date_modified = date('Y-m-d H:i:s');
             $rv->save();
         }
         $rv = new LogRecentlyViewed();
         $rv->addNewLog($viewer_id, $id);
     }
     $json_return[KeyParser::data] = $data;
     return response()->json($json_return);
 }
Example #4
0
 /**
  * Construct the needed Array for Reviews User and Restaurant
  * action: userAction, restaurantAction
  *
  * @param $reviews
  * @return mixed
  */
 public static function reviewsQueries($reviews)
 {
     $reviews_array = array();
     if (!$reviews) {
         return $reviews_array;
     }
     foreach ($reviews as $review) {
         $restaurant = Restaurants::find($review->restaurant_id);
         if (!$restaurant) {
             continue;
         }
         $user = Users::find($review->user_id);
         $photos = Photos::getByType(CONSTANTS::REVIEW, $review->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         if ($user) {
             $reviews_array[] = array(KeyParser::review => ModelFormatter::reviewFormat($review), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         }
         //end of check user
         unset($restaurant);
         unset($user);
         unset($photos);
         unset($photos_array);
     }
     //end foreach
     return $reviews_array;
 }
Example #5
0
 /**
  * Construct the needed Array for Checkins User and Restaurant
  * action:
  *
  * @param $checkins
  * @return mixed
  */
 public static function checkinsQueries($checkins)
 {
     $checkins_array = array();
     if (!$checkins) {
         return $checkins_array;
     }
     foreach ($checkins as $checkin) {
         $restaurant = Restaurants::find($checkin->restaurant_id);
         if (!$restaurant) {
             continue;
         }
         $user = Users::find($checkin->user_id);
         $photos = Photos::getByType(CONSTANTS::CHECKIN, $checkin->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         $checkins_array[] = array(KeyParser::checkin => ModelFormatter::checkinFormat($checkin), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         unset($restaurant);
         unset($user);
         unset($photos);
         unset($photos_array);
     }
     //end foreach
     return $checkins_array;
 }
Example #6
0
 public function index()
 {
     $user = Users::all();
     //dd($user);
     return view('admin.index')->withUser($user);
 }
Example #7
0
 /**
  * @param Request $request
  * @param $id
  * @return Response
  * @throws Exception
  */
 public function editAction(Request $request, $id)
 {
     /* Multipart Procedure
        $data = $request->only('json');
        $data_json = json_decode(file_get_contents($data['json']), true);
        */
     $data_json['CheckIn'] = $request->json()->get('CheckIn');
     if (!isset($data_json['CheckIn']) || !isset($data_json['CheckIn']['message'])) {
         $message = "Format should be: {'CheckIn': 'message': <string>}}";
         return showErrorResponse($message, HTTP_UNPROCESSABLE_ENTITY);
     }
     // check fo valid data
     // Check Ng Words
     $ng_words = NgWord::ngword_filter($data_json['CheckIn']['message']);
     if ($ng_words) {
         $message = "Bad word(s) found: " . implode(',', $ng_words);
         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
     }
     // check of Ng Words
     try {
         // Edit Review Data
         $checkin = new Checkins();
         $edit_checkin = $checkin->editCheckin($id, $data_json['CheckIn']);
         $photos = Photos::getByType(CONSTANTS::CHECKIN, $edit_checkin->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         $restaurant = Restaurants::find($edit_checkin->restaurant_id);
         if (!$restaurant) {
             return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
         }
         $user = Users::find($edit_checkin->user_id);
         $json_return[KeyParser::data] = array(KeyParser::checkin => ModelFormatter::checkinFormat($edit_checkin), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         return response()->json($json_return);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     // end catch
 }
Example #8
0
 /**
  * Update comment
  *
  * @param Request $request
  * @return Response
  */
 public function editCommentAction(Request $request)
 {
     $data = $request->json()->get('Comment');
     if (!isset($data['id']) || !isset($data['text']) || !isset($data['user_id'])) {
         $message = "Format should be: {'Comment': {'id': <int>, 'text': <string>, 'user_id': <int>}}";
         return showErrorResponse($message, HTTP_UNPROCESSABLE_ENTITY);
     }
     // Check Ng Words
     $ng_words = NgWord::ngword_filter($data['text']);
     if ($ng_words) {
         $message = "Bad word(s) found: " . implode(',', $ng_words);
         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
     }
     // check of Ng Words
     try {
         $comment = new Comments();
         $comment = $comment->editComment($data['id'], $data['user_id'], $data['text']);
         $comment = ModelFormatter::commentFormat($comment);
         $user = Users::find($data['user_id']);
         $user = ModelFormatter::userLongFormat($user);
         $json_return[KeyParser::data] = array(KeyParser::comment => $comment, KeyParser::user => $user);
     } catch (\Exception $e) {
         return showErrorResponse('Error Editing Comment');
     }
     return response()->json($json_return);
 }
Example #9
0
 /**
  * get all of the bookmarks of a user
  * /bookmarks/user/{user_id}
  *
  * @param $user_id
  * @return Response
  */
 public function userBookmarkListAction($user_id)
 {
     if (!is_numeric($user_id)) {
         return showErrorResponse('Incorrect User ID format');
     }
     $bookmark_list = Bookmarks::getBookmarkByUserId($user_id);
     $user_data = Users::find($user_id);
     $json_return[KeyParser::data] = array();
     if ($bookmark_list) {
         foreach ($bookmark_list as $bookmark) {
             $restaurant_data = Restaurants::find($bookmark->restaurant_id);
             if ($restaurant_data) {
                 $json_return[KeyParser::data][] = array(KeyParser::bookmark => ModelFormatter::bookmarkFormat($bookmark), KeyParser::user => ModelFormatter::userFormat($user_data), KeyParser::restaurant => ModelFormatter::restaurantBookmarkListViewFormat($restaurant_data), KeyParser::categories => Categories::getFormattedRestaurantCategories($bookmark->restaurant_id));
             }
         }
     }
     $json_return[KeyParser::page] = array(KeyParser::current => $bookmark_list->currentPage(), KeyParser::number => $bookmark_list->lastPage());
     return response()->json($json_return);
 }
Example #10
0
 /**
  * Upload Photo Routine for Restaurant
  * route: photos/upload/restaurant
  *
  * @param Request $request
  * @return Mixed
  */
 public function photoUploadRestaurantAction(Request $request)
 {
     $data = $request->only('json', 'fileField');
     $data_photos = $data['fileField'];
     $data_json = json_decode(file_get_contents($data['json']), true);
     try {
         DB::beginTransaction();
         foreach ($data_json['Photos'] as $data_json_photo) {
             foreach ($data_photos as $key => $data_photo) {
                 $photo_text = "";
                 if (isset($data_json_photo['Photo']['text'])) {
                     $photo_text = $data_json_photo['Photo']['text'];
                     // Check Ng Words
                     $ng_words = NgWord::ngword_filter($photo_text);
                     if ($ng_words) {
                         $message = "Bad word(s) found: " . implode(' ', $ng_words);
                         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
                     }
                     // check of Ng Words
                 }
                 $data_photos[$key]->text = $photo_text;
             }
         }
         $restaurant_id = $data_json['Restaurant']['restaurant_id'];
         $user_id = $data_json['Restaurant']['user_id'];
         // Save and Upload Photo
         $photos_upload = new Photos();
         $success_photo = $photos_upload->saveUploadedPhotos($data_photos, $data_json['Restaurant'], CONSTANTS::RESTAURANT, $restaurant_id);
         $followers = Follow::getFollowerUsersAll($user_id);
         $notification = new Notification();
         //Add Activity
         foreach ($success_photo as $photo) {
             $activity = new Activities();
             $activity->addActivity(CONSTANTS::PHOTO_UPLOAD_RESTAURANT, $photo->id, $user_id, $restaurant_id);
             foreach ($followers as $follower) {
                 $notification->addNotificationNewPhoto($user_id, $follower->follower_user_id, $photo->id, $restaurant_id);
             }
         }
         $photos_array = Photos::convertPhotosToArray($success_photo);
         $restaurant = Restaurants::find($restaurant_id);
         $user = Users::find($user_id);
         $json_return[KeyParser::data] = array(KeyParser::activity => ModelFormatter::activityFormat($activity), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         DB::commit();
         return response()->json($json_return);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     // end catch
 }
Example #11
0
 /**
  * Returns a list of Twitter friends which you have not yet followed
  *
  * @param Request $request
  * @return Response
  * @throws Exception
  */
 public function followTwitterUsersAction(Request $request)
 {
     $json_return[KeyParser::data] = array(KeyParser::users => array(), Keyparser::is_private => CONSTANTS::TWITTER_PUBLIC);
     $user_id = $request->json()->get('User')['user_id'];
     $twitter_id = $request->json()->get('User')['twitter_id'];
     if (!$twitter_id || !$user_id) {
         return showErrorResponse('Failed to access Twitter account');
     }
     $settings = array('oauth_access_token' => Config::get('services.twitter.oauth_access_token'), 'oauth_access_token_secret' => Config::get('services.twitter.oauth_access_token_secret'), 'consumer_key' => Config::get('services.twitter.consumer_key'), 'consumer_secret' => Config::get('services.twitter.consumer_secret'));
     $url = 'https://api.twitter.com/1.1/friends/ids.json';
     $getfield = "?user_id={$twitter_id}";
     $requestMethod = 'GET';
     $twitter = new \TwitterAPIExchange($settings);
     $response = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     $friends = json_decode($response);
     $twitter_friends = array();
     $followed_users = array();
     $friend_count = 0;
     if (isset($friends->error)) {
         $json_return[KeyParser::data][Keyparser::is_private] = CONSTANTS::TWITTER_PRIVATE;
     } else {
         foreach ($friends->ids as $friend_id) {
             $friend_user = Users::getByTwitterId($friend_id);
             if (!$friend_user) {
                 continue;
             }
             $is_followed = Follow::isFollowed($user_id, $friend_user->id);
             $follower_count = Follow::getCountByUserId($friend_user->id, CONSTANTS::FOLLOW_FOLLOWER);
             $review_count = Reviews::getCountByUserId($friend_user->id);
             if (!$is_followed && $friend_user->id != $user_id) {
                 $twitter_friends[$friend_count] = ModelFormatter::userFormat($friend_user);
                 $twitter_friends[$friend_count] += array(KeyParser::follower_count => $follower_count, KeyParser::review_count => $review_count, KeyParser::is_followed_by_viewer => $is_followed);
             } elseif ($is_followed && $friend_user->id != $user_id) {
                 $followed_users[$friend_count] = ModelFormatter::userFormat($friend_user);
                 $followed_users[$friend_count] += array(KeyParser::follower_count => $follower_count, KeyParser::review_count => $review_count, KeyParser::is_followed_by_viewer => $is_followed);
             }
             $friend_count++;
         }
         $twitter_friends = array_merge($twitter_friends, $followed_users);
         $json_return[KeyParser::data][KeyParser::users] = $twitter_friends;
     }
     return response()->json($json_return);
 }
Example #12
0
 /**
  * Get list of users with the most number of activities
  * Prioritize users that are not being followed yet
  *
  * @param $user_id
  * @return Response
  */
 public function viewFeaturedUsersAction($user_id)
 {
     $followed_users = array();
     $featured_users = array();
     $json_return[KeyParser::data] = array();
     $users = Users::getUsersWithMostActivities()->toArray();
     $all_followed_users = Follow::getFollowedUserIds($user_id);
     foreach ($users as $user) {
         $is_followed = in_array($user['id'], $all_followed_users);
         if ($user['id'] != $user_id) {
             if ($is_followed) {
                 $followed_users[] = $user['id'];
             } else {
                 $featured_users[] = $user['id'];
             }
         }
     }
     $featured_users = array_merge($featured_users, $followed_users);
     $featured_users = array_slice($featured_users, 0, 20);
     foreach ($featured_users as $index => $featured_user) {
         $json_return[KeyParser::data][KeyParser::users][$index] = Users::getStatistics($featured_user, $user_id);
     }
     return response()->json($json_return);
 }
Example #13
0
 /**
  * Query the users, restaurant, bookmarks, checkins, reviews
  *
  * @param int activities
  * @return mixed
  */
 public static function activitiesQueries($activities)
 {
     $activities_array = array();
     if ($activities->count()) {
         foreach ($activities as $activity) {
             $data = array();
             $data[KeyParser::activity] = ModelFormatter::activityFormat($activity);
             //GetUserInfo
             $user = Users::find($activity->user_id);
             if ($user) {
                 $data[KeyParser::user] = ModelFormatter::userFormat($user);
             } else {
                 $data[KeyParser::user][KeyParser::error] = "No Information";
             }
             //end check user
             //GetRestaurantInfo
             $restaurant = Restaurants::where('status_verify', CONSTANTS::STATUS_VERIFIED)->find($activity->restaurant_id);
             if ($restaurant) {
                 $data[KeyParser::restaurant] = ModelFormatter::restaurantFormat($restaurant);
             } else {
                 $data[KeyParser::restaurant][KeyParser::error] = "No Information";
             }
             // end check restaurant
             $data += self::getActivityType($activity->type, $activity->type_id);
             $activities_array[] = $data;
             unset($data);
         }
         //end foreach
     }
     //end count
     return $activities_array;
 }
Example #14
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 #15
0
 /**
  * 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);
 }
Example #16
0
 public function sendToAPNS()
 {
     $user_to = Users::find($this->user_id_to);
     $device_id = $user_to->device_id;
     // Build payload
     $aps = array(KeyParser::alert => $this->buildMessage(), KeyParser::sound => CONSTANTS::APNS_SOUND_DEFAULT, KeyParser::badge => $this->getNotificationByUserTo($this->user_id_to, CONSTANTS::NOTIFICATION_STATUS_NEW, true));
     $custom = array(KeyParser::id => $this->id, 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);
     $body = array('aps' => $aps, 'custom' => $custom);
     $payload = json_encode($body);
     $json_size = strlen($payload);
     $pem_file = Config::get('apns.apns_pem_file');
     $host = Config::get('apns.apns_host');
     $passphrase = Config::get('apns.apns_passphrase');
     // Create socket
     $ctx = stream_context_create();
     stream_context_set_option($ctx, 'ssl', 'local_cert', $pem_file);
     stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
     try {
         $fp = stream_socket_client($host, $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
     } catch (\Exception $e) {
         return array(KeyParser::status => CONSTANTS::FAIL, KeyParser::message => CONSTANTS::NOTIFICATION_SERVER_FAILURE, KeyParser::host => $host, KeyParser::pem_file => $pem_file, KeyParser::error => $e->getMessage());
     }
     if (!$fp) {
         return array(KeyParser::status => CONSTANTS::FAIL, KeyParser::message => CONSTANTS::NOTIFICATION_SERVER_FAILURE, KeyParser::host => $host, KeyParser::pem_file => $pem_file, KeyParser::error => CONSTANTS::NOTIFICATION_SERVER_FAILURE);
     }
     // Build send data
     try {
         $send_data = chr(0) . chr(0) . chr(32) . pack('H*', $device_id) . chr(0) . chr($json_size) . $payload;
     } catch (\ErrorException $e) {
         return array(KeyParser::status => CONSTANTS::FAIL, KeyParser::message => CONSTANTS::NOTIFICATION_INVALID_DEVICE_ID);
     }
     // Send
     $result = fwrite($fp, $send_data);
     if ($result !== false) {
         $result = $body;
     }
     fclose($fp);
     return $result;
 }
Example #17
0
 /**
  * Review View
  * route: reviews/view{id}
  *
  * @param $id
  * @optional ?viewer_id
  * @return Response
  */
 public function viewAction($id)
 {
     $json_return = array();
     $review = Reviews::find($id);
     if (!$review) {
         return showErrorResponse('Review not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_REVIEW_MISSING);
     }
     $restaurant = Restaurants::find($review->restaurant_id);
     if (!$restaurant) {
         return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
     }
     $user = Users::find($review->user_id);
     $photos = Photos::getByType(CONSTANTS::REVIEW, $review->id);
     $photos_array = Photos::convertPhotosToArray($photos);
     $comments = Comments::getByType(CONSTANTS::REVIEW, $review->id);
     $comments_array = array();
     if ($comments) {
         foreach ($comments as $comment) {
             $comments_array[] = ModelFormatter::commentFormat($comment);
         }
     }
     $json_return[KeyParser::data] = array(KeyParser::review => ModelFormatter::reviewFormat($review), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array, KeyParser::comments => $comments_array);
     return response()->json($json_return);
 }