Example #1
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 #2
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 #3
0
 /**
  * Returns either review, checkin, or bookmark activity based on $type parameter.
  *
  * @param $type - activity type. Either 'checkin', 'review', or 'bookmark'
  * @param $type_id - ID for checkin/review/bookmark activity
  * @return mixed
  */
 public static function getActivityType($type, $type_id)
 {
     $arr = array();
     switch ($type) {
         case CONSTANTS::CHECKIN:
             $check_in = CheckIns::find($type_id);
             if ($check_in) {
                 $arr[KeyParser::checkin] = ModelFormatter::checkinFormat($check_in);
             } else {
                 $arr[KeyParser::checkin] = array();
             }
             $photos = Photos::getByType(CONSTANTS::CHECKIN, $type_id);
             $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos);
             break;
         case CONSTANTS::REVIEW:
             $review = Reviews::find($type_id);
             if ($review) {
                 $arr[KeyParser::review] = ModelFormatter::reviewFormat($review);
             } else {
                 $arr[KeyParser::review] = array();
             }
             $photos = Photos::getByType(CONSTANTS::REVIEW, $type_id);
             $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos);
             break;
         case CONSTANTS::PHOTO_UPLOAD_RESTAURANT:
             $photos = Photos::where('id', $type_id)->get();
             $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos);
             break;
     }
     unset($photos_arr);
     return $arr;
 }