/**
  * Return the maximum number of guesses a client may submit.
  *
  * @return int Maximum number of guesses.
  *
  * @throws Exception Throws if an error occurred.
  */
 public static function getMaximumGuessesPerClient()
 {
     return (int) Registry::getValue('client.maxEntries')->getValue();
 }
Example #2
0
/**
 * Get the key of the current client session.
 *
 * @return string Session key
 *
 * @throws Exception Throws if an error occurred.
 */
function getSessionKey()
{
    // Return the key from the globals if set
    if (isset($GLOBALS['session_key'])) {
        return $GLOBALS['session_key'];
    }
    // Get the session cookie name
    $sessionCookieName = Registry::getValue('client.session.cookie.name')->getValue();
    // Get the session key
    $sessionKey = CookieManager::getCookie($sessionCookieName);
    // Set the session key global
    $GLOBALS['session_key'] = $sessionKey;
    // Return the session key
    return $sessionKey;
}
 /**
  * Delete this registry value permanently.
  *
  * @throws Exception Throws if an error occurred.
  */
 public function delete()
 {
     // Prepare a query for the being deleted
     $statement = Database::getPDO()->prepare('DELETE FROM ' . Registry::getDatabaseTableName() . ' WHERE registry_id=:id');
     $statement->bindValue(':id', $this->getId(), PDO::PARAM_INT);
     // Execute the prepared query
     if (!$statement->execute()) {
         throw new Exception('Failed to query the database.');
     }
 }
 /**
  * Get a registry value by it's keys.
  *
  * @param string $key The key.
  *
  * @return RegistryValue|null The registry value as object, or null if no was found.
  *
  * @throws Exception Throws if an error occurred.
  */
 public static function getValue($key)
 {
     // Trim the key
     // TODO: Parse the registry key
     $key = trim($key);
     // Make sure a value exists for this registry with this key
     if (!static::isValueWithKey($key)) {
         return null;
     }
     // Prepare a query for the database to list registrys with this ID
     $statement = Database::getPDO()->prepare('SELECT registry_id FROM ' . Registry::getDatabaseTableName() . ' WHERE registry_key=:registry_key');
     $statement->bindValue(':registry_key', $key, PDO::PARAM_STR);
     // Execute the prepared query
     if (!$statement->execute()) {
         throw new Exception('Failed to query the database.');
     }
     // Return the as object
     return new RegistryValue($statement->fetch(PDO::FETCH_ASSOC)['registry_id']);
 }