/** * * @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; }
/** * @covers \airmoi\FileMaker\Object\Record::setField */ public function testSetField() { $this->record->setField('text_field', __METHOD__); $this->assertEquals(__METHOD__, $this->record->getField('text_field')); $this->record->setField('text_field', __METHOD__ . ' repeat 1', 1); $this->assertEquals(__METHOD__ . ' repeat 1', $this->record->getField('text_field', 1)); $this->record->setField('related_sample::text_field', __METHOD__ . 'related[1]'); $this->assertEquals(__METHOD__ . 'related[1]', $this->record->getField('related_sample::text_field')); $this->record->setField('related_sample::text_field', __METHOD__ . 'related[2]', 1); $this->assertEquals(__METHOD__ . 'related[2]', $this->record->getField('related_sample::text_field', 1)); $this->record->setField('date_field', date('Y-m-d')); $this->assertEquals(date('Y-m-d'), $this->record->getField('date_field')); $this->assertInstanceOf(FileMakerException::class, $this->record->setField('missing_field', __METHOD__)); /** * Date autoformat */ $this->fm->setProperty('dateFormat', 'd/m/Y'); $this->record->setField('date_field', '16/06/2016'); $this->assertEquals('06/16/2016', $this->record->fields['date_field'][0]); $this->record->setField('date_field', '01/02/0001'); $this->assertEquals('02/01/0001', $this->record->fields['date_field'][0]); $this->record->setField('date_field', '31/12/4000'); $this->assertEquals('12/31/4000', $this->record->fields['date_field'][0]); $this->assertInstanceOf(FileMakerException::class, $this->record->setField('date_field', '2016-08-19')); $this->record->setField('timestamp_field', '08/01/1942 00:00:00'); $this->assertEquals('01/08/1942 00:00:00', $this->record->fields['timestamp_field'][0]); $this->assertInstanceOf(FileMakerException::class, $this->record->setField('timestamp_field', '2016-08-19')); }
/** * Loads extended (FMPXMLLAYOUT) layout information. * * @access private * * @return boolean|FileMakerException TRUE, if successful. * @throws FileMakerException */ public function loadExtendedInfo() { $error = new FileMakerException($this->fm, 'Related sets do not support extended information.'); if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; }
/** * 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; }
protected function _getCommandParams() { $queryParams = array('-db' => $this->fm->getProperty('database'), '-lay' => $this->_layout); foreach (array('_script' => '-script', '_preReqScript' => '-script.prefind', '_preSortScript' => '-script.presort') as $varName => $paramName) { if ($this->{$varName}) { $queryParams[$paramName] = $this->{$varName}; $varName .= 'Params'; if ($this->{$varName} !== null) { $queryParams[$paramName . '.param'] = $this->{$varName}; } } } if ($this->_resultLayout) { $queryParams['-lay.response'] = $this->_resultLayout; } foreach ($this->_globals as $fieldName => $fieldValue) { $queryParams[$fieldName . '.global'] = $fieldValue; } return $queryParams; }
/** * Parse the provided xml * * @param string $xml * @return FileMakerException|boolean * @throws FileMakerException */ public function parse($xml) { if (empty($xml)) { $error = new FileMakerException($this->_fm, 'Did not receive an XML document from the server.'); if ($this->_fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; } $this->_xmlParser = xml_parser_create('UTF-8'); xml_set_object($this->_xmlParser, $this); xml_parser_set_option($this->_xmlParser, XML_OPTION_CASE_FOLDING, false); xml_parser_set_option($this->_xmlParser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); xml_set_element_handler($this->_xmlParser, '_start', '_end'); xml_set_character_data_handler($this->_xmlParser, '_cdata'); if (!@xml_parse($this->_xmlParser, $xml)) { $error = new FileMakerException($this->_fm, sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_xmlParser)), xml_get_current_line_number($this->_xmlParser))); if ($this->_fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; } xml_parser_free($this->_xmlParser); if (!empty($this->_errorCode)) { $error = new FileMakerException($this->_fm, null, $this->_errorCode); if ($this->_fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; } if (version_compare($this->_serverVersion['version'], FileMaker::getMinServerVersion(), '<')) { $error = new FileMakerException($this->_fm, 'This API requires at least version ' . FileMaker::getMinServerVersion() . ' of FileMaker Server to run (detected ' . $this->_serverVersion['version'] . ').'); if ($this->_fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; } $this->_isParsed = true; return true; }
/** * 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); }
/** * 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; }
/** * 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; }
<pre><?php //header('Content-Type: text/plain'); //error_reporting(E_ALL); use airmoi\FileMaker\FileMaker; use airmoi\FileMaker\FileMakerException; use airmoi\FileMaker\FileMakerValidationException; require __DIR__ . '/../autoloader.php'; echo "==========================================" . PHP_EOL; echo " FILEMAKER API UNIT TEST" . PHP_EOL; echo "==========================================" . PHP_EOL . PHP_EOL; try { echo "------------------------------------------" . PHP_EOL; echo " Test FileMaker object's main methods" . PHP_EOL; echo "------------------------------------------" . PHP_EOL; $fm = new FileMaker('filemaker-test', 'localhost', 'filemaker', 'filemaker'); /* API infos */ echo "API version : " . $fm->getAPIVersion() . PHP_EOL; echo "Min server version : " . $fm->getMinServerVersion() . PHP_EOL . PHP_EOL; /* get databases list */ echo "Get databases list..."; $databases = $fm->listDatabases(); echo implode(', ', $databases) . '...<span style="color:green">SUCCESS</span>' . PHP_EOL . PHP_EOL; /* get layouts list */ echo "Get layouts list..."; $layouts = $fm->listLayouts(); if (sizeof($layouts) != 2) { echo '<span style="color:red">FAIL</span> !' . PHP_EOL; exit; } echo implode(', ', $layouts) . '...<span style="color:green">SUCCESS</span>' . PHP_EOL . PHP_EOL; /* get layouts list */
/** * 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 } } }