public static function serializeRoute($route) { if (!empty($route)) { $points = $route->points; $origins = []; $destinations = []; foreach ($points as $point) { if ($point->type === 'start') { $origins[] = $point; } else { $destinations[] = $point; } } return ['id' => $route->id, 'ride_id' => $route->ride_id, 'user_id' => $route->user_id, 'state' => $route->state, 'direction' => json_decode($route->direction), 'origins' => array_map(function ($x) { return DbUtil::serializeRoutePoint($x); }, $origins), 'destinations' => array_map(function ($x) { return DbUtil::serializeRoutePoint($x); }, $destinations), 'share_details' => ['arrival_time' => $route->endTime, 'notes' => $route->note]]; } else { return []; } }