Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Editing the fields and full documentation #13

Open
yfhui opened this issue Aug 15, 2019 · 2 comments
Open

Feature Request: Editing the fields and full documentation #13

yfhui opened this issue Aug 15, 2019 · 2 comments

Comments

@yfhui
Copy link

yfhui commented Aug 15, 2019

This plug in is excellent, but can we have a documentation for this plugin, or some example for us to read? So that it makes us easier to use

Other than that, I hope that this plug can provide interface for us to edit the fields. This plug in will be perfect if this function is implemented.

Hopefully I am not mistakenly missed those feature and actually they had existed in the plug in.

@danmichaelo
Copy link
Member

danmichaelo commented Aug 16, 2019

Hi @huiyunfung

Editing is indeed possible using File_MARC, but I agree that it should be documented. Here's an example to get you started:

<?php

require('vendor/autoload.php');

use Scriptotek\Marc\Record;

$source = '<?xml version="1.0" encoding="UTF-8" ?>
  <record xmlns="http://www.loc.gov/MARC21/slim">
    <leader>99999cam a2299999 u 4500</leader>
    <controlfield tag="001">98218834x</controlfield>
    <datafield tag="020" ind1=" " ind2=" ">
      <subfield code="a">8200424421</subfield>
      <subfield code="q">h.</subfield>
      <subfield code="c">Nkr 98.00</subfield>
    </datafield>
  </record>';

$record = Record::fromString($source);

$field = $record->query('020')->first();  // instance of Scriptotek\Marc\Fields\Field, wrapper for File_MARC_Data_Field

// Deleting a subfield
$subfield = $field->getSubfield('q');   // instance of File_MARC_Subfield
$field->deleteSubfield($subfield);

// Updating a subfield
$subfield = $field->getSubfield('c');   // instance of File_MARC_Subfield
$subfield->setData('New value');

// Adding a subfield
$newSubfield = new File_MARC_Subfield('9', 'Local value');
$field->appendSubfield($newSubfield);

echo $record->toXML();

For more options, I recommend checking out the source code of File_MARC (vendor/pear/file_marc). It comes with a few examples, and the source code is very well documented.

@reza0770
Copy link

What are the other methods of the record class? You have given XML as an example, but what are the rest of the methods? Especially those that convert into binary marc?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants