/** * Generate a unique (at the time this function was called) pin. * * @returnint A random pin that was not in the database at the time this function was called. */ public function generateUniquePin() { // A loop hiting the database? Why not... $pin = 0; do { $pin = Pin::generatePin(); } while ($this->find('count', array('conditions' => array('Pin.pin' => $pin))) > 0); return $pin; }
/** * Generate a new pin record * * @param int $memberId The id of the member the pin belongs to. * @param int $joinTimestamp The time the pin was generated. */ private function __generatePin($memberId, $joinTimestamp) { $pinId = count($this->__pins) + 1; $pin = $this->__generateUniqueEntry($this->__pins, 'pin', function () { return Pin::generatePin(); }); $record = array('pin_id' => $pinId, 'pin' => $pin, 'date_added' => date("Y-m-d H:i:s", $joinTimestamp), 'expiry' => null, 'state' => 30, 'member_id' => $memberId); array_push($this->__pins, $record); }