Itf14.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Barcode
  17. * @subpackage Object
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** @see Zend_Barcode_Object_Int25 */
  23. require_once 'Zend/Barcode/Object/Int25.php';
  24. /** @see Zend_Validate_Barcode */
  25. require_once 'Zend/Validate/Barcode.php';
  26. /**
  27. * Class for generate Itf14 barcode
  28. *
  29. * @category Zend
  30. * @package Zend_Barcode
  31. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class Zend_Barcode_Object_Itf14 extends Zend_Barcode_Object_Int25
  35. {
  36. /**
  37. * @var $_barcodeLength integer | string
  38. */
  39. protected $_barcodeLength = 14;
  40. /**
  41. * Constructor
  42. * @param array|Zend_Config $options
  43. * @return void
  44. */
  45. public function __construct($options = null)
  46. {
  47. parent::__construct($options);
  48. // Checksum is mandatory with Itf14
  49. $this->_withChecksum = true;
  50. // Default to true but not mandatory
  51. $this->_withChecksumInText = true;
  52. }
  53. /**
  54. * Activate/deactivate the automatic generation
  55. * of the checksum character
  56. * added to the barcode text
  57. * @param boolean $value
  58. * @return Zend_Barcode_Object
  59. */
  60. public function setWithChecksum($value)
  61. {
  62. // Checksum is mandatory with Itf14
  63. return $this;
  64. }
  65. /**
  66. * Activate/deactivate the automatic generation
  67. * of the checksum character
  68. * added to the barcode text
  69. * @param boolean $value
  70. * @return Zend_Barcode_Object
  71. * @throw Zend_Barcode_Object_Exception
  72. */
  73. public function setWithChecksumInText($value)
  74. {
  75. return $this;
  76. }
  77. /**
  78. * Retrieve text to encode
  79. * @return string
  80. */
  81. public function getText()
  82. {
  83. $text = $this->_getTextWithChecksum();
  84. if (strlen($text) < 14) {
  85. $text = str_repeat('0', 14 - strlen($text)) . $text;
  86. }
  87. return $text;
  88. }
  89. /**
  90. * Retrieve text to display
  91. * @return string
  92. */
  93. public function getTextToDisplay()
  94. {
  95. return $this->getText();
  96. }
  97. /**
  98. * Check allowed characters
  99. * @param string $value
  100. * @return string
  101. * @throw Zend_Barcode_Object_Exception
  102. */
  103. public function validateText($value)
  104. {
  105. $this->_validateText($value, array('automaticPrepend' => 0, 'substituteChecksumCharacter' => 0));
  106. }
  107. }