/** * API Method inserts a new Item 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'); } $item = new Item($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 // $item->Iditem = $this->SafeGetVal($json, 'iditem'); $item->Holder = $this->SafeGetVal($json, 'holder'); $item->Level = $this->SafeGetVal($json, 'level'); $item->Institution = $this->SafeGetVal($json, 'institution'); $item->Inventoryid = $this->SafeGetVal($json, 'inventoryid'); $item->Uritype = $this->SafeGetVal($json, 'uritype'); $item->Uri = $this->SafeGetVal($json, 'uri'); $item->Keywords = $this->SafeGetVal($json, 'keywords'); $item->Description = $this->SafeGetVal($json, 'description'); $item->Uidtype = $this->SafeGetVal($json, 'uidtype'); $item->Uid = $this->SafeGetVal($json, 'uid'); $item->Class = $this->SafeGetVal($json, 'class'); $item->Type = $this->SafeGetVal($json, 'type'); $item->Iseletronic = $this->SafeGetVal($json, 'iseletronic'); $item->Creationdate = $this->SafeGetVal($json, 'creationdate'); $item->Acquisitiondate = $this->SafeGetVal($json, 'acquisitiondate'); $item->Scopecontent = $this->SafeGetVal($json, 'scopecontent'); $item->Originalexistence = $this->SafeGetVal($json, 'originalexistence'); $item->Originallocation = $this->SafeGetVal($json, 'originallocation'); $item->Repositorycode = $this->SafeGetVal($json, 'repositorycode'); $item->Copyexistence = $this->SafeGetVal($json, 'copyexistence'); $item->Copylocation = $this->SafeGetVal($json, 'copylocation'); $item->Legalaccess = $this->SafeGetVal($json, 'legalaccess'); $item->Accesscondition = $this->SafeGetVal($json, 'accesscondition'); $item->Reproductionrights = $this->SafeGetVal($json, 'reproductionrights'); $item->Reproductionrightsdescription = $this->SafeGetVal($json, 'reproductionrightsdescription'); $item->Itemdate = $this->SafeGetVal($json, 'itemdate'); $item->Publishdate = $this->SafeGetVal($json, 'publishdate'); $item->Publisher = $this->SafeGetVal($json, 'publisher'); $item->Itematributes = $this->SafeGetVal($json, 'itematributes'); $item->Ispublic = $this->SafeGetVal($json, 'ispublic'); $item->Preliminaryrule = $this->SafeGetVal($json, 'preliminaryrule'); $item->Punctuation = $this->SafeGetVal($json, 'punctuation'); $item->Notes = $this->SafeGetVal($json, 'notes'); $item->Otherinformation = $this->SafeGetVal($json, 'otherinformation'); $item->Idfather = $this->SafeGetVal($json, 'idfather'); $item->Titledefault = $this->SafeGetVal($json, 'titledefault'); $item->Subitem = $this->SafeGetVal($json, 'subitem'); $item->Deletecomfirm = $this->SafeGetVal($json, 'deletecomfirm'); $item->Typeitem = $this->SafeGetVal($json, 'typeitem'); $item->Edition = $this->SafeGetVal($json, 'edition'); $item->Isexposed = $this->SafeGetVal($json, 'isexposed'); $item->Isoriginal = $this->SafeGetVal($json, 'isoriginal'); $item->Ispart = $this->SafeGetVal($json, 'ispart'); $item->Haspart = $this->SafeGetVal($json, 'haspart'); $item->Ispartof = $this->SafeGetVal($json, 'ispartof'); $item->Numberofcopies = $this->SafeGetVal($json, 'numberofcopies'); $item->Tobepublicin = date('Y-m-d H:i:s', strtotime($this->SafeGetVal($json, 'tobepublicin'))); $item->Creationdateattributed = $this->SafeGetVal($json, 'creationdateattributed'); $item->Itemdateattributed = $this->SafeGetVal($json, 'itemdateattributed'); $item->Publishdateattributed = $this->SafeGetVal($json, 'publishdateattributed'); $item->Serachdump = $this->SafeGetVal($json, 'serachdump'); $item->Itemmediadir = $this->SafeGetVal($json, 'itemmediadir'); $item->Validate(); $errors = $item->GetValidationErrors(); if (count($errors) > 0) { $this->RenderErrorJSON('Please check the form for errors', $errors); } else { $item->Save(); $this->RenderJSON($item, $this->JSONPCallback(), true, $this->SimpleObjectParams()); } } catch (Exception $ex) { $this->RenderExceptionJSON($ex); } }