/** * Returns an array of layouts from the current database that are * available with the current server settings and the current * user name and password credentials. * * @return array|FileMakerException List of layout names. * @throws FileMakerException */ public function listLayouts() { $request = $this->execute(array('-db' => $this->getProperty('database'), '-layoutnames' => true)); if (FileMaker::isError($request)) { return $request; } $parser = new FMResultSet($this); $result = $parser->parse($request); if (FileMaker::isError($result)) { return $result; } $list = array(); foreach ($parser->parsedResult as $data) { $list[] = $data['fields']['LAYOUT_NAME'][0]; } return $list; }
public function execute() { $params = $this->_getCommandParams(); $this->_setSortParams($params); $this->_setRangeParams($params); $this->_setRelatedSetsFilters($params); if (count($this->_findCriteria) || $this->recordId) { $params['-find'] = true; } else { $params['-findall'] = true; } if ($this->recordId) { $params['-recid'] = $this->recordId; } if ($this->_operator) { $params['-lop'] = $this->_operator; } foreach ($this->_findCriteria as $field => $value) { $params[$field] = $value; } $result = $this->fm->execute($params); if (FileMaker::isError($result)) { return $result; } return $this->_getResult($result); }
/** * Loads extended (FMPXMLLAYOUT) layout information. * * @access private * * @param string $recid Record from which to load extended information. * * @return boolean TRUE, if successful. * @throws FileMakerException; */ public function loadExtendedInfo($recid = null) { if (!$this->extended || $recid != null) { if ($recid != null) { $result = $this->fm->execute(array('-db' => $this->fm->getProperty('database'), '-lay' => $this->getName(), '-recid' => $recid, '-view' => null), 'FMPXMLLAYOUT'); } else { $result = $this->fm->execute(array('-db' => $this->fm->getProperty('database'), '-lay' => $this->getName(), '-view' => null), 'FMPXMLLAYOUT'); } $parser = new FMPXMLLAYOUT($this->fm); $parseResult = $parser->parse($result); if (FileMaker::isError($parseResult)) { return $parseResult; } $parser->setExtendedInfo($this); $this->extended = true; } return $this->extended; }
/** * Sets the new value for a field. * * @param string $field Name of field to set. * @param string $value Value to set for this field. * @param integer $repetition Field repetition number to set, * Defaults to the first repetition. * * @return string */ public function setField($field, $value, $repetition = 0) { $fieldInfos = $this->fm->getLayout($this->_layout)->getField($field); /* if(FileMaker::isError($fieldInfos)){ return $fieldInfos; }*/ $format = FileMaker::isError($fieldInfos) ? null : $fieldInfos->result; if (!empty($value) && $this->fm->getProperty('dateFormat') !== null && ($format === 'date' || $format === 'timestamp')) { if ($format === 'date') { $dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value . ' 00:00:00'); $value = $dateTime->format('m/d/Y'); } else { $dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value); $value = $dateTime->format('m/d/Y H:i:s'); } } $this->_fields[$field][$repetition] = $value; return $value; }
/** * * @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; }
/** * Sets the new value for a date, time, or timestamp field from a * UNIX timestamp value. * * If the field is not a date or time field, then this method returns * an Error object. Otherwise, returns TRUE. * * If layout data for the target of this command has not already * been loaded, calling this method loads layout data so that * the type of the field can be checked. * * @param string $field Name of the field to set. * @param string $timestamp Timestamp value. * @param integer $repetition Field repetition number to set. * Defaults to the first repetition. * * @return string|FileMakerException * @throws FileMakerException */ public function setFieldFromTimestamp($field, $timestamp, $repetition = 0) { $layout =& $this->fm->getLayout($this->_layout); if (FileMaker::isError($layout)) { return $layout; } $field =& $layout->getField($field); if (FileMaker::isError($field)) { return $field; } switch ($field->getResult()) { case 'date': return $this->setField($field, date('m/d/Y', $timestamp), $repetition); case 'time': return $this->setField($field, date('H:i:s', $timestamp), $repetition); case 'timestamp': return $this->setField($field, date('m/d/Y H:i:s', $timestamp), $repetition); } $error = new FileMakerException($this->fm, 'Only time, date, and timestamp fields can be set to the value of a timestamp.'); if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; }
/** * * @param string $xml * @return Result|FileMakerException * @throws FileMakerException */ protected function _getResult($xml) { $parser = new FMResultSet($this->fm); $parseResult = $parser->parse($xml); if (FileMaker::isError($parseResult)) { return $parseResult; } $result = new Result($this->fm); $parseResult = $parser->setResult($result, $this->_recordClass); if (FileMaker::isError($parseResult)) { return $parseResult; } return $result; }
/** * Add extended infos to a Layout object * * @param Layout $layout * @return FileMakerException * @throws FileMakerException */ public function setExtendedInfo(Layout $layout) { if (!$this->_isParsed) { $error = new FileMakerException($this->_fm, 'Attempt to set extended information before parsing data.'); if ($this->_fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; } $layout->valueLists = $this->_valueLists; $layout->valueListTwoFields = $this->_valueListTwoFields; foreach ($this->_fields as $fieldName => $fieldInfos) { try { $field = $layout->getField($fieldName); if (!FileMaker::isError($field)) { $field->styleType = $fieldInfos['styleType']; $field->valueList = $fieldInfos['valueList'] ? $fieldInfos['valueList'] : null; } } catch (\Exception $e) { //Field may be missing when it is stored in a portal, ommit error } } }