/** * Responds with information about updated vertical * * @method put * @return json/xml data */ public function put($id) { $results = array(); $vertical = Verticals::findFirstById($id); if ($vertical != false) { $verticalsCollection = VerticalsCollection::findFirst(array(array('id' => $id))); if ($verticalsCollection != false) { $verticalsCollection->id = $vertical->id; $verticalsCollection->name = $vertical->name; $verticalsCollection->description = $vertical->description; $verticalsCollection->status = $vertical->status; $verticalsCollection->active = $vertical->active; $verticalsCollection->created = $vertical->created; $verticalsCollection->modified = $vertical->modified; $verticalsCollection->createdBy = $vertical->createdBy; $verticalsCollection->modifiedBy = $vertical->modifiedBy; $verticalsCollection->save(); $results['id'] = $vertical->id; } } return $results; }
/** * @api {put} /verticals/:id PUT /verticals/:id * @apiExample Example usage: * curl -i -X PUT "http://apibeta.compargo.com/v1/verticals/07f44e24-1d43-11e4-b32d-eff91066cccf/?countryCode=ph&language=en" * -H "X-COMPARE-REST-API-KEY: 1234567890" * -d "name=Insurance&description=Insurance&status=1" * * @apiDescription Update a Vertical * @apiName Put * @apiGroup Verticals * * @apiHeader {String} X-COMPARE-REST-API-KEY Vertical unique access-key. * * @apiParam {String} language Mandatory Language. * @apiParam {String} countryCode Mandatory Country Code. * @apiParam {String} id Mandatory Vertical Unique ID. * @apiParam {String} name Mandatory Name of the Vertical. * @apiParam {String} [description] Optional Description of the Vertical. * @apiParam {String} [status] Optional Status of the Vertical. * @apiParam {String} [createdBy] Optional ID of the User who created the Vertical. * @apiParam {String} [modifiedBy] Optional ID of the User who modified the Vertical. * * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * { * "id": "07f44e24-1d43-11e4-b32d-eff91066cccf" * } * * @apiError BadInputParameter The request cannot be fulfilled due to bad syntax. * * @apiErrorExample Error-Response: * HTTP/1.1 400 * { * "error": "BadInputParameter" * } * * @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 VerticalNotFound The id of the Vertical was not found. * * @apiErrorExample Error-Response: * HTTP/1.1 404 Not Found * { * "error": "VerticalNotFound" * } */ public function put($id) { $results = $params = array(); $request = $this->di->get('request'); $data = $request->getPut(); if (!empty($data)) { $vertical = Verticals::findFirstById($id); if (!$vertical) { throw new HTTPException("Not found", 404, array('dev' => 'Vertical does not exist', 'internalCode' => 'P1000', 'more' => '')); } else { $data['name'] = isset($data['name']) ? $data['name'] : $vertical->name; $data['description'] = isset($data['description']) ? $data['description'] : $vertical->description; $data['status'] = isset($data['status']) ? $data['status'] : $vertical->status; if (isset($data['status'])) { $data['active'] = $data['status'] != Verticals::ACTIVE ? 0 : 1; } $data['createdBy'] = isset($data['createdBy']) ? $data['createdBy'] : $vertical->createdBy; $data['modifiedBy'] = isset($data['modifiedBy']) ? $data['modifiedBy'] : $vertical->modifiedBy; if ($vertical->save($data)) { $results['id'] = $vertical->id; } else { throw new HTTPException("Request unable to be followed due to semantic errors", 422, array('dev' => $vertical->getMessages(), 'internalCode' => 'P1000', 'more' => '')); } } } else { throw new HTTPException("The request cannot be fulfilled due to bad syntax.", 400, array('dev' => 'A required field is missing.', 'internalCode' => 'P1000', 'more' => '')); } return $results; }