/**
  * Responds with information about updated inserted area
  *
  * @method post
  * @return json/xml data
  */
 public function put($id)
 {
     $results = array();
     $area = Areas::findFirstById($id);
     if ($area) {
         $areasCollection = AreasCollection::findFirst(array(array('id' => $id)));
         if ($areasCollection != false) {
             $areasCollection->id = $area->id;
             $areasCollection->name = $area->name;
             $areasCollection->category = $area->category;
             $areasCollection->description = $area->description;
             $areasCollection->language = $area->language;
             $areasCollection->bounds = $area->bounds;
             $areasCollection->parentId = $area->parentId;
             $areasCollection->lft = $area->lft;
             $areasCollection->rght = $area->rght;
             $areasCollection->scope = $area->scope;
             $areasCollection->status = $area->status;
             $areasCollection->active = $area->active;
             $areasCollection->created = $area->created;
             $areasCollection->modified = $area->modified;
             $areasCollection->createdBy = $area->createdBy;
             $areasCollection->modifiedBy = $area->modifiedBy;
             $areasCollection->save();
             $results['id'] = $area->id;
         }
     }
     return $results;
 }
 /**
  * @api {put} /areas/:id PUT /areas/:id
  * @apiExample Example usage:
  * curl -i -X PUT "http://apibeta.compargo.com/v1/areas/4b639068-319b-11e4-988c-7d9574853fac/?countryCode=ph&language=en"
  *      -H "X-COMPARE-REST-API-KEY: 1234567890"
  *      -d "name=Western%20Visayas&status=1"
  *      
  * @apiDescription Update an Area
  * @apiName        Update
  * @apiGroup       Areas
  *
  * @apiHeader      {String} X-COMPARE-REST-API-KEY   Areas unique access-key.
  *
  * @apiParam       {String} language                 Mandatory Language.
  * @apiParam       {String} countryCode              Mandatory Country Code.
  * @apiParam       {String} id                       Mandatory Area Unique ID.
  * @apiParam       {String} name                     Mandatory Name of the Area.
  * @apiParam       {String} category                 Mandatory Category of the Area.
  * @apiParam       {String} language                 Mandatory Language of the Area.
  * @apiParam       {String} [description]            Optional Description of the Area.
  * @apiParam       {String} [bounds]                 Optional Bounds of the Area. 
  * @apiParam       {String} [parentId]               Optional Parent ID of the Area.
  * @apiParam       {String} [lft]                    Optional Lft of the Area.
  * @apiParam       {String} [rght]                   Optional Rght of the Area.
  * @apiParam       {Number} [scope=0]                Optional Scope of the Area.
  * @apiParam       {Number} [editable=0]             OptionalEditable Flag of the Area.
  * @apiParam       {Number} [visibility=0]           Optional Visibility Flag of the Area.
  * @apiParam       {Number} [status=0]               Optional Status Flag of the Area.
  *
  * @apiSuccessExample Success-Response:
  *     HTTP/1.1 200 OK
  *     {
  *       "id": "574a5eb2-1d59-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 AreaNotFound The id of the Area was not found.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 404 Not Found
  *     {
  *       "error": "AreaNotFound"
  *     }
  */
 public function put($id)
 {
     $results = $params = array();
     $request = $this->di->get('request');
     $data = $request->getPut();
     if (!empty($data)) {
         $area = Areas::findFirstById($id);
         if (!$area) {
             throw new HTTPException("Not found", 404, array('dev' => 'Area does not exist', 'internalCode' => 'P1000', 'more' => ''));
         } else {
             $data['name'] = isset($data['name']) ? $data['name'] : $area->name;
             $data['category'] = isset($data['category']) ? $data['category'] : $area->category;
             $data['description'] = isset($data['description']) ? $data['description'] : $area->description;
             $data['language'] = isset($data['language']) ? $data['language'] : $area->language;
             $data['bounds'] = isset($data['bounds']) ? $data['bounds'] : $area->bounds;
             $data['parentId'] = isset($data['parentId']) ? $data['parentId'] : $area->parentId;
             $data['lft'] = isset($data['lft']) ? $data['lft'] : $area->lft;
             $data['rght'] = isset($data['rght']) ? $data['rght'] : $area->rght;
             $data['scope'] = isset($data['scope']) ? $data['scope'] : $area->scope;
             $data['status'] = isset($data['status']) ? $data['status'] : $area->status;
             if (isset($data['status'])) {
                 $data['active'] = $data['status'] != Areas::ACTIVE ? 0 : 1;
             }
             if ($area->save($data)) {
                 $results['id'] = $area->id;
             } else {
                 throw new HTTPException("Request unable to be followed due to semantic errors", 422, array('dev' => $area->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;
 }