Esempio n. 1
0
 /**
  * Responds with messages about models
  *
  * @method validation
  * @param  array $parameters
  * @param  array $jsonSchema
  * @return boolean
  */
 public function validateProperty($fields = NULL, $jsonSchema = NULL)
 {
     $valid = array();
     $retVal = "";
     $output = readJsonFromFile($jsonSchema, $this);
     if (!empty($output)) {
         if (substr(get_class($this), -7) == 'Options') {
             $properties = $output['properties']['options'];
         } else {
             $properties = $output['properties'];
         }
         foreach ($fields as $fieldKey => $fieldValue) {
             if (array_key_exists($fieldKey, $properties)) {
                 $retVal = $this->getValidators($fieldValue, $properties[$fieldKey]);
                 if ($retVal !== '') {
                     $valid[] = $this->getValidators($fieldValue, $properties[$fieldKey]);
                 }
             }
         }
     }
     return $valid;
 }
 /**
  * @api {post} /products/import/ POST /products/import/
  * @apiExample Example usage:
  * curl -i -X POST "http://apibeta.compargo.com/v1/products/import/?language=en&countryCode=ph
  *      -H "X-COMPARE-REST-API-KEY: 1234567890"
  *      -d "channelId=a1d14206-1ea9-11e4-b32d-eff91066cccf&
  *          data=[{"areaName": "NCR Luzon, Visayas and Mindanao",
  *            	   "brandName": "Bank of Commerce",
  *            	   "companyName": "Bank of Commerce",
  *            	   "productName": "Visa Classic",
  *            	   "productImage": "bank-of-commerce-visa-classic.jpg",
  *            	   "linkInformation": "http://www.bankcom.com.ph/percc.php#vc",
  *            	   "linkApplication": "http://www.bankcom.com.ph/img/ccaf.pdf",
  *            	   "featured": 0,
  *            	   "hasApplyButton": 0,
  *            	   "overlayOrClickthrough": 0,
  *            	   "phoneNumber": 0,
  *            	   "status": 1,
  *            	   "providerCard": 1,
  *            	   "premiumCard": 0,
  *            	   "octopusCard": 0,
  *            	   "islamicCard": 0,
  *            	   "businessCard": 0,
  *            	   "studentCard": 0,
  *            	   "travelCard": 0,
  *            	   "shoppingCard": 0,
  *            	   "specialtyCard": 0,
  *            	   "onlineShoppingCard": 0,
  *            	   "coBranded": 0,
  *            	   "greatFor1": "Get a separate credit limit for your local and foreign transactions",
  *            	   "greatFor2": "Get up to 30% of your credit limit as cash advance",
  *            	   "greatFor3": "Purchase new appliances, gadgets or other high-ticket items by installment",
  *            	   "bewareThat1": 0,
  *            	   "bewareThat2": 0,
  *            	   "bewareThat3": 0,
  *            	   "promoPicture": 0,
  *            	   "promoTitle": 0,
  *            	   "promoApplyPicture": 0,
  *            	   "promoApplyContent": 0,
  *            	   "ribbonBest": 0,
  *            	   "rewardConversion": "P50 spent = 1 point",
  *            	   "rewardConversionCondition": "Only principal cardholders can redeem reward points",
  *            	   "rewardMultiplier": "No points multiplier",
  *            	   "rewardMultiplierCondition": 0,
  *            	   "rewardSpendingShopping": "SM P500 Gift Card (3,711 points)",
  *            	   "rewardSpendingEntertainment": "SM Cinema Tickets for Two (3,149 points)",
  *            	   "rewardSpendingDining": 0,
  *            	   "rewardSpendingOther": 0,
  *            	   "earningPointsOctopus": 0,
  *            	   "earningPointsAutomaticTransaction": 0,
  *            	   "earningPointsOnlineBillPayments": 0,
  *            	   "earningPointsOnlineShopping": 0,
  *            	   "earningPointsInstallment": 0,
  *            	   "cashbackDining": 0,
  *            	   "cashbackDiningCondition": 0,
  *            	   "cashbackShopping": 0,
  *            	   "cashbackShoppingCondition": 0,
  *            	   "cashbackGroceries": 0,
  *            	   "cashbackGroceriesCondition": 0,
  *            	   "cashbackEntertainment": 0,
  *            	   "cashbackEntertainmentCondition": 0,
  *            	   "cashbackPetrol": 0,
  *            	   "cashbackPetrolCondition": 0,
  *            	   "cashbackLocalRetail": 0,
  *            	   "cashbackLocalRetailCondition": 0,
  *            	   "cashbackOverseasSpending": 0,
  *            	   "cashbackOverseasCondition": 0,
  *            	   "cashbackGeneral": 0,
  *            	   "cashbackGeneralCondition": 0,
  *            	   "cashbackOther": 0,
  *            	   "cashbackOtherCondition": 0,
  *            	   "cashbackMetaCondition": 0,
  *            	   "cbeLocalRetails": 0,
  *            	   "cbeLocalRetailsCondition": 0,
  *            	   "cbeLocalDining": 0,
  *            	   "cbeLocalDiningCondition": 0,
  *            	   "cbeOverseasTransaction": 0,
  *            	   "cbeOverseasTransactionCondition": 0,
  *            	   "cbeOnlineShopping": 0,
  *            	   "cbeOnlineShoppingCondition": 0,
  *            	   "cbeOnlineBillPayment": 0,
  *            	   "cbeOnlineBillPaymentCondition": 0,
  *            	   "cbeOctopusAavs": 0,
  *            	   "cbeOctopusAavsCondition": 0,
  *            	   "cbeAutomaticTransaction": 0,
  *            	   "cbeAutomaticTransactionCondition": 0,
  *            	   "cbeInstalment": 0,
  *            	   "cbeInstalmentConditi": 0,
  *            	   "cbeSpecialCondition": 0,
  *            	   "cbsAllNewTransactions": 0,
  *            	   "cbsCashCoupons": 0,
  *            	   "cbsAutopusAavs": 0,
  *            	   "cbsPetrol": 0,
  *            	   "cbsDining": 0,
  *            	   "cbsShopping": 0,
  *            	   "cbsEntertainment": 0,
  *            	   "cbsTravel": 0,
  *            	   "cbsSpecialCondition": 0,
  *            	   "discountsDining": 0,
  *            	   "discountsDiningCondition": 0,
  *            	   "discountsShopping": 0,
  *            	   "discountsShoppingCondition": 0,
  *            	   "discountsGroceries": 0,
  *            	   "discountsGroceriesCondition": 0,
  *            	   "discountsEntertainment": 0,
  *            	   "discountsEntertainmentCondition": 0,
  *            	   "discountsPetrol": 0,
  *            	   "discountsPetrolCondition": 0,
  *            	   "discountsOther": 0,
  *            	   "discountsOtherCondition": 0,
  *            	   "discountsMetaCondition": 0,
  *            	   "milesConversionLocal": 0,
  *            	   "milesConversionConditionLocal": 0,
  *            	   "milesConversionOverseas": 0,
  *            	   "milesConversionConditionOverseas": 0,
  *            	   "milesPogram": 0,
  *            	   "insurance": 0,
  *            	   "airportLounge": 0,
  *            	   "travelOther": 0,
  *            	   "fraudProtection": 0,
  *            	   "installmentPlan": 0,
  *            	   "personalAssistant": 0,
  *            	   "parking": 0,
  *            	   "creditLimit": 0,
  *            	   "purchaseInterest": 3.5,
  *            	   "purchaseApr": 0,
  *            	   "cashAdvanceInterest": 0,
  *            	   "cashAdvanceApr": 0,
  *            	   "interestFreePeriod": 21,
  *            	   "delinquencyRetailPurchaseApr": 0,
  *            	   "delinquencyCashAdvanceApr": 0,
  *            	   "annualFee": 1500,
  *            	   "annualFeePromo": 0,
  *            	   "annualFeeWaiver": "Request for a reversal by calling Customer Care and spend P5,000 within the specified period",
  *            	   "foreignTransactionFee": "2% of the converted amount",
  *            	   "annualFeeSupplementary": "P750",
  *            	   "annualFeeSupplementaryCondition": 0,
  *            	   "cashAdvanceFee": "5% of the amount withdrawn ",
  *            	   "cashAdvanceFee2": 0,
  *            	   "cardReplacementFee": "P300",
  *            	   "annualFeeAfterFirst": 1500,
  *            	   "partlyWaivedCondition": 0,
  *            	   "minimumRepayment": "5% of the amount due",
  *            	   "minimumRepayment2": "P500, whichever is higher",
  *            	   "latePayment": "2% of the overdue amount",
  *            	   "latePayment2": 0,
  *            	   "creditOverLimit": 0,
  *            	   "balanceTransferLowest": 0.88,
  *            	   "balanceTransferMonth": 18,
  *            	   "balanceTransferLongest": 0,
  *            	   "balanceTransferHighlight": 0,
  *            	   "balanceTransferAware": 0,
  *            	   "monthlyIncomeLocals": 10000,
  *            	   "monthlyIncomeForeigners": 0,
  *            	   "minimumEmploymentSalaried": 0,
  *            	   "minimumEmploymentSelfEmployed": 0,
  *            	   "minimumAge": 21,
  *            	   "minimumAgeSupplementary": 18,
  *            	   "existingCardHolder": 1,
  *            	   "nationality": 1,
  *            	   "residence": 0,
  *            	   "other1": 0,
  *            	   "other2": 0,
  *            	   "minimumAnnualIncome": 10000,
  *            	   "maxAge": 65,
  *            	   "language": "en"
  *               }]"
  * 
  *      
  * @apiDescription Bulk import of Products
  * @apiName        Import
  * @apiGroup       Products
  *
  * @apiHeader  {String} X-COMPARE-REST-API-KEY   Products unique access-key.
  *
  * @apiParam   {String} language                 Mandatory Language.
  * @apiParam   {String} countryCode              Mandatory Country Code.
  * @apiParam   {String} id                       Mandatory Product Unique ID.
  * @apiParam   {String} channelId                Mandatory ChannelId of the Product.
  * @apiParam   {String} date                     Mandatory Data of the Product.
  *
  * @apiSuccess {String} id                       The ID of Product.
  *
  * @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 ProductNotFound The id of the Product was not found.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 404 Not Found
  *     {
  *       "error": "ProductNotFound"
  *     }
  *     
  * @apiError RouteNotFound That route was not found on the server.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 404 
  *     {
  *       "error": "RouteNotFound"
  *     }    
  */
 public function bulkImport()
 {
     $results = array();
     $request = $this->di->get('request');
     $data = $request->getPost();
     $processCompany = $processBrand = $processChannel = $processArea = 1;
     if (!empty($data)) {
         $product = new Products();
         $productId = $product->id;
         $metaData = new Memory();
         $columns = $metaData->getColumnMap($product);
         $channelId = isset($data['channelId']) ? $data['channelId'] : '';
         $upload = isset($data['data']) ? $data['data'] : '';
         $channel = Channels::findFirstById($channelId);
         if (!$channel) {
             throw new HTTPException("Not found", 404, array('dev' => 'The requested channel does not exist.', 'internalCode' => 'P1000', 'more' => ''));
         }
         if (isJson($upload) && !empty($channelId)) {
             $productData = $brandData = $areaData = $companyData = array();
             $companyParams = $brandParams = $channelParams = $productParams = array();
             $channelAlias = $channel->alias;
             $errors = '';
             $upload = json_decode($upload, true);
             if (!empty($upload)) {
                 for ($i = 0; $i < count($upload); $i++) {
                     $productInformation = $upload[$i];
                     $company = Companies::findFirstByName($productInformation['companyName']);
                     if ($company) {
                         $companyId = $company->id;
                         $processCompany = 0;
                     } else {
                         $company = new Companies();
                         $schemaFile = $this->schemaDir . $this->getDI()->getConfig()->application->jsonSchema->companies;
                         $output = readJsonFromFile($schemaFile, $this);
                         if (!empty($output)) {
                             $properties = $output['properties'];
                             foreach ($properties as $key => $value) {
                                 switch ($key) {
                                     case 'options':
                                         continue 2;
                                         break;
                                     case 'name':
                                         $companyParams[$key] = $productInformation['companyName'];
                                         break;
                                     default:
                                         $companyParams[$key] = !empty($productInformation[$key]) ? $productInformation[$key] : '';
                                         break;
                                 }
                             }
                         }
                         $valid = $company->validateProperty($companyParams, $schemaFile);
                         if (!empty($valid)) {
                             $errors .= implode(", ", $valid);
                             throw new HTTPException("Request unable to be followed due to semantic errors.", 422, array('dev' => ucfirst($errors), 'internalCode' => 'P1000', 'more' => ''));
                         }
                         $companyParams['id'] = $company->id;
                         $companyParams['createdBy'] = isset($productInformation['createdBy']) ? $productInformation['createdBy'] : '';
                         $companyParams['modifiedBy'] = isset($productInformation['modifiedBy']) ? $productInformation['modifiedBy'] : '';
                         $processCompany = 1;
                     }
                     $brandName = !empty($productInformation['brandName']) ? $productInformation['brandName'] : $productInformation['companyName'];
                     if (isset($brandName)) {
                         $brand = Brands::findFirstByName($brandName);
                         if ($brand) {
                             $brandId = $brand->id;
                             $processBrand = 0;
                         } else {
                             $brand = new Brands();
                             $schemaFile = $this->schemaDir . $this->getDI()->getConfig()->application->jsonSchema->brands;
                             $output = readJsonFromFile($schemaFile, $this);
                             if (!empty($output)) {
                                 $properties = $output['properties'];
                                 foreach ($properties as $key => $value) {
                                     switch ($key) {
                                         case 'options':
                                             continue 2;
                                             break;
                                         case 'name':
                                             $brandParams['name'] = $brandName;
                                             break;
                                         default:
                                             $brandParams[$key] = !empty($productInformation[$key]) ? $productInformation[$key] : '';
                                             break;
                                     }
                                 }
                             }
                             $valid = $brand->validateProperty($brandParams, $schemaFile);
                             if (!empty($valid)) {
                                 $errors .= implode(", ", $valid);
                                 throw new HTTPException("Request unable to be followed due to semantic errors.", 422, array('dev' => ucfirst($errors), 'internalCode' => 'P1000', 'more' => ''));
                             }
                             $brandParams['id'] = $brand->id;
                             $brandParams['createdBy'] = isset($productInformation['createdBy']) ? $productInformation['createdBy'] : '';
                             $brandParams['modifiedBy'] = isset($productInformation['modifiedBy']) ? $productInformation['modifiedBy'] : '';
                             $processBrand = 1;
                         }
                     }
                     $areaName = $productInformation['areaName'];
                     if (isset($areaName)) {
                         $area = Areas::findFirstByName($areaName);
                         if ($area) {
                             $areaId = $area->id;
                         } else {
                             $area = new Areas();
                             $schemaFile = $this->schemaDir . $this->getDI()->getConfig()->application->jsonSchema->areas;
                             $output = readJsonFromFile($schemaFile, $this);
                             if (!empty($output)) {
                                 $properties = $output['properties'];
                                 foreach ($properties as $key => $value) {
                                     switch ($key) {
                                         case 'options':
                                             continue 2;
                                             break;
                                         case 'name':
                                             $areaParams['name'] = $areaName;
                                             break;
                                         default:
                                             $areaParams[$key] = !empty($productInformation[$key]) ? $productInformation[$key] : '';
                                             break;
                                     }
                                 }
                             }
                             $valid = $area->validateProperty($areaParams, $schemaFile);
                             if (!empty($valid)) {
                                 $errors .= implode(", ", $valid);
                                 throw new HTTPException("Request unable to be followed due to semantic errors.", 422, array('dev' => ucfirst($errors), 'internalCode' => 'P1000', 'more' => ''));
                             }
                             $areaParams['id'] = $area->id;
                             $areaParams['name'] = $areaName;
                             $areaParams['language'] = $productInformation['language'];
                             $areaParams['status'] = $productInformation['status'];
                             if (isset($areaParams['status'])) {
                                 $areaParams['active'] = $productInformation['status'] != Areas::ACTIVE ? 0 : 1;
                             }
                             $areaParams['createdBy'] = isset($productInformation['createdBy']) ? $productInformation['createdBy'] : '';
                             $areaParams['modifiedBy'] = isset($productInformation['modifiedBy']) ? $productInformation['modifiedBy'] : '';
                             $processArea = 1;
                         }
                     }
                     $productName = !empty($productInformation['productName']) ? $productInformation['productName'] : '';
                     if (isset($productName)) {
                         $product = Products::findFirstByName($productName);
                         if ($product) {
                             $productId = $product->id;
                             $processChannel = 0;
                         } else {
                             $params['productName'] = $productInformation['productName'];
                             $params['featured'] = isset($productInformation['featured']) ? $productInformation['featured'] : 0;
                             $params['productImage'] = isset($productInformation['productImage']) ? $productInformation['productImage'] : '';
                             $product = new Products();
                             $schemaFile = $this->schemaDir . $this->getDI()->getConfig()->application->jsonSchema->{$channelAlias};
                             $output = readJsonFromFile($schemaFile, $this);
                             if (!empty($output)) {
                                 $properties = $output['properties'];
                                 foreach ($properties as $key => $value) {
                                     switch ($key) {
                                         case 'options':
                                             continue 2;
                                             break;
                                         case 'name':
                                             $productData['name'] = $productInformation['productName'];
                                             break;
                                         case 'id':
                                             $productData['id'] = $product->id;
                                             break;
                                         default:
                                             $productData[$key] = !empty($productInformation[$key]) ? $productInformation[$key] : '';
                                             break;
                                     }
                                 }
                             }
                             $valid = $product->validateProperty($productData, $schemaFile);
                             if (!empty($valid)) {
                                 $errors .= implode(", ", $valid);
                                 throw new HTTPException("Request unable to be followed due to semantic errors.", 422, array('dev' => $errors, 'internalCode' => 'P1000', 'more' => ''));
                             }
                             $productData['id'] = $product->id;
                             $productData['channelId'] = $channelId;
                             $productData['name'] = $productInformation['productName'];
                             $productData['alias'] = '';
                             $productData['language'] = $productInformation['language'];
                             $productData['featured'] = $productInformation['featured'];
                             $productData['icon'] = $productInformation['productImage'];
                             $productData['status'] = $productInformation['status'];
                             if (isset($productData['status'])) {
                                 $productData['active'] = $productInformation['status'] != Products::ACTIVE ? 0 : 1;
                             }
                             $productData['createdBy'] = isset($productInformation['createdBy']) ? $productInformation['createdBy'] : '';
                             $productData['modifiedBy'] = isset($productInformation['modifiedBy']) ? $productInformation['modifiedBy'] : '';
                             $processChannel = 1;
                         }
                         // only save the records when all data is valid
                         if ($processCompany) {
                             $companyParams['id'] = $company->id;
                             if ($company->create($companyParams)) {
                                 $companyId = $company->id;
                             } else {
                                 throw new HTTPException("Request unable to be followed due to semantic errors", 422, array('dev' => $company->getMessages(), 'internalCode' => 'P1000', 'more' => ''));
                             }
                         }
                         if ($processBrand) {
                             $brandParams['companyId'] = $company->id;
                             if ($brand->create($brandParams)) {
                                 $brandId = $brand->id;
                             } else {
                                 throw new HTTPException("Request unable to be followed due to semantic errors", 422, array('dev' => $brand->getMessages(), 'internalCode' => 'P1000', 'more' => ''));
                             }
                         }
                         if ($processArea) {
                             if ($area->create($areaParams)) {
                                 $areaId = $area->id;
                             } else {
                                 throw new HTTPException("Request unable to be followed due to semantic errors", 422, array('dev' => $area->getMessages(), 'internalCode' => 'P1000', 'more' => ''));
                             }
                         }
                         if ($processChannel) {
                             $productData['id'] = $product->id;
                             $productData['brandId'] = $brandId;
                             if ($product->create($productData)) {
                                 $productId = $product->id;
                             } else {
                                 throw new HTTPException("Request unable to be followed due to semantic errors", 422, array('dev' => $product->getMessages(), 'internalCode' => 'P1000', 'more' => ''));
                             }
                         }
                         unset($productInformation['productName']);
                         unset($productInformation['areaName']);
                         unset($productInformation['brandName']);
                         unset($productInformation['companyName']);
                         unset($productInformation['language']);
                         unset($productInformation['featured']);
                         unset($productInformation['productImage']);
                         $this->_addProductsOptions($productId, $areaId, $channelAlias, $productInformation);
                     }
                 }
                 return $results;
             } else {
                 throw new HTTPException('Could not return results in specified format', 403, array('dev' => 'Could not understand type specified by type parameter in query string.', 'internalCode' => 'NF1000', 'more' => 'Type may not be implemented.'));
             }
         } else {
             throw new HTTPException('Could not return results in specified format', 403, array('dev' => 'Could not understand type specified by type parameter in query string.', 'internalCode' => 'NF1000', 'more' => 'Type may not be implemented.'));
         }
     } else {
         throw new HTTPException("The request cannot be fulfilled due to bad syntax.", 400, array('dev' => 'A required field is missing.', 'internalCode' => 'P1000', 'more' => ''));
     }
 }
 /**
  * @api {get} /properties GET /properties
  * @apiExample Example usage:
  * curl -H "X-COMPARE-REST-API-KEY: 1234567890" 
  *      -i "http://apibeta.compargo.com/v1/properties/?countryCode=ph&language=en&
  *          title=brands
  *
  * @apiDescription Read data of a Property
  * @apiName        GetOne
  * @apiGroup       Properties
  *
  * @apiHeader      {String} X-COMPARE-REST-API-KEY   Properties unique access-key.
  *
  * @apiParam       {String} language                 Mandatory Language.
  * @apiParam       {String} countryCode              Mandatory Country Code.
  * @apiParam       {String} title                    Mandatory Title.
  * 
  * @apiSuccess     {String} id                       ID of the Country. 
  * 
  * @apiSuccessExample Success-Response:
  *     HTTP/1.1 200 OK
  *     {
  *       "$schema": "http://json-schema.org/draft-04/schema#",
  *       "title": "brands",
  *       "type": "object",
  *       "properties": {
  *       "name": {
  *          "label": "name",
  *          "type": "string",
  *          "validators": [
  *           {
  *               "rule": "minLength",
  *               "options": {
  *                   "min": 2
  *               },
  *              "message": "name must be greater than 2 characters long"
  *           },
  *           {
  *               "rule": "maxLength",
  *               "options": {
  *                   "max": 255
  *               },
  *               "message": "name must be less than 255 characters long"
  *           }
  *       ],
  *       "required": true
  *   },
  *   "alias": {
  *       "label": "alias",
  *       "type": "string",
  *       "validators": [
  *           {
  *               "rule": "minLength",
  *               "options": {
  *                   "min": 2
  *               },
  *               "message": "alias must be greater than 2 characters long"
  *           },
  *           {
  *               "rule": "maxLength",
  *               "options": {
  *                   "max": 255
  *               },
  *               "message": "alias must be less than 255 characters long"
  *           },
  *           {
  *               "rule": "slug",
  *               "options": {
  *                   "separator": "-"
  *               },
  *               "message": "alias must only have alpha-numeric and -"
  *           }
  *       ],
  *       "required": false
  *    }
  *}
  *
  * @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 PropertyNotFound The name of the Property was not found.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 404 Not Found
  *     {
  *       "error": "PropertyNotFound"
  *     }
  */
 public function getOne($title)
 {
     $output = readJsonFromFile($this->schemaDir . $this->di->getConfig()->application->jsonSchema->{$title});
     if (!empty($output)) {
         $results = $output['properties'];
     } else {
         throw new HTTPException("Not found", 404, array('dev' => 'Property does not exist', 'internalCode' => 'P1000', 'more' => ''));
     }
     return $results;
 }
 /**
  * @api {post} /companies POST /companies
  * @apiExample Example usage:
  * curl -i -X POST "http://apibeta.compargo.com/v1/companies/?countryCode=ph&language=en"
  *      -H "X-COMPARE-REST-API-KEY: 1234567890"
  *      -d "verticalId=07f44e24-1d43-11e4-b32d-eff91066cccf&
  *          name=HSBC&
  *          alias=hsbc&
  *          logo=ph/companies/hsbc.jpg&
  *          link=hsbc.com.ph&
  *          description=HSBC&
  *          language=en&
  *          revenueValue=5.00&
  *          status=1"
  *
  * @apiDescription  Create a new Company
  * @apiName         Post
  * @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} name                     Mandatory Name of the Company.
  * 
  * @apiParam        {String} [description]            Optional Description of the Company.
  * @apiParam        {String} [alias]                  Optional Alias of the Company.
  * @apiParam        {String} [logo]                   Optional Logo of the Company.
  * @apiParam        {String} [link]                   Optional Link of the Company.
  * @apiParam        {String} [revenueValue]           Optional Revenue Value of the Company.
  * @apiParam        {String} [createdBy]              Optional ID of the User who created the Company.
  * @apiParam        {String} [modifiedBy]             Optional ID of the User who modified the Company.
  *
  * @apiSuccess      {String} id                       The new Company-ID.
  *
  * @apiSuccessExample Success-Response:
  *     HTTP/1.1 200 OK
  *     {
  *       "id": "33f42f48-37b6-11e4-b18a-fe7344fb1ea4"
  *     }
  *
  * @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 RouteNotFound That route was not found on the server.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 404
  *     {
  *       "error": "RouteNotFound"
  *     }
  */
 public function post()
 {
     $results = $params = array();
     $request = $this->di->get('request');
     $data = $request->getPost();
     if (!empty($data)) {
         $company = new Companies();
         $data['id'] = $company->id;
         $data['alias'] = isset($data['alias']) ? $data['alias'] : '';
         $data['logo'] = isset($data['logo']) ? $data['logo'] : '';
         $data['link'] = isset($data['link']) ? $data['link'] : '';
         $data['description'] = isset($data['description']) ? $data['description'] : '';
         $data['language'] = isset($data['language']) ? $data['language'] : '';
         $data['revenueValue'] = isset($data['revenueValue']) ? $data['revenueValue'] : '0.00';
         // iterate each field on the json schemaj
         // and fill parameters to feed on validator later
         // required/mandatory fields w/o values will trigger a validation error
         $schemaFile = $this->schemaDir . $this->getDI()->getConfig()->application->jsonSchema->companies;
         $output = readJsonFromFile($schemaFile, $this);
         if (!empty($output)) {
             $properties = $output['properties'];
             foreach ($properties as $key => $value) {
                 if ($key == 'options') {
                     continue;
                 }
                 $params[$key] = !empty($data[$key]) ? $data[$key] : '';
             }
         }
         // var_dump($params); die;
         // $params['name'] = isset($data['name']) ? $data['name'] : '';
         // $params['logo'] = $data['logo'];
         // $params['link'] = $data['link'];
         // $params['description'] = $data['description'];
         // $params['language'] = $data['language'];
         // $params['revenueValue'] = $data['revenueValue'];
         // $params['featured'] = $data['featured'];
         $valid = $company->validateProperty($params, $schemaFile);
         if (!empty($valid)) {
             $errors = implode(", ", $valid);
             throw new HTTPException("Request unable to be followed due to semantic errors.", 422, array('dev' => ucfirst($errors), 'internalCode' => 'P1000', 'more' => ''));
         }
         $data['status'] = isset($data['status']) ? $data['status'] : 0;
         if (isset($data['status'])) {
             $data['active'] = $data['status'] != Companies::ACTIVE ? 0 : 1;
         }
         $data['createdBy'] = isset($data['createdBy']) ? $data['createdBy'] : '';
         $data['modifiedBy'] = isset($data['modifiedBy']) ? $data['modifiedBy'] : '';
         if ($company->create($data)) {
             $results['id'] = $company->id;
         } else {
             throw new HTTPException("Request unable to be followed due to semantic errors.", 422, array('dev' => $company->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;
 }