public function findAction() { $request = new Request(); $request->initRequest(); $post = $request->getPost(); $roadMapper = new RoadMapper(); $roads = $roadMapper->getByStartFinish($post['departure_point'], $post['destination_point'], "opened"); $userMapper = new UserMapper(); $carMapper = new CarMapper(); $result = array(); if ($roads) { foreach ($roads as $road) { $user = $userMapper->getUserByEmail($road->driverid); $car = $carMapper->getByAutoId($road->autoid); $roadMapper->clear(); $getPoints = $roadMapper->getRoutPointsByRoad($road->id); $routPoints = array(); foreach ($getPoints as $point) { $routPoints[$point->pointqueue] = $point->point; } $result[] = array('startdate' => $road->startdate, 'start' => $road->start, 'start_adress' => $road->start_adress, 'finish' => $road->finish, 'finish_adress' => $road->finish_adress, 'freeseats' => $road->freeseats, 'price' => $road->price, 'terms' => $road->terms, 'rout_points' => $routPoints, 'username' => $user->username, 'surname' => $user->surname, 'rate' => $user->rate, 'photo' => $user->photo, 'age' => $user->getAge(), 'car_brand' => $car->brand, 'car_model' => $car->model); $userMapper->clear(); $carMapper->clear(); $roadMapper->clear(); } } echo json_encode($result); }
public function saveAction() { $message = ErMessenger::getInstance(); $userEmail = ErSession::getFromSession('user'); $request = new Request(); $request->initRequest(); $post = $request->getPost(); if (isset($post)) { $autoId = $this->clearStr($post['regnumber']); $carMapper = new CarMapper(); $carExist = $carMapper->getByAutoId($autoId); $car = $carExist ? $carExist : new Car(); $carMapper->clear(); $car->brand = $this->clearStr($post['brand']); $car->model = $this->clearStr($post['model']); $car->color = $this->clearStr($post['color']); $car->seats = $this->clearStr($post['seats']); $car->fuelrate = $this->clearStr($post['fuelrate']); if (!$carExist) { $car->regnumber = $this->clearStr($post['regnumber']); $car->userid = $this->clearStr($userEmail); $car->photo = ""; if ($carMapper->insertNewCar($car)) { $message->setSucceedMessage('202', 'user/private'); } else { $message->setErrMessage('100', 'user/private'); } } else { if ($carMapper->updateCar($car)) { $message->setSucceedMessage('202', 'user/private'); } else { $message->setErrMessage('100', 'user/private'); } } echo json_encode($this->fetchUserCars($userEmail)); } }
protected function fetchUserData($userEmail) { $result = array(); $userMapper = new UserMapper(); $carMapper = new CarMapper(); $routeMapper = new RoadMapper(); $currentUser = $userMapper->getUserByEmail($userEmail); $userCars = $carMapper->getByUser($userEmail); $userRoutes = $routeMapper->getByUser($userEmail); $routes = array(); $carMapper->clear(); $i = 0; foreach ($userRoutes as $route) { $routes[$i] = get_object_vars($route); $_car = $carMapper->getByAutoId($route->autoid); $routes[$i]['car'] = get_object_vars($_car); $carMapper->clear(); ++$i; } $cars = array(); foreach ($userCars as $car) { $cars[] = get_object_vars($car); } $result['user'] = get_object_vars($currentUser); $result['user']['age'] = $currentUser->getAge(); $result['cars'] = $cars; $result['routes'] = $routes; return $result; }