_withChecksum = true; // Default to true but not mandatory $this->_withChecksumInText = true; } /** * Activate/deactivate the automatic generation * of the checksum character * added to the barcode text * @param boolean $value * @return Zend_Barcode_Object */ public function setWithChecksum($value) { // Checksum is mandatory with Itf14 return $this; } /** * Activate/deactivate the automatic generation * of the checksum character * added to the barcode text * @param boolean $value * @return Zend_Barcode_Object * @throw Zend_Barcode_Object_Exception */ public function setWithChecksumInText($value) { return $this; } /** * Retrieve text to encode * @return string */ public function getText() { $text = $this->_getTextWithChecksum(); if (strlen($text) < 14) { $text = str_repeat('0', 14 - strlen($text)) . $text; } return $text; } /** * Retrieve text to display * @return string */ public function getTextToDisplay() { return $this->getText(); } /** * Check allowed characters * @param string $value * @return string * @throw Zend_Barcode_Object_Exception */ public function validateText($value) { $validator = new Zend_Validate_Barcode(array( 'adapter' => 'itf14', 'checksum' => false, )); // prepend '0' if (strlen($value) < 13) { $value = str_repeat('0', 13 - strlen($value)) . $value; } // add a '0' because checksum is mandatory if (!$validator->isValid($value . '0')) { $message = implode("\n", $validator->getMessages()); /** * @see Zend_Barcode_Object_Exception */ require_once 'Zend/Barcode/Object/Exception.php'; throw new Zend_Barcode_Object_Exception($message); } } }