/** * This method returns an object based upon the specified MODE or NULL if at end of file. * * Return Classes: * * if MODE_READ_FIELD * returns \DCarbone\AmberHat\Record\RecordFieldInterface * * if MODE_READ_RECORD * returns \DCarbone\AmberHat\Record\Record * * @return mixed */ public function read() { if ($this->_position === self::POS_END_OF_DOC) { return null; } if ($this->_mode === self::MODE_READ_RECORD) { $record = new Record(); } /** @var RecordField $field */ $field = null; while ($line = fgets($this->_fh)) { xml_parse($this->_parser, ValueUtility::utf8ByteFix($line)); switch ($this->_position) { // This will be reached during multi-line field value parsing. case self::POS_IN_FIELD: continue 2; // Typically speaking, fields will be on a single line. // However, in the event of multi-line notes content or the like, // we do NOT want to create an item per-line. // Typically speaking, fields will be on a single line. // However, in the event of multi-line notes content or the like, // we do NOT want to create an item per-line. case self::POS_END_OF_FIELD: $field = new RecordField($this->_recordID, $this->_formName, $this->_fieldName, $this->_fieldValue, $this->_redcapEventName, $this->_getMetadataItem($this->_fieldName)); // Reset stored field values. $this->_recordID = null; $this->_redcapEventName = null; $this->_fieldName = null; $this->_fieldValue = null; // We will be 1 loop behind until we've // reached the end of the document. if (null === $this->_previousField) { $field->firstFieldInRecord = true; $this->_previousField = $field; $field = null; continue 2; } if ($this->_mode === self::MODE_READ_FIELD) { $returnField = $this->_previousField; $this->_previousField = $field; return $returnField; } // We're still collecting fields for this record... if ($field->recordID === $this->_previousField->recordID && $field->redcapEventName === $this->_previousField->redcapEventName) { $record[] = $this->_previousField; $this->_previousField = $field; $field = null; continue 2; } // If we've reached here, we are at a new record. $this->_previousField->lastFieldInRecord = true; $field->firstFieldInRecord = true; $record->recordID = $this->_previousField->recordID; $record->formName = $this->_formName; $record[] = $this->_previousField; $this->_previousField = $field; return $record; case self::POS_END_OF_DOC: if (null === $this->_previousField) { return null; } $this->_previousField->lastFieldInRecord = true; if ($this->_mode === self::MODE_READ_FIELD) { return $this->_previousField; } $record[] = $this->_previousField; return $record; } } return null; }
/** * Returns string usable by PHP's date functions, null if the format is not matched, * or FALSE if this is not a date field. * * @param string $fieldValue * @return false|null|string */ public function getDateTimeFormatString($fieldValue) { if (!is_string($fieldValue) || '' === $fieldValue) { return null; } if (false === $this->_dateFormatSought) { if ($this->isDateTimeField()) { $this->_dateTimeFormatString = ValueUtility::getFieldDateTimeFormatString($fieldValue); } else { $this->_dateTimeFormatString = false; } $this->_dateFormatSought = true; } return $this->_dateTimeFormatString; }