/** * Adds an Instruction to a Channel. * * Body of output document takes the form: * * <code> * {"position":"12","channel":"main","data":{"k"=>"v pairs"},"object_type":"Car","communication_key":"g4c667c80947"} * </code> * * @param array $params Expected in the form: * `array('channelset'=>'name','channel'=>'name','object_type'=>'type of object','data'=>array('k'='v pairs')) */ public function restPostChannelsetChannel($params) { InstructionControl::startTransaction(); $channelsetId = $this->getChannelSetId($params['channelset']); $userRec = $this->getUser($channelsetId); $channelId = InstructionControl::getChannelId($channelsetId, $params['channel']); $instructionId = InstructionControl::reserveInstructionId($userRec['id'], $channelId, $params['object_type']); $data = array_key_exists('data', $_REQUEST) ? $_REQUEST['data'] : array(); InstructionControl::addInstructionData($instructionId, $data); InstructionControl::completeTransaction(); $position = InstructionControl::getPositionForInstructionId($instructionId); $return = InstructionControl::generateReturnDocument('INSTRUCTION', array(), array(), array(), array(), array('position' => $position, 'channel' => $params['channel'], 'data' => $data, 'object_type' => $params['object_type'], 'communication_key' => $userRec['communication_key'])); header('HTTP/1.1 201 Created'); echo json_encode($return); if (INSTRUCTIONCONTROL__NOTIFY_OTHER_CLIENTS == 'APE') { InstructionControl::notifyOtherClientsApe($params['channelset'], $channelId, $return); } return true; }