/** * executeRequest() * * Execute the received request. */ private function executeRequest() { switch ($this->requestType) { case self::GET_USER_REQUEST: case self::GET_VEHICLES_REQUEST: try { $user = Doctrine_Core::getTable('sfGuardUser')->createQuery('u')->where('u.api_key = ?', $this->requestApiKey)->andwhere('u.username = ?', $this->requestUsername)->execute(); if (sizeof($user) == 1) { $this->responseUser = $user[0]; $this->responseVehicles = Doctrine_Core::getTable('Vehicle')->createQuery('v')->where('v.user_id = ?', $user[0]->getId())->execute(); } else { $this->setError(211); } } catch (Exception $e) { $this->setError(230); } break; case self::SET_CHARGE_REQUEST: try { $user = Doctrine_Core::getTable('sfGuardUser')->createQuery('u')->where('u.api_key = ?', $this->requestApiKey)->andwhere('u.username = ?', $this->requestUsername)->execute(); if (sizeof($user) == 1) { $this->responseUser = $user[0]; $this->responseVehicles = Doctrine_Core::getTable('Vehicle')->createQuery('v')->where('v.user_id = ?', $user[0]->getId())->andwhere('v.id = ?', $this->requestVehicle)->execute(); if (sizeof($this->responseVehicles) == 1) { $charge = new Charge(); $charge->setVehicleId($this->responseVehicles[0]->getId()); $charge->setUserId($this->responseUser->getId()); $charge->setCategoryId($this->requestCategory); $charge->setDate($this->requestDate); $charge->setKilometers($this->requestKilometers); $charge->setAmount($this->requestAmount); $charge->setComment($this->requestComment); $charge->setQuantity($this->requestQuantity); $charge->save(); } else { $this->setError(220); } } else { $this->setError(211); } } catch (Exception $e) { $this->setError(230); } break; default: $this->setError(500); break; } }