/**
  * @api {put} /country_options/:id PUT /country_options/:id
  * @apiExample Example usage:
  * curl -i -X PUT "http://apibeta.compargo.com/v1/country_options/8c1291d6-22b9-11e4-bd33-17609cecca2f/?countryCode=ph&language=en"
  *      -H "X-COMPARE-REST-API-KEY: 1234567890"
  *      -d "name=numcode
  *          value=004&
  *          editable=1&
  *          visibility=1&
  *          status=1"
  *      
  * @apiDescription Update a Country Option
  * @apiName  Put
  * @apiGroup Country Options
  *
  * @apiHeader {String} X-COMPARE-REST-API-KEY   Country Options unique access-key.
  *
  * @apiParam  {String} language                 Mandatory Language.
  * @apiParam  {String} countryCode              Mandatory Country Code.
  * @apiParam  {String} id                       Mandatory Country Option Unique ID.
  * @apiParam  {String} name                     Mandatory Name of the Country Option.
  * @apiParam  {String} value                    Mandatory Value of the Country Option.
  * @apiParam  {String} [label]                  Optional Label of the Country Option.
  * @apiParam  {String} [editable]               Optional Editable Flag of the Country Option.
  * @apiParam  {String} [visibility]             Optional Visibility Flag of the Country Option.
  * @apiParam  {String} [status]                 Optional Status of the Country Option.
  * @apiParam  {String} [createdBy]              Optional ID of the User who created the Country Option.
  * @apiParam  {String} [modifiedBy]             Optional ID of the User who modified the Country Option.
  *
  * @apiSuccessExample Success-Response:
  *     HTTP/1.1 200 OK
  *     {
  *       "id": "8c1291d6-22b9-11e4-bd33-17609cecca2f"
  *     }
  *     
  * @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 CountryOptionNotFound The id of the Country Option was not found.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 404 Not Found
  *     {
  *       "error": "CountryOptionNotFound"
  *     }
  */
 public function put($id)
 {
     $results = array();
     $request = $this->di->get('request');
     $data = $request->getPut();
     if (!empty($data)) {
         $countryOptions = CountryOptions::findFirstById($id);
         if (!$countryOptions) {
             throw new HTTPException("Not found", 404, array('dev' => 'Country option does not exist', 'internalCode' => 'P1000', 'more' => ''));
         } else {
             $params['countryId'] = isset($data['countryId']) ? $data['countryId'] : $countryOptions->countryId;
             $params['name'] = isset($data['name']) ? $data['name'] : $countryOptions->name;
             $params['value'] = isset($data['value']) ? $data['value'] : $countryOptions->value;
             $params['label'] = isset($data['label']) ? $data['label'] : $countryOptions->label;
             $data['status'] = isset($data['status']) ? $data['status'] : $countryOptions->status;
             if (isset($data['status'])) {
                 $data['active'] = $data['status'] != CountryOptions::ACTIVE ? 0 : 1;
                 $data['editable'] = $data['status'] != CountryOptions::ACTIVE ? 0 : $countryOptions->editable;
                 $data['visibility'] = $data['status'] != CountryOptions::ACTIVE ? 0 : $countryOptions->visibility;
             }
             $data['createdBy'] = isset($data['createdBy']) ? $data['createdBy'] : $countryOptions->createdBy;
             $data['modifiedBy'] = isset($data['modifiedBy']) ? $data['modifiedBy'] : $countryOptions->modifiedBy;
             if ($countryOptions->save($data)) {
                 $results['id'] = $countryOptions->id;
             } else {
                 throw new HTTPException("Request unable to be followed due to semantic errors", 422, array('dev' => $countryOptions->getMessages(), 'internalCode' => 'P1000', 'more' => ''));
             }
         }
     } else {
     }
     return $results;
 }
 /**
  * Responds with information about updated inserted company
  *
  * @method post
  * @return json/xml data
  */
 public function put($id)
 {
     $results = array();
     $countryOption = CountryOptions::findFirstById($id);
     if ($countryOption) {
         $countryOptionsCollection = CountryOptionsCollection::findFirst(array(array('id' => $id)));
         if ($countryOptionsCollection != false) {
             $countryOptionCollection->id = $countryOption->id;
             $countryOptionCollection->countryId = $countryOption->countryId;
             $countryOptionCollection->name = $countryOption->name;
             $countryOptionCollection->value = $countryOption->value;
             $countryOptionCollection->label = $countryOption->label;
             $countryOptionCollection->status = $countryOption->status;
             $countryOptionCollection->active = $countryOption->active;
             $countryOptionCollection->editable = $countryOption->editable;
             $countryOptionCollection->visibility = $countryOption->active;
             $countryOptionCollection->created = $countryOption->created;
             $countryOptionCollection->modified = $countryOption->modified;
             $countryOptionCollection->createdBy = $countryOption->createdBy;
             $countryOptionCollection->modifiedBy = $countryOption->modifiedBy;
             $success = $countryOptionsCollection->save();
             if ($success) {
                 if (1 == $countryOption->status) {
                     $country = Country::findFirst(array(array('id' => $countryOption->countryId)));
                     if ($country) {
                         $name = $countryOption->name;
                         $country->{$name} = $countryOption->value;
                         $country->save();
                         $results['id'] = $countryOption->id;
                     }
                 }
             }
         }
     }
     return $results;
 }