/** * Responds with information about updated inserted brand * * @method put * @return json/xml data */ public function put($id) { $results = array(); $brand = Brands::findFirstById($id); if ($brand) { $brandCollection = BrandsCollection::findFirst(array(array('id' => $id))); if ($brandCollection != false) { $brandCollection->id = $brand->id; $brandCollection->companyId = $brand->companyId; $brandCollection->name = $brand->name; $brandCollection->alias = $brand->alias; $brandCollection->logo = $brand->logo; $brandCollection->link = $brand->link; $brandCollection->description = $brand->description; $brandCollection->language = $brand->language; $brandCollection->revenueValue = $brand->revenueValue; $brandCollection->active = $brand->active; $brandCollection->created = $brand->created; $brandCollection->modified = $brand->modified; $brandCollection->createdBy = $brand->createdBy; $brandCollection->modifiedBy = $brand->modifiedBy; $brandCollection->save(); $results['id'] = $brand->id; } } return $results; }
/** * 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 {put} /brands/upload/:id PUT /brands/upload/:id * @apiExample Example usage: * curl --upload-file /home/moneymax/brands/bpi-family.png "http://apibeta.compargo.com/v1/brands/upload/0d6b45a6-3eea-11e4-9a7a-90a27a7c008a/?language=en&countryCode=ph * -H "X-COMPARE-REST-API-KEY: 1234567890" * * @apiDescription Upload a Brand Image * @apiName Delete * @apiGroup Brands * * @apiHeader {String} X-COMPARE-REST-API-KEY Brands unique access-key. * * @apiParam {String} language Mandatory Language. * @apiParam {String} countryCode Mandatory Country Code. * @apiParam {String} id Mandatory Company Unique ID. * @apiParam {String} file Mandatory File. * * @apiSuccess {String} id The ID of Brand. * * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * { * "id": "0d6b45a6-3eea-11e4-9a7a-90a27a7c008a" * } * * @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 BrandNotFound The id of the Brand was not found. * * @apiErrorExample Error-Response: * HTTP/1.1 404 Not Found * { * "error": "BrandNotFound" * } * * @apiError RouteNotFound That route was not found on the server. * * @apiErrorExample Error-Response: * HTTP/1.1 404 * { * "error": "RouteNotFound" * } */ public function upload($id) { $parameters = $results = array(); $requestBody = file_get_contents("php://input"); $request = $this->di->get('request'); $language = $request->get()['language']; if (!empty($requestBody)) { $brand = Brands::findFirstById($id); if ($brand) { $width = isset($request->get()['width']) ? $request->get()['width'] : ''; $height = isset($request->get()['height']) ? $request->get()['height'] : ''; $quality = isset($request->get()['quality']) ? $request->get()['quality'] : 85; $parameters = array('prefix' => $id . '_', 'basename' => $brand->name, 'uploadpath' => $language . '/brands/', 'max_width' => $width, 'max_height' => $height, 'quality' => $quality); $image = new ImageUpload(); if ($filename = $image->save($requestBody, $parameters)) { $brand->logo = $filename; if ($brand->save()) { $brandCollection = BrandsCollection::findFirst(array('condition' => array('id' => $id))); $brandCollection->logo = $filename; if ($brandCollection->save()) { $results[] = $brandCollection; } } } } } 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; }