public function create($quantity, $uid) { $numbers = new Ml_Model_Numbers(); $tokens = array(); for ($counter = 0; $counter < $quantity; $counter++) { //not beautiful $partialFirst = $numbers->baseEncode(mt_rand(36 * 36 + 1, 36 * 36 * 36), "qwertyuiopasdfghjklzxcvbnm0123456789"); $partialSecond = $numbers->baseEncode(mt_rand(31 * 31 + 1, 31 * 31 * 31), "qwrtyuopasdghjklzcvnm123456789"); $tokens[] = $partialFirst . '-' . $partialSecond; } $escapeUid = $this->_dbAdapter->quoteInto("?", $uid); if (!empty($tokens)) { $querystring = "INSERT IGNORE INTO `" . $this->_dbTable->getTableName() . "` (`uid`, `hash`) VALUES "; do { $line = '(' . $escapeUid . ', ' . $this->_dbAdapter->quoteInto("?", current($tokens)) . ')'; $querystring .= $line; next($tokens); if (current($tokens)) { $querystring .= ", "; } } while (current($tokens)); $this->_dbAdapter->query($querystring); } return $tokens; }
/** * Makes a pseudo-uniquely ID * * Format: * x-y-z * * whereas: * x - time portion * y - random number * z - check digit * * There's a collision chance that must be avoided * with integrity check where necessary. * */ public static function makeUUId() { $numbers = new Ml_Model_Numbers(); $lowerLimit = pow(29, 3); //==2111 $upperLimit = pow(29, 4) - 1; //==ZZZZ $timeDivisor = 2.5; $ptime = (int) ((int) $_SERVER['REQUEST_TIME'] / $timeDivisor); $rand1 = mt_rand($lowerLimit, $upperLimit); $rand2 = mt_rand($lowerLimit, $upperLimit); $num1 = $numbers->baseEncode($ptime, self::base); $num2 = $numbers->baseEncode($rand1, self::base); $num3 = $numbers->baseEncode($rand2, self::base); $uuid = $num1 . $num2 . $num3 . Ml_Model_Verhoeff::calcsum($ptime . $rand1 . $rand2); return $uuid; }