public function genHash($id = null) { if (is_null($id)) { $recipients = Campaign::getRecipients($this->getGroup()); foreach ($recipients as $recipient) { do { $hash = sha1(uniqid($this->getId(), true)); $hash = substr($hash, 0, 20); $sql = 'INSERT INTO campaign_hash SET user_id="' . e($recipient->getId()) . '", campaign_id="' . e($this->getId()) . '", hash="' . e($hash) . '"'; $result = Database::singleton()->query($sql); } while (!$result); } } else { $recipient = new CampaignUser($id); do { $hash = sha1(uniqid($this->getId(), true)); $hash = substr($hash, 0, 20); $sql = 'INSERT INTO campaign_hash SET user_id="' . e($recipient->getId()) . '", campaign_id="' . e($this->getId()) . '", hash="' . e($hash) . '"'; $result = Database::singleton()->query($sql); } while (!$result); } }