From bf0d32465588f81edded48d3ec3cdd58cfe07cd8 Mon Sep 17 00:00:00 2001 From: oliver Date: Sat, 12 Mar 2016 15:56:32 +0100 Subject: [PATCH] move method to create random hashes to Utils-class --- app/Utils.inc | 25 ++++++++++++++++++++ models/CharactergroupsqueststationsModel.inc | 24 +------------------ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/app/Utils.inc b/app/Utils.inc index 401fea8c..0aae181b 100644 --- a/app/Utils.inc +++ b/app/Utils.inc @@ -19,6 +19,14 @@ */ class Utils { + /** + * String length for hashes + * + * @var int + */ + const HASH_LENGTH = 10; + + /** @@ -209,6 +217,23 @@ return $mimetype; } + + /** + * Create a random hash string. + * + * @param int Length of string + * @return string String with random characters + */ + public static function createRandomHash($length=self::HASH_LENGTH) + { + // Length of URL + $length = max(0, min(32, $length)); + + + // Create and return random string + return substr(md5(microtime()), rand(0, 32-$length), $length); + } + } ?> diff --git a/models/CharactergroupsqueststationsModel.inc b/models/CharactergroupsqueststationsModel.inc index a90ffc95..ef719eee 100644 --- a/models/CharactergroupsqueststationsModel.inc +++ b/models/CharactergroupsqueststationsModel.inc @@ -38,12 +38,6 @@ * @var int; */ const STATUS_SOLVED = 3; - /** - * String length for Station URLs - * - * @var int - */ - const URL_LENGTH = 10; /** * Required models @@ -487,7 +481,7 @@ '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', 'iississddss', $questId, $stationtypeId, $title, - $this->createStationUrl(), $pos, + \hhu\z\Utils::createRandomHash(), $pos, $prolog, $task, $latitude, $longitude, $righttext, $wrongtext ); @@ -630,22 +624,6 @@ ); } - - /** - * Generate a URL for Stations with random characters. - * - * @return string A string with random characters - */ - private function createStationUrl() - { - // Length of URL - $length = max(0, min(32, self::URL_LENGTH)); - - - // Create and return random string - return substr(md5(microtime()), rand(0, 32-$length), $length); - } - } ?>