/** * Deletes this record from the database on the Database Server. * * @return Result Response object. * @throws FileMakerException */ public function delete() { if (empty($this->recordId)) { throw new FileMakerException($this->fm, 'You cannot delete a record that does not exist on the server.'); } if ($this->parent) { $editCommand = $this->fm->newEditCommand($this->parent->layout->getName(), $this->parent->recordId, []); $editCommand->_setdeleteRelated($this->layout->getName() . "." . $this->recordId); return $editCommand->execute(); } else { $layoutName = $this->layout->getName(); $editCommand = $this->fm->newDeleteCommand($layoutName, $this->recordId); return $editCommand->execute(); } }
echo 'New record count ' . $result->getTableRecordCount() . '... <span style="color:green">SUCCESS</span>' . PHP_EOL . PHP_EOL; echo "test create record... "; $newRecord = $fm->newAddCommand($layout->getName()); $time = time(); $newRecord->setField('id_sample', $record->getField('id')); $newRecord->setField('text_field', "NEW RELATED RECORD"); $newRecord->setField('number_field', rand(1, 1000)); $newRecord->setField('date_field', date('m/d/Y', $time)); $newRecord->setField('time_field', date('H:i:s', $time)); $newRecord->setField('timestamp_field', date('m/d/Y H:i:s', $time)); $result = $newRecord->execute(); $recordId = $result->getFirstRecord()->getRecordId(); echo 'New record count ' . $result->getTableRecordCount() . '... '; echo '<span style="color:green">SUCCESS</span>' . PHP_EOL . PHP_EOL; echo "test delete record... "; $delCommand = $fm->newDeleteCommand($layout->getName(), $recordId); $result = $delCommand->execute(); echo 'New record count ' . $result->getTableRecordCount() . '... <span style="color:green">SUCCESS</span>' . PHP_EOL . PHP_EOL; echo "test Record validation rules... "; $updateCommand = $fm->newEditCommand($layout->getName(), $record->getRecordId(), ['text_field' => str_repeat('a', 51)]); try { $updateCommand->validate(); } catch (\tranduchieu\FileMaker\FileMakerValidationException $e) { if ($e->getErrors('text_field')[0][1] == FileMaker::RULE_MAXCHARACTERS) { echo '... <span style="color:green">SUCCESS</span>' . PHP_EOL . PHP_EOL; } else { echo '... <span style="color:red">FAIL</span>' . PHP_EOL . PHP_EOL; } } echo "test Add record... "; $addCommand = $fm->newAddCommand($layout->getName(), ['text_field' => 'Test Add Command']);