Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Validate/Barcode/Issn.php
Go to the documentation of this file.
00001 <?php
00025 require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
00026 
00033 class Zend_Validate_Barcode_Issn extends Zend_Validate_Barcode_AdapterAbstract
00034 {
00039     protected $_length = array(8, 13);
00040 
00045     protected $_characters = '0123456789X';
00046 
00051     protected $_checksum = '_gtin';
00052 
00059     public function checkChars($value)
00060     {
00061         if (strlen($value) != 8) {
00062             if (strpos($value, 'X') !== false) {
00063                 return false;
00064             }
00065         }
00066 
00067         return parent::checkChars($value);
00068     }
00069 
00076     public function checksum($value)
00077     {
00078         if (strlen($value) == 8) {
00079             $this->_checksum = '_issn';
00080         } else {
00081             $this->_checksum = '_gtin';
00082         }
00083 
00084         return parent::checksum($value);
00085     }
00086 
00094     protected function _issn($value)
00095     {
00096         $checksum = substr($value, -1, 1);
00097         $values   = str_split(substr($value, 0, -1));
00098         $check    = 0;
00099         $multi    = 8;
00100         foreach($values as $token) {
00101             if ($token == 'X') {
00102                 $token = 10;
00103             }
00104 
00105             $check += ($token * $multi);
00106             --$multi;
00107         }
00108 
00109         $check %= 11;
00110         $check  = 11 - $check;
00111         if ($check == $checksum) {
00112             return true;
00113         } else if (($check == 10) && ($checksum == 'X')) {
00114             return true;
00115         }
00116 
00117         return false;
00118     }
00119 }
 All Data Structures Namespaces Files Functions Variables Enumerations