Exemplo n.º 1
0
 /**
  * API Method inserts a new Level 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');
         }
         $level = new Level($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
         // $level->Idlevel = $this->SafeGetVal($json, 'idlevel');
         $level->Fond = $this->SafeGetVal($json, 'fond');
         $level->Institution = $this->SafeGetVal($json, 'institution');
         $level->Type = $this->SafeGetVal($json, 'type');
         $level->Level = $this->SafeGetVal($json, 'level');
         $level->Countitem = $this->SafeGetVal($json, 'countitem');
         $level->Levelcol = $this->SafeGetVal($json, 'levelcol');
         $level->Validate();
         $errors = $level->GetValidationErrors();
         if (count($errors) > 0) {
             $this->RenderErrorJSON('Please check the form for errors', $errors);
         } else {
             $level->Save();
             $this->RenderJSON($level, $this->JSONPCallback(), true, $this->SimpleObjectParams());
         }
     } catch (Exception $ex) {
         $this->RenderExceptionJSON($ex);
     }
 }