/**
  * Gets the data within a channel.
  *
  * Body of output document takes the form:
  *
  * <code>
  * [{"object_type":"x","communication_key":"y","position":"99","data":{...},...]
  * </code>
  *
  * @param array $params The following keys are expected: 
  * 	`array('channelset'=>'name of channelset','channel'=>'name of channel')`
  */
 public function restGetChannelsetChannel($params)
 {
     $channelsetId = $this->getChannelSetId($params['channelset']);
     $userRec = $this->getUser($channelsetId);
     InstructionControl::setUserChannelset($userRec['id'], $channelsetId);
     $data = InstructionControl::getInstructionForChannel(InstructionControl::getChannelId($channelsetId, $params['channel']));
     header('HTTP/1.1 200 OK');
     echo json_encode(InstructionControl::generateReturnDocument('CHANNEL_DATA', array(), array(), array(), array('channel' => $params['channel']), $data));
     return true;
 }
 public function testGetInstructionForChannel()
 {
     // Load a load of data and check we can read it back.
     $channel = genSaneGuid();
     $channelId = $this->_getChannelId($channel);
     $user = InstructionControl::getUser(null, genSaneGuid());
     foreach ($this->providerAddInstructionData() as $dataChunk) {
         $data = $dataChunk[1];
         $objectType = $dataChunk[0];
         $id = InstructionControl::reserveInstructionId($user['id'], $channelId, $objectType);
         InstructionControl::addInstructionData($id, $data);
     }
     $loadedData = InstructionControl::getInstructionForChannel($channelId);
     $position = 0;
     foreach ($this->providerAddInstructionData() as $dataChunk) {
         $data = $dataChunk[1];
         $objectType = $dataChunk[0];
         $loaded = array_shift($loadedData);
         $expected = array('object_type' => $objectType, 'communication_key' => $user['communication_key'], 'position' => $position++, 'data' => $data);
         $this->assertEquals($expected, $loaded);
     }
     // Also check that if we supply a non existant channel we get an empty
     // array
     $this->assertEquals(array(), InstructionControl::getInstructionForChannel(genSaneGuid()));
 }