/** * Responds with information about updated inserted company option * * @method put * @return json/xml data */ public function put($id) { $results = array(); $companiesOption = CompaniesOptions::findFirstById($id); if ($companiesOption) { $companiesOptionCollection = CompaniesOptionsCollection::findFirst(array(array('id' => $id))); if ($companiesOptionCollection != false) { $companiesOptionCollection->id = $companiesOption->id; $companiesOptionCollection->modelId = $companiesOption->modelId; $companiesOptionCollection->category = $companiesOption->category; $companiesOptionCollection->name = $companiesOption->name; $companiesOptionCollection->value = $companiesOption->value; $companiesOptionCollection->label = $companiesOption->label; $companiesOptionCollection->status = $companiesOption->status; $companiesOptionCollection->active = $companiesOption->active; $companiesOptionCollection->editable = $companiesOption->editable; $companiesOptionCollection->visibility = $companiesOption->visibility; $companiesOptionCollection->created = $companiesOption->created; $companiesOptionCollection->modified = $companiesOption->modified; $companiesOptionCollection->createdBy = $companiesOption->createdBy; $companiesOptionCollection->modifiedBy = $companiesOption->modifiedBy; $companiesOptionCollection->save(); $success = $companiesOptionCollection->save(); if ($success) { if ('company' == $companiesOption->category && 1 == $companiesOption->status) { $collection = CompaniesCollection::findFirst(array(array('id' => $companiesOption->modelId))); } else { if ('brand' == $companiesOption->category && 1 == $companiesOption->status) { $collection = BrandsCollection::findFirst(array(array('id' => $companiesOption->modelId))); } } if ($collection) { $name = $companiesOption->name; $collection->{$name} = $companiesOption->value; $collection->save(); $results['id'] = $companiesOption->id; } } } } return $results; }
/** * @api {post} /companies_options/:id POST /companies_options/:id * @apiExample Example usage: * curl -H "X-COMPARE-REST-API-KEY: 1234567890" * -i -X POST "http://apibeta.compargo.com/v1/companies_options/05a5ec26-372a-11e4-b18a-fe7344fb1ea4/?countryCode=ph&language=en" * * @apiDescription Read data of a Companies Options * @apiName SearchOne * @apiGroup Companies Options * * @apiHeader {String} X-COMPARE-REST-API-KEY Companies Options unique access-key. * * @apiParam {String} language Mandatory Language. * @apiParam {String} countryCode Mandatory Country Code. * @apiParam {String} id Mandatory Companies Options unique ID. * * @apiSuccess {String} id ID of the Companies Option. * @apiSuccess {String} modelId Brand ID/Company ID of the Companies Option. * @apiSuccess {String} category Brand/Company Category of the Companies Option. * @apiSuccess {String} name Name of the Companies Option. * @apiSuccess {String} value Value of the Companies Option. * @apiSuccess {String} label Label of the Companies Option. * @apiSuccess {String} editable Editable Flag of the Companies Option. * @apiSuccess {String} visibility Visibility Flag of the Companies Option. * @apiSuccess {Number} status Status Flag of the Companies Option. * @apiSuccess {Number} active Active Flag of the Companies Option. * @apiSuccess {Date} created Creation date of the Companies Option. * @apiSuccess {Date} modified Modification date of the Companies Option. * @apiSuccess {String} createdBy ID of the User who created the Companies Option. * @apiSuccess {String} modifiedBy ID of the User who modified the Companies Option. * * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * { * "id": "8a048714-2791-11e4-bd33-17609cecca2f", * "modelId": "10f0c896-2134-11e4-bb06-0a68ec684316", * "category": "company", * "name": "fax", * "value": "123456789", * "label": "", * "editable": "0", * "visibility": "0", * "status": "1" * } * * @apiError CompaniesOptionNotFound The id of the Companies Option was not found. * * @apiErrorExample Error-Response: * HTTP/1.1 404 Not Found * { * "error": "CompaniesOptionNotFound" * } * * @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) { $companiesOptions = new CompaniesOptionsCollection($this->di); $results = $this->respond($companiesOptions, $id); } else { $results = CompaniesOptionsCollection::findFirstById($id); } if (!$results) { throw new HTTPException("Not found", 404, array('dev' => 'Companies option does not exist', 'internalCode' => 'P1000', 'more' => '')); } return $results; }