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