/** * Creates a new dance */ function dance_put() { /* User ID ------------------------------------------------- */ $uuid = $this->put("uuid"); $guid = $this->put("guid"); $robot_id = $this->put("robot_id"); $sound_id = $this->put("sound_id"); $robot_name = $this->put("robot_name"); $robot_still = $this->put("robot_still"); $is_entered_into_comp = $this->put("is_entered_into_comp") == 1 ? 1 : 0; /* Save the main data into a json encoded array ------------------------------------------------- */ $move = array("masterTempo" => $this->put("masterTempo"), "neck_tempoMultiplier" => $this->put("neck_tempoMultiplier"), "neck_upDown" => $this->put("neck_upDown"), "neck_leftRight" => $this->put("neck_leftRight"), "rightForearm_reverse" => $this->put("rightForearm_reverse"), "rightForearm_tempoMultiplier" => $this->put("rightForearm_tempoMultiplier"), "rightForearm_amount" => $this->put("rightForearm_amount"), "rightForearm_angle" => $this->put("rightForearm_angle"), "rightUpperArm_reverse" => $this->put("rightUpperArm_reverse"), "rightUpperArm_tempoMultiplier" => $this->put("rightUpperArm_tempoMultiplier"), "rightUpperArm_amount" => $this->put("rightUpperArm_amount"), "rightUpperArm_angle" => $this->put("rightUpperArm_angle"), "leftForearm_reverse" => $this->put("leftForearm_reverse"), "leftForearm_tempoMultiplier" => $this->put("leftForearm_tempoMultiplier"), "leftForearm_amount" => $this->put("leftForearm_amount"), "leftForearm_angle" => $this->put("leftForearm_angle"), "leftUpperArm_reverse" => $this->put("leftUpperArm_reverse"), "leftUpperArm_tempoMultiplier" => $this->put("leftUpperArm_tempoMultiplier"), "leftUpperArm_amount" => $this->put("leftUpperArm_amount"), "leftUpperArm_angle" => $this->put("leftUpperArm_angle"), "hips_tempoMultiplier" => $this->put("hips_tempoMultiplier"), "hips_upDown" => $this->put("hips_upDown"), "hips_leftRight" => $this->put("hips_leftRight")); $encoded_move = json_encode($move); /* Save it ------------------------------------------------- */ $dance = new Dance(); $dance->get_by_guid($guid); if ($dance->exists()) { $dance->move = $encoded_move; $dance->date_updated = mktime(); $dance->robot_name = $robot_name; $dance->robot_still = $robot_still; $dance->is_entered_into_comp = $is_entered_into_comp; // Save the soundtrack to the dance $soundtrack = new Soundtrack(); $soundtrack->get_by_id($sound_id); $dance->save($soundtrack); $output = $dance->save() ? $dance->guid : 'Error'; } else { /* New dance ------------------------------------------------- */ $user = new User(); $user->get_by_uuid($uuid); if ($user->exists()) { // Dance doesn't exist, create it $new_dance = new Dance(); $new_dance->guid = uniqid(); $new_dance->move = $encoded_move; $new_dance->date_created = mktime(); $new_dance->date_updated = mktime(); $new_dance->robot_name = $robot_name; $new_dance->robot_still = $robot_still; $new_dance->is_entered_into_comp = $is_entered_into_comp; // Save the dance on the user if ($new_dance->save($user)) { // Save the robot to the dance $robot = new Robot(); $robot->get_by_id($robot_id); $new_dance->save($robot); // Save the soundtrack to the dance $soundtrack = new Soundtrack(); $soundtrack->get_by_id($sound_id); $new_dance->save($soundtrack); $output = $new_dance->guid; } } else { $output = "Error"; // $output = "unable to find user with UUID ". $uuid; } } /* Return the data ------------------------------------------------- */ $this->response($output); }