Beispiel #1
0
 /**
  *
  * @return boolean|FileMakerException 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();
     if (FileMaker::isError($result)) {
         return $result;
     }
     $records = $result->getRecords();
     $firstRecord = $records[0];
     $relatedSet = $firstRecord->getRelatedSet($this->layout->getName());
     if (FileMaker::isError($relatedSet)) {
         return $relatedSet;
     }
     foreach ($relatedSet as $record) {
         if ($record->getRecordId() == $this->recordId) {
             return $this->_updateFrom($record);
             break;
         }
     }
     $error = new FileMakerException($this->fm, 'Failed to find the updated child in the response.');
     if ($this->fm->getProperty('errorHandling') === 'default') {
         return $error;
     }
     throw $error;
 }
Beispiel #2
0
 /**
  * Populate a layout object with parsed datas
  *
  * @param Layout $layout
  * @return FileMakerException|boolean
  * @throws FileMakerException
  */
 public function setLayout(Layout $layout)
 {
     if (!$this->_isParsed) {
         $error = new FileMakerException($this->_fm, 'Attempt to get a layout object before parsing data.');
         if ($this->_fm->getProperty('errorHandling') === 'default') {
             return $error;
         }
         throw $error;
     }
     if ($this->_layout === $layout) {
         return true;
     }
     $layout->name = $this->_parsedHead['layout'];
     $layout->database = $this->_parsedHead['database'];
     $layout->table = $this->_parsedHead['table'];
     foreach ($this->_fieldList as $fieldInfos) {
         $field = new Field($layout);
         $field->name = $fieldInfos['name'];
         $field->autoEntered = (bool) ($fieldInfos['auto-enter'] === 'yes');
         $field->global = (bool) ($fieldInfos['global'] === 'yes');
         $field->maxRepeat = (int) $fieldInfos['max-repeat'];
         $field->result = $fieldInfos['result'];
         $field->type = $fieldInfos['type'];
         if ($fieldInfos['not-empty'] === 'yes') {
             $field->validationRules[FileMaker::RULE_NOTEMPTY] = true;
             $field->validationMask |= FileMaker::RULE_NOTEMPTY;
         }
         if ($fieldInfos['numeric-only'] === 'yes') {
             $field->validationRules[FileMaker::RULE_NUMERICONLY] = true;
             $field->validationMask |= FileMaker::RULE_NUMERICONLY;
         }
         if (array_key_exists('max-characters', $fieldInfos)) {
             $field->maxCharacters = (int) $fieldInfos['max-characters'];
             $field->validationRules[FileMaker::RULE_MAXCHARACTERS] = true;
             $field->validationMask |= FileMaker::RULE_MAXCHARACTERS;
         }
         if ($fieldInfos['four-digit-year'] === 'yes') {
             $field->validationRules[FileMaker::RULE_FOURDIGITYEAR] = true;
             $field->validationMask |= FileMaker::RULE_FOURDIGITYEAR;
         }
         if ($fieldInfos['time-of-day'] === 'yes') {
             $field->validationRules[FileMaker::RULE_TIMEOFDAY] = true;
             $field->validationMask |= FileMaker::RULE_TIMEOFDAY;
         }
         if ($fieldInfos['four-digit-year'] === 'no' && $fieldInfos['result'] === 'timestamp') {
             $field->validationRules[FileMaker::RULE_TIMESTAMP_FIELD] = true;
             $field->validationMask |= FileMaker::RULE_TIMESTAMP_FIELD;
         }
         if ($fieldInfos['four-digit-year'] === 'no' && $fieldInfos['result'] === 'date') {
             $field->validationRules[FileMaker::RULE_DATE_FIELD] = true;
             $field->validationMask |= FileMaker::RULE_DATE_FIELD;
         }
         if ($fieldInfos['time-of-day'] === 'no' && $fieldInfos['result'] === 'time') {
             $field->validationRules[FileMaker::RULE_TIME_FIELD] = true;
             $field->validationMask |= FileMaker::RULE_TIME_FIELD;
         }
         $layout->fields[$field->getName()] = $field;
     }
     foreach ($this->_relatedSetNames as $relatedSetName => $fields) {
         $relatedSet = new RelatedSet($layout);
         $relatedSet->name = $relatedSetName;
         foreach ($fields as $fieldInfos) {
             $field = new Field($layout);
             $field->name = $fieldInfos['name'];
             $field->autoEntered = (bool) ($fieldInfos['auto-enter'] === 'yes');
             $field->global = (bool) ($fieldInfos['global'] === 'yes');
             $field->maxRepeat = (int) $fieldInfos['max-repeat'];
             $field->result = $fieldInfos['result'];
             $field->type = $fieldInfos['type'];
             if ($fieldInfos['not-empty'] === 'yes') {
                 $field->validationRules[FileMaker::RULE_NOTEMPTY] = true;
                 $field->validationMask |= FileMaker::RULE_NOTEMPTY;
             }
             if ($fieldInfos['numeric-only'] === 'yes') {
                 $field->validationRules[FileMaker::RULE_NUMERICONLY] = true;
                 $field->validationMask |= FileMaker::RULE_NUMERICONLY;
             }
             if (array_key_exists('max-characters', $fieldInfos)) {
                 $field->maxCharacters = (int) $fieldInfos['max-characters'];
                 $field->validationRules[FileMaker::RULE_MAXCHARACTERS] = true;
                 $field->validationMask |= FileMaker::RULE_MAXCHARACTERS;
             }
             if ($fieldInfos['four-digit-year'] === 'yes') {
                 $field->validationRules[FileMaker::RULE_FOURDIGITYEAR] = true;
                 $field->validationMask |= FileMaker::RULE_FOURDIGITYEAR;
             }
             if ($fieldInfos['time-of-day'] === 'yes' || $fieldInfos['result'] === 'time') {
                 $field->validationRules[FileMaker::RULE_TIMEOFDAY] = true;
                 $field->validationMask |= FileMaker::RULE_TIMEOFDAY;
             }
             if ($fieldInfos['four-digit-year'] === 'no' && $fieldInfos['result'] === 'timestamp') {
                 $field->validationRules[FileMaker::RULE_TIMESTAMP_FIELD] = true;
                 $field->validationMask |= FileMaker::RULE_TIMESTAMP_FIELD;
             }
             if ($fieldInfos['four-digit-year'] === 'no' && $fieldInfos['result'] === 'date') {
                 $field->validationRules[FileMaker::RULE_DATE_FIELD] = true;
                 $field->validationMask |= FileMaker::RULE_DATE_FIELD;
             }
             if ($fieldInfos['time-of-day'] === 'no' && $fieldInfos['result'] === 'time') {
                 $field->validationRules[FileMaker::RULE_TIME_FIELD] = true;
                 $field->validationMask |= FileMaker::RULE_TIME_FIELD;
             }
             $relatedSet->fields[$field->getName()] = $field;
         }
         $layout->relatedSets[$relatedSet->getName()] = $relatedSet;
     }
     $this->_layout = $layout;
     return true;
 }