move method to create random hashes to Utils-class
This commit is contained in:
parent
60036ea794
commit
bf0d324655
2 changed files with 26 additions and 23 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Reference in a new issue