コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
ファイル: LikeController.php プロジェクト: jigen7/laravel5
 /**
  * Delete like on review, checkin or photo
  *
  * @param $request
  * @return mixed
  */
 public function deleteAction(Request $request)
 {
     $type = $request->type;
     $type_id = $request->type_id;
     $user_id = $request->user_id;
     $error_msg = checkTypeId($type, $type_id);
     if ($error_msg) {
         return $error_msg;
     }
     $is_liked = Like::isLiked($user_id, $type, $type_id);
     if ($is_liked) {
         try {
             $like = new Like();
             $like->deleteLike($type, $type_id, $user_id);
         } catch (\Exception $e) {
             return showErrorResponse($e->getMessage());
         }
     }
     $json_return[KeyParser::data] = array(KeyParser::type => $type, KeyParser::type_id => $type_id, KeyParser::user_id => $user_id, KeyParser::like_count => Like::getCount($type, $type_id));
     return response()->json($json_return);
 }