Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Validate/Barcode/Royalmail.php
Go to the documentation of this file.
00001 <?php
00025 require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
00026 
00033 class Zend_Validate_Barcode_Royalmail extends Zend_Validate_Barcode_AdapterAbstract
00034 {
00039     protected $_length = -1;
00040 
00045     protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
00046 
00047     protected $_rows = array(
00048         '0' => 1, '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1,
00049         '6' => 2, '7' => 2, '8' => 2, '9' => 2, 'A' => 2, 'B' => 2,
00050         'C' => 3, 'D' => 3, 'E' => 3, 'F' => 3, 'G' => 3, 'H' => 3,
00051         'I' => 4, 'J' => 4, 'K' => 4, 'L' => 4, 'M' => 4, 'N' => 4,
00052         'O' => 5, 'P' => 5, 'Q' => 5, 'R' => 5, 'S' => 5, 'T' => 5,
00053         'U' => 0, 'V' => 0, 'W' => 0, 'X' => 0, 'Y' => 0, 'Z' => 0,
00054      );
00055 
00056     protected $_columns = array(
00057         '0' => 1, '1' => 2, '2' => 3, '3' => 4, '4' => 5, '5' => 0,
00058         '6' => 1, '7' => 2, '8' => 3, '9' => 4, 'A' => 5, 'B' => 0,
00059         'C' => 1, 'D' => 2, 'E' => 3, 'F' => 4, 'G' => 5, 'H' => 0,
00060         'I' => 1, 'J' => 2, 'K' => 3, 'L' => 4, 'M' => 5, 'N' => 0,
00061         'O' => 1, 'P' => 2, 'Q' => 3, 'R' => 4, 'S' => 5, 'T' => 0,
00062         'U' => 1, 'V' => 2, 'W' => 3, 'X' => 4, 'Y' => 5, 'Z' => 0,
00063     );
00064 
00069     protected $_checksum = '_royalmail';
00070 
00077     protected function _royalmail($value)
00078     {
00079         $checksum = substr($value, -1, 1);
00080         $values   = str_split(substr($value, 0, -1));
00081         $rowvalue = 0;
00082         $colvalue = 0;
00083         foreach($values as $row) {
00084             $rowvalue += $this->_rows[$row];
00085             $colvalue += $this->_columns[$row];
00086         }
00087 
00088         $rowvalue %= 6;
00089         $colvalue %= 6;
00090 
00091         $rowchkvalue = array_keys($this->_rows, $rowvalue);
00092         $colchkvalue = array_keys($this->_columns, $colvalue);
00093         $chkvalue    = current(array_intersect($rowchkvalue, $colchkvalue));
00094         if ($chkvalue == $checksum) {
00095             return true;
00096         }
00097 
00098         return false;
00099     }
00100 
00107     public function checkChars($value)
00108     {
00109         if ($value[0] == '(') {
00110             $value = substr($value, 1);
00111 
00112             if ($value[strlen($value) - 1] == ')') {
00113                 $value = substr($value, 0, -1);
00114             } else {
00115                 return false;
00116             }
00117         }
00118 
00119         return parent::checkChars($value);
00120     }
00121 }
 All Data Structures Namespaces Files Functions Variables Enumerations