/** * Responds with information about updated inserted company * * @method put * @return json/xml data */ public function put($id) { $company = Companies::findFirstById($id); if ($company) { $companyCollection = CompaniesCollection::findFirst(array(array('id' => $id))); if ($companyCollection != false) { $companyCollection->id = $company->id; $companyCollection->name = $company->name; $companyCollection->alias = $company->alias; $companyCollection->logo = $company->logo; $companyCollection->link = $company->link; $companyCollection->description = $company->description; $companyCollection->language = $company->language; $companyCollection->revenueValue = $company->revenueValue; $companyCollection->status = $company->status; $companyCollection->active = $company->active; $companyCollection->created = $company->created; $companyCollection->modified = $company->modified; $companyCollection->save(); $results['id'] = $company->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} /companies/upload/:id PUT /companies/upload/:id * @apiExample Example usage: * curl --upload-file /home/moneymax/companies/bpi.png "http://apibeta.compargo.com/v1/companies/upload/0c00ae86-3eea-11e4-9a7a-90a27a7c008a/?language=en&countryCode=ph * -H "X-COMPARE-REST-API-KEY: 1234567890" * * @apiDescription Upload a Company Image * @apiName Delete * @apiGroup Companies * * @apiHeader {String} X-COMPARE-REST-API-KEY Companies 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 Company. * * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * { * "id": "96b3d052-3716-11e4-b18a-fe7344fb1ea4" * } * * @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 CompanyNotFound The id of the Company was not found. * * @apiErrorExample Error-Response: * HTTP/1.1 404 Not Found * { * "error": "CompanyNotFound" * } * * @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)) { $company = Companies::findFirstById($id); if ($company) { $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' => $company->name, 'uploadpath' => $language . '/companies/', 'max_width' => $width, 'max_height' => $height, 'quality' => $quality); $image = new ImageUpload(); if ($filename = $image->save($requestBody, $parameters)) { $company->logo = $filename; if ($company->save()) { $companyCollection = CompaniesCollection::findFirst(array('condition' => array('id' => $id))); $companyCollection->logo = $filename; if ($companyCollection->save()) { $results[] = $companyCollection; } } } } } 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; }