public function setFields (array $fields)
    {
        $this->_fields = array();
        $this->_records = array();
        $prevLevel = null;
        foreach ($fields as $field) {
            $level = $field->getLevel();
            if ($level === 0) {
                $this->append($field);
            } else {
                if ($level === 1 && $prevLevel !== 1) {
                    $localRecord = new LocalRecord(array($field));
                    $this->addLocalRecord($localRecord);
                } else {
                    $records = $this->getLocalRecords();
                    // Handle malformed Pica record w/ missing local record field
                    if (empty($records)) {
                        $localRecord = new LocalRecord();
                        $this->addLocalRecord($localRecord);
                    } else {
                        $localRecord = end($records);
                    }
                    if ($level === 1) {
                        $localRecord->append($field);
                    } else {
                        $copyRecord = $localRecord->getCopyRecordByItemNumber($field->getOccurrence());
                        if ($copyRecord) {
                            $copyRecord->append($field);
                        } else {
                            $localRecord->addCopyRecord(new CopyRecord(array($field)));
                        }
                    }
                }
            }
            $prevLevel = $level;
        }
    }
public function setFields (array $fields)
    {
        $this->_fields = array();
        $this->_records = array();
        $prevLevel = null;
        foreach ($fields as $field) {
            $level = $field->getLevel();
            if ($level === 0) {
                $this->append($field);
            } else {
                if ($level === 1 && $prevLevel !== 1) {
                    $localRecord = new LocalRecord(array($field));
                    $this->addLocalRecord($localRecord);
                } else {
                    $records = $this->getLocalRecords();
                    // Handle malformed Pica record w/ missing local record field
                    if (empty($records)) {
                        $localRecord = new LocalRecord();
                        $this->addLocalRecord($localRecord);
                    } else {
                        $localRecord = end($records);
                    }
                    if ($level === 1) {
                        $localRecord->append($field);
                    } else {
                        $copyRecord = $localRecord->getCopyRecordByItemNumber($field->getOccurrence());
                        if ($copyRecord) {
                            $copyRecord->append($field);
                        } else {
                            $localRecord->addCopyRecord(new CopyRecord(array($field)));
                        }
                    }
                }
            }
            $prevLevel = $level;
        }
    }
public function setFields ( array $ fields ) { $ this -> _fields = array ( ) ; $ this -> _records = array ( ) ; $ prevLevel = null ; foreach ( $ fields as $ field ) { $ level = $ field -> getLevel ( ) ; if ( $ level === 0 ) { $ this -> append ( $ field ) ; } else { if ( $ level === 1 && $ prevLevel !== 1 ) { $ localRecord = new LocalRecord ( array ( $ field ) ) ; $ this -> addLocalRecord ( $ localRecord ) ; } else { $ records = $ this -> getLocalRecords ( ) ; // Handle malformed Pica record w/ missing local record field if ( empty ( $ records ) ) { $ localRecord = new LocalRecord ( ) ; $ this -> addLocalRecord ( $ localRecord ) ; } else { $ localRecord = end ( $ records ) ; } if ( $ level === 1 ) { $ localRecord -> append ( $ field ) ; } else { $ copyRecord = $ localRecord -> getCopyRecordByItemNumber ( $ field -> getOccurrence ( ) ) ; if ( $ copyRecord ) { $ copyRecord -> append ( $ field ) ; } else { $ localRecord -> addCopyRecord ( new CopyRecord ( array ( $ field ) ) ) ; } } } } $ prevLevel = $ level ; } }
Set the record's fields.

@todo   Relocate to \HAB\Pica\Record\Record::factory(), maybe

@param  array $fields Field
@return void
Set the record s fields .