/**
  * Gets connected player
  * @param boolean $assertConnected Specifies if player has to be connected (throw excpeptoin if not 
  * @return Player The logged Player
  */
 public function getConnectedPlayer($assertConnected = true)
 {
     if (!isset(AuthenticationTool::$connectedPlayer)) {
         if ($assertConnected) {
             AuthenticationTool::getInstance()->assertPlayerConnected();
         }
         AuthenticationTool::$connectedPlayer = OsteoFactory::getElement('Player', SessionTool::getInstance()->getParameter(AuthenticationTool::SESSION_PLAYER_ID));
     }
     return AuthenticationTool::$connectedPlayer;
 }
Ejemplo n.º 2
0
 public function add()
 {
     // Sets encrypted password
     $this->salt = rand(10000, 99999);
     $this->password = $this->encryptPassword($this->password);
     parent::add();
     // Sets first game
     $playerStructure = new PlayerHasStructure();
     $playerStructure->player_id = $this->id;
     $playerStructure->structure_id = OsteoFactory::getElement('Structure', null, 'structure_category_id=7')->id;
     $playerStructure->add();
 }
Ejemplo n.º 3
0
    $quizz = array('structureId' => $structureId, 'questionList' => array());
    foreach ($questionList as $question) {
        $quizz['questionList'][] = array('questionId' => $question->id, 'answer' => null);
    }
    $quizz['isCraft'] = $isCraft;
    $quizz['startDate'] = DateTool::getTimestamp();
    $player->current_quizz = json_encode($quizz);
    $player->update();
    $currentQuestionIndex = 0;
    $currentQuestion = reset($questionList);
} else {
    if ($player->current_quizz) {
        $quizz = json_decode($player->current_quizz, true);
        foreach ($quizz['questionList'] as $questionNumber => $quizzQuestion) {
            if ($quizzQuestion['answer'] === null) {
                $currentQuestion = OsteoFactory::getElement('Question', $quizzQuestion['questionId']);
                $currentQuestionIndex = $questionNumber;
                break;
            }
        }
        // No questionwith no answer: test is over
        if (!isset($currentQuestion)) {
            RequestTool::redirect('/result.php');
        }
    } else {
        RequestTool::redirect('/');
    }
}
// Form submitted: check question answer
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $answerList = $currentQuestion->getAnswerList();
Ejemplo n.º 4
0
$errorList = array();
$login = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    try {
        $login = RequestTool::getParameter('login', RequestTool::PARAM_TYPE_ALPHANUM, true, null, RequestTool::METHOD_POST);
    } catch (ParameterException $e) {
        $errorList['login'] = AuthenticationTool::getLoginErrorMessage();
    }
    try {
        $password = RequestTool::getParameter('password', RequestTool::PARAM_TYPE_PASSWORD, true, null, RequestTool::METHOD_POST);
    } catch (ParameterException $e) {
        $errorList['login'] = AuthenticationTool::getLoginErrorMessage();
    }
    if (empty($errorList)) {
        try {
            $player = OsteoFactory::getElement('Player', null, 'player_login=\'' . $login . '\'');
            if ($player->password !== $player->encryptPassword($password)) {
                throw new ElementNoResultException();
            }
            AuthenticationTool::getInstance()->setConnectedPlayer($player->id);
            RequestTool::redirect('/');
        } catch (ElementNoResultException $e) {
            $errorList['login'] = AuthenticationTool::getLoginErrorMessage();
        }
    }
}
//$smarty->assign('javascript', array('manageQuestion'));
//$smarty->assign('css', array('manageElement'));
$smarty->assign('login', $login);
$smarty->assign('errorList', $errorList);
$smarty->assign('page', 'login');
Ejemplo n.º 5
0
            if (in_array($uploadedFileExtension, $availableExtensionList)) {
                $destinationFile = 'questions/question_' . $question->id . '.' . $uploadedFileExtension;
                $isUploaded = move_uploaded_file($imageFile['tmp_name'], IMAGE_PATH_FROM_ROOT . $destinationFile);
                if ($isUploaded) {
                    $question->image = IMAGE_PATH . $destinationFile;
                    $question->update();
                }
            }
        }
        if (empty($errorList)) {
            RequestTool::redirect('/admin/questionList.php');
        }
    }
} else {
    if ($questionId !== null) {
        $question = OsteoFactory::getElement('Question', $questionId);
    }
}
if (isset($question)) {
    $smarty->assign('question', $question->toArray(Osteo::FORMAT_ADMIN));
}
$questionCategoryList = OsteoFactory::getElementList('QuestionCategory');
$strucutreList = OsteoFactory::getElementList('Structure');
$smarty->assign('isEditMode', $questionId !== null);
$smarty->assign('submitText', $questionId !== null ? 'Mettre à jour' : 'Ajouter');
$smarty->assign('errorList', $errorList);
$smarty->assign('formAction', '/admin/manageQuestion.php' . ($questionId !== null ? '?questionId=' . $questionId : ''));
$smarty->assign('javascript', array('admin/manageQuestion'));
$smarty->assign('css', array('manageElement'));
$smarty->assign('questionCategoryList', Osteo::elementListToArray($questionCategoryList, Osteo::FORMAT_ADMIN));
$smarty->assign('structureList', Osteo::elementListToArray($strucutreList, Osteo::FORMAT_ADMIN));
Ejemplo n.º 6
0
            if (in_array($uploadedFileExtension, $availableExtensionList)) {
                $destinationFile = 'structures/structure_' . $structure->id . '.' . $uploadedFileExtension;
                $isUploaded = move_uploaded_file($imageFile['tmp_name'], IMAGE_PATH_FROM_ROOT . $destinationFile);
                if ($isUploaded) {
                    $structure->image = IMAGE_PATH . $destinationFile;
                    $structure->update();
                }
            }
            if (empty($errorList)) {
                RequestTool::redirect('/admin/structureList.php');
            }
        }
    }
} else {
    if ($structureId !== null) {
        $structure = OsteoFactory::getElement('Structure', $structureId);
    }
}
if (isset($structure)) {
    $smarty->assign('structure', $structure->toArray(Osteo::FORMAT_ADMIN));
}
$structureCategoryList = OsteoFactory::getElementList('StructureCategory');
$structureList = OsteoFactory::getElementList('Structure');
$smarty->assign('isEditMode', $structureId !== null);
$smarty->assign('submitText', $structureId !== null ? 'Mettre à jour' : 'Ajouter');
$smarty->assign('errorList', $errorList);
$smarty->assign('formAction', '/admin/manageStructure.php' . ($structureId !== null ? '?structureId=' . $structureId : ''));
$smarty->assign('javascript', array('admin/manageStructure'));
$smarty->assign('structureCategoryList', Osteo::elementListToArray($structureCategoryList, Osteo::FORMAT_ADMIN));
$smarty->assign('structureList', Osteo::elementListToArray($structureList, Structure::FORMAT_SIMPLE_LIST));
$smarty->assign('page', 'admin/manageStructure');
Ejemplo n.º 7
0
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    try {
        $login = RequestTool::getParameter('login', RequestTool::PARAM_TYPE_ALPHANUM, true, null, RequestTool::METHOD_POST);
        try {
            OsteoFactory::getElement('Player', null, 'player_login = \'' . $login . '\'');
            $errorList['login'] = '******';
        } catch (ElementNoResultException $e) {
            // Email not used, do nothing
        }
    } catch (ParameterException $e) {
        $errorList['login'] = '******';
    }
    try {
        $email = RequestTool::getParameter('email', RequestTool::PARAM_TYPE_EMAIL, true, null, RequestTool::METHOD_POST);
        try {
            OsteoFactory::getElement('Player', null, 'player_email = \'' . $email . '\'');
            $errorList['email'] = 'Adresse e-mail déjà utilisée';
        } catch (ElementNoResultException $e) {
            // Email not used, do nothing
        }
    } catch (ParameterException $e) {
        $errorList['email'] = 'Adresse e-mail incorrecte';
    }
    try {
        $password = RequestTool::getParameter('password', RequestTool::PARAM_TYPE_PASSWORD, true, null, RequestTool::METHOD_POST);
        $passwordConfirmation = RequestTool::getParameter('passwordConfirmation', RequestTool::PARAM_TYPE_PASSWORD, true, null, RequestTool::METHOD_POST);
        if ($password !== $passwordConfirmation) {
            $errorList['password'] = '******';
        }
    } catch (ParameterException $e) {
        $errorList['password'] = '******';
Ejemplo n.º 8
0
        if ($isUnlocked) {
            try {
                $newPlayerStructure = new PlayerHasStructure();
                $newPlayerStructure->player_id = $player->id;
                $newPlayerStructure->structure_id = $relatedStructure->structure_id;
                $newPlayerStructure->add();
            } catch (DatabaseDuplicateEntryException $e) {
                // Already in database
            }
        }
    }
}
if (!$quizz['isCraft']) {
    $questionDataList = array();
    foreach ($quizz['questionList'] as $questionData) {
        $question = OsteoFactory::getElement('Question', $questionData['questionId']);
        $questionDataList[] = $question->toArray(Question::FORMAT_RESULT, $questionData['answer']);
    }
    $smarty->assign('questionList', $questionDataList);
}
$smarty->assign('isCraft', $quizz['isCraft']);
$smarty->assign('isSuccess', $isSuccess);
$smarty->assign('previousBestScore', $previousBestScore);
$smarty->assign('previousBestTime', $previousBestTime);
$smarty->assign('isBestScore', $isBestScore);
$smarty->assign('isBestTime', $isBestTime);
$smarty->assign('correctAnswerNumber', $correctAnswerNumber);
$formattedTime = DateTool::timestampToString($time, DateTool::FORMAT_MINUTES);
if (StringTool::startsWith($formattedTime, '00m')) {
    $formattedTime = StringTool::truncateFirstChars($formattedTime, 4);
}