/** * API Method inserts a new Creator record and render response as JSON */ public function Create() { try { $json = json_decode(RequestUtil::GetBody()); if (!$json) { throw new Exception('The request body does not contain valid JSON'); } $creator = new Creator($this->Phreezer); // TODO: any fields that should not be inserted by the user should be commented out // this is an auto-increment. uncomment if updating is allowed // $creator->Idcreator = $this->SafeGetVal($json, 'idcreator'); $creator->Institution = $this->SafeGetVal($json, 'institution'); $creator->Type = $this->SafeGetVal($json, 'type'); $creator->Name = $this->SafeGetVal($json, 'name'); $creator->Notes = $this->SafeGetVal($json, 'notes'); $creator->Birthdate = $this->SafeGetVal($json, 'birthdate'); $creator->Deathdate = $this->SafeGetVal($json, 'deathdate'); $creator->Nationality = $this->SafeGetVal($json, 'nationality'); $creator->Maincontact = $this->SafeGetVal($json, 'maincontact'); $creator->Validate(); $errors = $creator->GetValidationErrors(); if (count($errors) > 0) { $this->RenderErrorJSON('Please check the form for errors', $errors); } else { $creator->Save(); $this->RenderJSON($creator, $this->JSONPCallback(), true, $this->SimpleObjectParams()); } } catch (Exception $ex) { $this->RenderExceptionJSON($ex); } }