protected function updateMetadatas(\record_adapter $record, $xml)
    {
        $metas = $record->getDatabox()->get_meta_structure();

        $datas = $metadatas = [];

        if (false !== $sxe = simplexml_load_string($xml)) {
            $fields = $sxe->xpath('/record/description');
            if ($fields && is_array($fields)) {
                foreach ($fields[0] as $fieldname => $value) {
                    $fieldname = trim($fieldname);
                    $value = trim($value);

                    if (null === $databox_field = $metas->get_element_by_name($fieldname)) {
                        continue;
                    }

                    if ($databox_field->is_multi()) {

                        $new_value = \caption_field::get_multi_values($value, $databox_field->get_separator());
                        if (isset($datas[$databox_field->get_id()])) {
                            $value = array_unique(array_merge($datas[$databox_field->get_id()], $new_value));
                        } else {
                            $value = $new_value;
                        }
                    } else {
                        $new_value = $value;
                        if (isset($datas[$databox_field->get_id()])) {
                            $value = $datas[$databox_field->get_id()] . ' ' . $new_value;
                        } else {
                            $value = $new_value;
                        }
                    }

                    $datas[$databox_field->get_id()] = $value;
                }
            }
        }

        foreach ($datas as $meta_struct_id => $values) {
            if (is_array($values)) {
                foreach ($values as $value) {
                    $metadatas[] = [
                        'meta_struct_id' => $meta_struct_id
                        , 'meta_id'        => null
                        , 'value'          => $value
                    ];
                }
            } else {
                $metadatas[] = [
                    'meta_struct_id' => $meta_struct_id
                    , 'meta_id'        => null
                    , 'value'          => $values
                ];
            }
        }

        $record->set_metadatas($metadatas, true);
    }
protected function updateMetadatas(\record_adapter $record, $xml)
    {
        $metas = $record->getDatabox()->get_meta_structure();

        $datas = $metadatas = [];

        if (false !== $sxe = simplexml_load_string($xml)) {
            $fields = $sxe->xpath('/record/description');
            if ($fields && is_array($fields)) {
                foreach ($fields[0] as $fieldname => $value) {
                    $fieldname = trim($fieldname);
                    $value = trim($value);

                    if (null === $databox_field = $metas->get_element_by_name($fieldname)) {
                        continue;
                    }

                    if ($databox_field->is_multi()) {

                        $new_value = \caption_field::get_multi_values($value, $databox_field->get_separator());
                        if (isset($datas[$databox_field->get_id()])) {
                            $value = array_unique(array_merge($datas[$databox_field->get_id()], $new_value));
                        } else {
                            $value = $new_value;
                        }
                    } else {
                        $new_value = $value;
                        if (isset($datas[$databox_field->get_id()])) {
                            $value = $datas[$databox_field->get_id()] . ' ' . $new_value;
                        } else {
                            $value = $new_value;
                        }
                    }

                    $datas[$databox_field->get_id()] = $value;
                }
            }
        }

        foreach ($datas as $meta_struct_id => $values) {
            if (is_array($values)) {
                foreach ($values as $value) {
                    $metadatas[] = [
                        'meta_struct_id' => $meta_struct_id
                        , 'meta_id'        => null
                        , 'value'          => $value
                    ];
                }
            } else {
                $metadatas[] = [
                    'meta_struct_id' => $meta_struct_id
                    , 'meta_id'        => null
                    , 'value'          => $values
                ];
            }
        }

        $record->set_metadatas($metadatas, true);
    }
protected function updateMetadatas ( \ record_adapter $ record , $ xml ) { $ metas = $ record -> getDatabox ( ) -> get_meta_structure ( ) ; $ datas = $ metadatas = [ ] ; if ( false !== $ sxe = simplexml_load_string ( $ xml ) ) { $ fields = $ sxe -> xpath ( '/record/description' ) ; if ( $ fields && is_array ( $ fields ) ) { foreach ( $ fields [ 0 ] as $ fieldname => $ value ) { $ fieldname = trim ( $ fieldname ) ; $ value = trim ( $ value ) ; if ( null === $ databox_field = $ metas -> get_element_by_name ( $ fieldname ) ) { continue ; } if ( $ databox_field -> is_multi ( ) ) { $ new_value = \ caption_field :: get_multi_values ( $ value , $ databox_field -> get_separator ( ) ) ; if ( isset ( $ datas [ $ databox_field -> get_id ( ) ] ) ) { $ value = array_unique ( array_merge ( $ datas [ $ databox_field -> get_id ( ) ] , $ new_value ) ) ; } else { $ value = $ new_value ; } } else { $ new_value = $ value ; if ( isset ( $ datas [ $ databox_field -> get_id ( ) ] ) ) { $ value = $ datas [ $ databox_field -> get_id ( ) ] . ' ' . $ new_value ; } else { $ value = $ new_value ; } } $ datas [ $ databox_field -> get_id ( ) ] = $ value ; } } } foreach ( $ datas as $ meta_struct_id => $ values ) { if ( is_array ( $ values ) ) { foreach ( $ values as $ value ) { $ metadatas [ ] = [ 'meta_struct_id' => $ meta_struct_id , 'meta_id' => null , 'value' => $ value ] ; } } else { $ metadatas [ ] = [ 'meta_struct_id' => $ meta_struct_id , 'meta_id' => null , 'value' => $ values ] ; } } $ record -> set_metadatas ( $ metadatas , true ) ; }
Update the metadatas of a record

@param \record_adapter $record
@param string          $xml
Update the metadatas of a record