Example #1
0
 /**
  * 
  * @return boolean TRUE on success
  * @throws FileMakerException
  */
 private function _commitEditChild()
 {
     $modifiedFields = [];
     foreach ($this->fields as $fieldName => $repetitions) {
         foreach ($repetitions as $repetition => $value) {
             if (!empty($this->_modifiedFields[$fieldName][$repetition])) {
                 $modifiedFields[$fieldName . '.' . $this->recordId][$repetition] = $value;
             }
         }
     }
     $editCommand = $this->fm->newEditCommand($this->parent->layout->getName(), $this->parent->getRecordId(), $modifiedFields);
     $result = $editCommand->execute();
     $records = $result->getRecords();
     $firstRecord = $records[0];
     $relatedSet = $firstRecord->getRelatedSet($this->layout->getName());
     foreach ($relatedSet as $record) {
         if ($record->getRecordId() == $this->recordId) {
             return $this->_updateFrom($record);
             break;
         }
     }
     throw new FileMakerException('Failed to find the updated child in the response.');
 }
Example #2
0
 $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']);
 $addCommand->setField('number_field', rand(1, 2000));
 $addCommand->setFieldFromTimestamp('date_field', time());
 $addCommand->setFieldFromTimestamp('timestamp_field', time());
 $addCommand->setFieldFromTimestamp('time_field', time());