/**
  * Responds with information about updated inserted channel
  *
  * @method put
  * @return json/xml data
  */
 public function put($id)
 {
     $results = array();
     $channel = Channels::findFirstById($id);
     if ($channel) {
         $channelCollection = ChannelsCollection::findFirst(array(array('id' => $id)));
         if ($channelCollection != false) {
             $channelCollection->id = $channel->id;
             $channelCollection->verticalId = $channel->verticalId;
             $channelCollection->name = $channel->name;
             $channelCollection->description = $channel->description;
             $channelCollection->alias = $channel->alias;
             $channelCollection->revenueValue = $channel->revenueValue;
             $channelCollection->perPage = $channel->perPage;
             $channelCollection->active = $channel->active;
             $channelCollection->status = $channel->status;
             $channelCollection->created = $channel->created;
             $channelCollection->modified = $channel->modified;
             $channelCollection->createdBy = $channel->createdBy;
             $channelCollection->modifiedBy = $channel->modifiedBy;
             $channelCollection->save();
             $results['id'] = $channel->id;
         }
     }
     return $results;
 }
 /**
  * Responds with information about updated inserted channels option
  *
  * @method put
  * @return json/xml data
  */
 public function put($id)
 {
     $results = array();
     $channelsOption = ChannelsOptions::findFirstById($id);
     if ($channelsOption) {
         $channelsOptionCollection = ChannelsOptionsCollection::findFirst(array(array('id' => $id)));
         if ($channelsOptionCollection != false) {
             $channelsOptionCollection->id = $channelsOption->id;
             $channelsOptionCollection->channelId = $channelsOption->channelId;
             $channelsOptionCollection->name = $channelsOption->name;
             $channelsOptionCollection->value = $channelsOption->value;
             $channelsOptionCollection->label = $channelsOption->label;
             $channelsOptionCollection->status = $channelsOption->status;
             $channelsOptionCollection->active = $channelsOption->active;
             $channelsOptionCollection->editable = $channelsOption->editable;
             $channelsOptionCollection->visibility = $channelsOption->visibility;
             $channelsOptionCollection->created = $channelsOption->created;
             $channelsOptionCollection->modified = $channelsOption->modified;
             $channelsOptionCollection->createdBy = $channelsOption->createdBy;
             $channelsOptionCollection->modifiedBy = $channelsOption->modifiedBy;
             $success = $channelsOptionCollection->save();
             if ($success) {
                 if (1 == $channelsOption->status) {
                     $channels = Channels::findFirst(array(array('id' => $channelsOption->channelId)));
                     if ($channels) {
                         $name = $channelsOption->name;
                         $channels->{$name} = $channelsOption->value;
                         $channels->save();
                         $results['id'] = $channelsOption->id;
                     }
                 }
             }
         }
     }
     return $results;
 }
 /**
  * @api {post} /channels/search/:id POST /channels/search/:id
  * @apiExample Example usage:
  * curl -H "X-COMPARE-REST-API-KEY: 1234567890" 
  *      -i "http://apibeta.compargo.com/v1/channels/search/a1d14206-1ea9-11e4-b32d-eff91066cccf/?countryCode=ph&language=en"
  * 
  * @apiDescription Read data of a Channel
  * @apiName        SearchOne
  * @apiGroup       Channels
  *
  * @apiHeader      {String} X-COMPARE-REST-API-KEY   Channels unique access-key.
  *
  * @apiParam       {String} language                 Mandatory Language.
  * @apiParam       {String} countryCode              Mandatory Country Code.
  * @apiParam       {String} id                       Mandatory Channel unique ID.
  *
  * @apiSuccess     {String} id                       ID of the Channel.
  * @apiSuccess     {String} verticalId               Vertical ID of the Channel.
  * @apiSuccess     {String} name                     Name of the Channel.
  * @apiSuccess     {String} description              Description of the Channel.
  * @apiSuccess     {String} alias                    Alias of the Channel.
  * @apiSuccess     {String} revenueValue             Revenue Value of the Channel.
  * @apiSuccess     {String} perPage                  Per Page of the Channel.
  * @apiSuccess     {Number} status                   Status of the Channel.
  * @apiSuccess     {Number} active                   Flag of the Channel.
  * @apiSuccess     {Date}   created                  Creation date of the Channel.
  * @apiSuccess     {Date}   modified                 Modification date of the Channel.
  * @apiSuccess     {String} createdBy                ID of the User who created the Channel.
  * @apiSuccess     {String} modifiedBy               ID of the User who modified the Channel.
  * 
  * @apiSuccessExample Success-Response:
  *     HTTP/1.1 200 OK
  *     {
  *       "id": "c6b5edee-1eac-11e4-b32d-eff91066cccf",
  *       "verticalId": "78d7ca20-1dd0-11e4-b32d-eff91066cccf",
  *       "name": "Broadband",
  *       "description": "Broadband",
  *       "alias": "broadband",
  *       "revenueValue": "5.00",
  *       "perPage": "10",
  *       "status": "1",
  *       "active": "1",
  *       "created": "2014-08-08 05:33:34",
  *       "modified": "0000-00-00 00:00:00",
  *       "createdBy": "a8838d12-1dcc-11e4-b32d-eff91066cccf",
  *       "modifiedBy": "a8838d12-1dcc-11e4-b32d-eff91066cccf"
  *     }
  *
  * @apiError ChannelNotFound The id of the Channel was not found.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 404 Not Found
  *     {
  *       "error": "ChannelNotFound"
  *     }
  *
  * @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 searchOne($id)
 {
     $results = array();
     $request = $this->di->get('requestBody');
     $parameters = $request->get();
     if (count($parameters) > 1) {
         $channel = new ChannelsCollection($this->di);
         $results = $this->respond($channel, $id);
     } else {
         $results = ChannelsCollection::findFirstById($id);
     }
     if (!$results) {
         throw new HTTPException("Not found", 404, array('dev' => 'Channel does not exist', 'internalCode' => 'P1000', 'more' => ''));
     }
     return $results;
 }