/classes/BiblioField.php

https://bitbucket.org/mstetson/obiblio/ · PHP · 156 lines · 120 code · 6 blank · 30 comment · 16 complexity · 8379ddb3f10260356426687664463bd6 MD5 · raw file

  1. <?php
  2. /* This file is part of a copyrighted work; it is distributed with NO WARRANTY.
  3. * See the file COPYRIGHT.html for more details.
  4. */
  5. require_once("../classes/Localize.php");
  6. /******************************************************************************
  7. * UsmarcField represents a library bibliography subfield. Contains business rules for
  8. * subfield data validation.
  9. *
  10. * @author David Stevens <dave@stevens.name>;
  11. * @version 1.0
  12. * @access public
  13. ******************************************************************************
  14. */
  15. class BiblioField {
  16. var $_bibid = "";
  17. var $_fieldid = "";
  18. var $_tag = "";
  19. var $_tagError = "";
  20. var $_ind1Cd = "";
  21. var $_ind2Cd = "";
  22. var $_subfieldCd = "";
  23. var $_subfieldCdError = "";
  24. var $_fieldData = "";
  25. var $_fieldDataError = "";
  26. var $_isRequired = false;
  27. var $_isRepeatable = false;
  28. /****************************************************************************
  29. * @return boolean true if data is valid, otherwise false.
  30. * @access public
  31. ****************************************************************************
  32. */
  33. function validateData() {
  34. $loc = new Localize(OBIB_LOCALE,"classes");
  35. $valid = true;
  36. if (($this->_isRequired ) and ($this->_fieldData == "")) {
  37. $valid = false;
  38. $this->_fieldDataError = $loc->getText("biblioFieldError1");
  39. }
  40. if ($this->_tag == "") {
  41. $valid = false;
  42. $this->_tagError = $loc->getText("biblioFieldError1");
  43. } else if (!is_numeric($this->_tag)) {
  44. $valid = false;
  45. $this->_tagError = $loc->getText("biblioFieldError2");
  46. }
  47. if ($this->_subfieldCd == "") {
  48. $valid = false;
  49. $this->_subfieldCdError = $loc->getText("biblioFieldError1");
  50. }
  51. unset($loc);
  52. return $valid;
  53. }
  54. /****************************************************************************
  55. * Getter methods for all fields
  56. * @return string
  57. * @access public
  58. ****************************************************************************
  59. */
  60. function getBibid() {
  61. return $this->_bibid;
  62. }
  63. function getFieldid() {
  64. return $this->_fieldid;
  65. }
  66. function getTag() {
  67. return $this->_tag;
  68. }
  69. function getTagError() {
  70. return $this->_tagError;
  71. }
  72. function getInd1Cd() {
  73. return $this->_ind1Cd;
  74. }
  75. function getInd2Cd() {
  76. return $this->_ind2Cd;
  77. }
  78. function getSubfieldCd() {
  79. return $this->_subfieldCd;
  80. }
  81. function getSubfieldCdError() {
  82. return $this->_subfieldCdError;
  83. }
  84. function getFieldData() {
  85. return $this->_fieldData;
  86. }
  87. function getFieldDataError() {
  88. return $this->_fieldDataError;
  89. }
  90. function isRequired() {
  91. if ($this->_isRequired) {
  92. return true;
  93. } else {
  94. return false;
  95. }
  96. }
  97. function isRepeatable() {
  98. if ($this->_isRepeatable) {
  99. return true;
  100. } else {
  101. return false;
  102. }
  103. }
  104. /****************************************************************************
  105. * Setter methods for all fields
  106. * @param string $value new value to set
  107. * @return void
  108. * @access public
  109. ****************************************************************************
  110. */
  111. function setBibid($value) {
  112. $this->_bibid = trim($value);
  113. }
  114. function setFieldid($value) {
  115. $this->_fieldid = trim($value);
  116. }
  117. function setTag($value) {
  118. $this->_tag = trim($value);
  119. }
  120. function setInd1Cd($value) {
  121. $this->_ind1Cd = substr(trim($value),0,1);
  122. }
  123. function setInd2Cd($value) {
  124. $this->_ind2Cd = substr(trim($value),0,1);
  125. }
  126. function setSubfieldCd($value) {
  127. $this->_subfieldCd = substr(trim($value),0,1);
  128. }
  129. function setFieldData($value) {
  130. $this->_fieldData = trim($value);
  131. }
  132. function setFieldDataError($value) {
  133. $this->_fieldDataError = trim($value);
  134. }
  135. function setIsRequired($value) {
  136. if ($value) {
  137. $this->_isRequired = true;
  138. } else {
  139. $this->_isRequired = false;
  140. }
  141. }
  142. function setIsRepeatable($value) {
  143. if ($value) {
  144. $this->_isRepeatable = true;
  145. } else {
  146. $this->_isRepeatable = false;
  147. }
  148. }
  149. }
  150. ?>