/** * Responds with information about updated inserted country * * @method post * @return json/xml data */ public function put($id) { $results = array(); $country = Country::findFirstById($id); if ($country) { $countryCollection = CountryCollection::findFirst(array(array('id' => $id))); if ($countryCollection != false) { $countryCollection->id = $country->id; $countryCollection->name = $country->name; $countryCollection->description = $country->description; $countryCollection->status = $country->status; $countryCollection->active = $country->active; $countryCollection->created = $country->created; $countryCollection->modified = $country->modified; $countryCollection->createdBy = $country->createdBy; $countryCollection->modifiedBy = $country->modifiedBy; $countryCollection->save(); $results['id'] = $country->id; } } return $results; }
/** * Responds with information about updated inserted company * * @method post * @return json/xml data */ public function put($id) { $results = array(); $countryOption = CountryOptions::findFirstById($id); if ($countryOption) { $countryOptionsCollection = CountryOptionsCollection::findFirst(array(array('id' => $id))); if ($countryOptionsCollection != false) { $countryOptionCollection->id = $countryOption->id; $countryOptionCollection->countryId = $countryOption->countryId; $countryOptionCollection->name = $countryOption->name; $countryOptionCollection->value = $countryOption->value; $countryOptionCollection->label = $countryOption->label; $countryOptionCollection->status = $countryOption->status; $countryOptionCollection->active = $countryOption->active; $countryOptionCollection->editable = $countryOption->editable; $countryOptionCollection->visibility = $countryOption->active; $countryOptionCollection->created = $countryOption->created; $countryOptionCollection->modified = $countryOption->modified; $countryOptionCollection->createdBy = $countryOption->createdBy; $countryOptionCollection->modifiedBy = $countryOption->modifiedBy; $success = $countryOptionsCollection->save(); if ($success) { if (1 == $countryOption->status) { $country = Country::findFirst(array(array('id' => $countryOption->countryId))); if ($country) { $name = $countryOption->name; $country->{$name} = $countryOption->value; $country->save(); $results['id'] = $countryOption->id; } } } } } return $results; }
/** * @api {get} /country/search/:id GET /country/search/:id * @apiExample Example usage: * curl -H "X-COMPARE-REST-API-KEY: 1234567890" * -i "http://apibeta.compargo.com/v1/country/search/4de2ec7a-22b5-11e4-bd33-17609cecca2f/?countryCode=ph&language=en" * * @apiDescription Read data of a Country * @apiName SearchOne * @apiGroup Country * * @apiHeader {String} X-COMPARE-REST-API-KEY Country unique access-key. * * @apiParam {String} language Mandatory Language. * @apiParam {String} countryCode Mandatory Country Code. * @apiParam {String} id Mandatory Country unique ID. * * @apiSuccess {String} id ID of the Country. * @apiSuccess {String} name Name of the Country. * @apiSuccess {String} alias Alias of the Country. * @apiSuccess {String} description Description of the Country. * @apiSuccess {Number} status Status of the Country. * @apiSuccess {Number} active Flag of the Country. * @apiSuccess {Date} created Creation date of the Country. * @apiSuccess {Date} modified Modification date of the Country. * @apiSuccess {String} createdBy ID of the User who created the Country. * @apiSuccess {String} modifiedBy ID of the User who modified the Country. * * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * { * "id": "4de2ec7a-22b5-11e4-bd33-17609cecca2f", * "name": "Philippines", * "description": "", * "status": "1", * "active": "1", * "created": "2014-08-13 08:44:42", * "modified": "0000-00-00 00:00:00", * "createdBy": "a8838d12-1dcc-11e4-b32d-eff91066cccf", * "modifiedBy": "a8838d12-1dcc-11e4-b32d-eff91066cccf" * } * * @apiError CountryNotFound The id of the Country was not found. * * @apiErrorExample Error-Response: * HTTP/1.1 404 Not Found * { * "error": "CountryNotFound" * } * * @apiError InvalidAccessToken The access token is invalid. * * @apiErrorExample Error-Response: * HTTP/1.1 401 Unauthorized * { * "error": "InvalidAccessToken" * } * * @apiError MissingAuthenticationCredentials The authentication credentials are missing. * * @apiErrorExample Error-Response: * HTTP/1.1 401 Unauthorized * { * "error": "MissingAuthenticationCredentials" * } * * @apiError RouteNotFound That route was not found on the server. * * @apiErrorExample Error-Response: * HTTP/1.1 404 * { * "error": "RouteNotFound" * } * */ public function searchOne($id) { $results = array(); $request = $this->di->get('requestBody'); $parameters = $request->get(); if (count($parameters) > 1) { $country = new CountryCollection($this->di); $results = $this->respond($country, $id); } else { $results = CountryCollection::find(array(array("id" => $id))); } if (!$results) { throw new HTTPException("Not found", 404, array('dev' => 'Country does not exist', 'internalCode' => 'P1000', 'more' => '')); } return $results; }