Permalink
Browse files

Add isControlField() and isDataField() convenience methods to File_MA…

…RC_Field

git-svn-id: https://svn.php.net/repository/pear/packages/File_MARC/trunk@276438 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 5df49d9 commit a28d8f3efec95edb2d3e1c76dd8da3469f7ecddd Dan Scott committed Feb 25, 2009
Showing with 143 additions and 7 deletions.
  1. +3 −0 CHANGELOG
  2. +35 −0 MARC/Field.php
  3. +8 −7 package.xml
  4. +97 −0 tests/marc_012.phpt
View
@@ -1,3 +1,6 @@
+0.2.3-beta
+* Handle single-record MARC21XML files with "record" as the root element
+
0.1.1-alpha
* Add File_MARC_Record::toXML() method for generating MARCXML output
* Add File_MARCXML class for reading MARCXML source
View
@@ -142,6 +142,41 @@ function isEmpty()
}
// }}}
+ // {{{ isControlField()
+ /**
+ * Is control field
+ *
+ * Checks if the field is a control field.
+ *
+ * @return bool Returns true if the field is a control field, otherwise false
+ */
+ function isControlField()
+ {
+ if (get_class($this) == 'File_MARC_Control_Field') {
+ return true;
+ }
+ return false;
+ }
+ // }}}
+
+ // {{{ isDataField()
+ /**
+ * Is data field
+ *
+ * Checks if the field is a data field.
+ *
+ * @return bool Returns true if the field is a data field, otherwise false
+ */
+ function isDataField()
+ {
+ if (get_class($this) == 'File_MARC_Data_Field') {
+ return true;
+ }
+ return false;
+ }
+ // }}}
+
+
/**
* ========== OUTPUT METHODS ==========
*/
View
@@ -19,21 +19,19 @@ This package is based on the PHP MARC package, originally called "php-marc", tha
<email>dbs@php.net</email>
<active>yes</active>
</lead>
- <date>2008-10-30</date>
+ <date>2009-02-25</date>
<version>
- <release>0.2.2</release>
- <api>0.2.0</api>
+ <release>0.3.0</release>
+ <api>0.3.0</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">GNU Lesser General Public License</license>
<notes>
-0.2.2-beta
-* Address PEAR Coding Standard violations (mostly whitespace) - closes bug# 14923
-* Include MARCFLAT.php in distribution package
-* Update copyright dates
+0.3.0-beta
+* Add isControlField() and isDataField() convenience methods to File_MARC_Field
</notes>
<contents>
<dir name="/" baseinstalldir="File">
@@ -70,6 +68,7 @@ This package is based on the PHP MARC package, originally called "php-marc", tha
<file name="marc_009.phpt" role="test" />
<file name="marc_010.phpt" role="test" />
<file name="marc_011.phpt" role="test" />
+ <file name="marc_012.phpt" role="test" />
<file name="marc_field_001.phpt" role="test" />
<file name="marc_field_002.phpt" role="test" />
<file name="marc_field_003.phpt" role="test" />
@@ -80,7 +79,9 @@ This package is based on the PHP MARC package, originally called "php-marc", tha
<file name="marc_xml_002.phpt" role="test" />
<file name="marc_xml_003.phpt" role="test" />
<file name="marc_xml_004.phpt" role="test" />
+ <file name="marc_xml_005.phpt" role="test" />
<file name="music.mrc" role="test" />
+ <file name="onerecord.xml" role="test" />
<file name="sandburg.mrc" role="test" />
<file name="sandburg.xml" role="test" />
<file name="xmlescape.mrc" role="test" />
View
@@ -0,0 +1,97 @@
+--TEST--
+marc_012: test isControlField() and isDataField() convenience methods
+--FILE--
+<?php
+$dir = dirname(__FILE__);
+require 'File/MARC.php';
+$marc_file = new File_MARC($dir . '/' . 'music.mrc');
+
+while ($marc_record = $marc_file->next()) {
+ $fields = $marc_record->getFields();
+ foreach ($fields as $field) {
+ print $field->getTag();
+ if ($field->isControlField()) {
+ print "\tControl field!";
+ }
+ if ($field->isDataField()) {
+ print "\tData field!";
+ }
+ print "\n";
+ }
+}
+
+?>
+--EXPECT--
+001 Control field!
+004 Control field!
+005 Control field!
+008 Control field!
+010 Data field!
+035 Data field!
+035 Data field!
+040 Data field!
+050 Data field!
+245 Data field!
+260 Data field!
+300 Data field!
+500 Data field!
+505 Data field!
+650 Data field!
+650 Data field!
+700 Data field!
+700 Data field!
+700 Data field!
+740 Data field!
+852 Data field!
+001 Control field!
+005 Control field!
+007 Control field!
+008 Control field!
+024 Data field!
+028 Data field!
+035 Data field!
+040 Data field!
+100 Data field!
+245 Data field!
+260 Data field!
+300 Data field!
+511 Data field!
+500 Data field!
+518 Data field!
+500 Data field!
+500 Data field!
+505 Data field!
+650 Data field!
+700 Data field!
+710 Data field!
+740 Data field!
+001 Control field!
+005 Control field!
+007 Control field!
+008 Control field!
+024 Data field!
+028 Data field!
+033 Data field!
+033 Data field!
+033 Data field!
+033 Data field!
+035 Data field!
+040 Data field!
+048 Data field!
+110 Data field!
+245 Data field!
+260 Data field!
+300 Data field!
+440 Data field!
+511 Data field!
+518 Data field!
+500 Data field!
+500 Data field!
+505 Data field!
+650 Data field!
+700 Data field!
+700 Data field!
+700 Data field!
+700 Data field!
+700 Data field!
+852 Data field!

0 comments on commit a28d8f3

Please sign in to comment.