/**
  * 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;
 }
 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();
 }
<?php

require_once '../../init/initAdmin.inc.php';
OsteoFactory::getElementList('StructureCategory');
$structureList = OsteoFactory::getElementList('Structure');
//$smarty->assign('javascript', array('manageQuestion'));
//$smarty->assign('css', array('manageElement'));
$smarty->assign('structureList', Osteo::elementListToArray($structureList, Osteo::FORMAT_ADMIN));
$smarty->assign('page', 'admin/structureList');
$smarty->display('admin/layout.tpl');
require_once 'init/end.inc.php';
Example #4
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();
Example #5
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');
Example #6
0
<?php

require_once '../init/init.inc.php';
//$smarty->assign('javascript', array('manageQuestion'));
//$smarty->assign('css', array('manageElement'));
$smarty->assign('page', 'index');
if (AuthenticationTool::getInstance()->isPlayerConnected()) {
    OsteoFactory::getElementList('Component');
    $structureList = OsteoFactory::getElementList('Structure', null, 'structure_category_order, structure_order ASC', 'structure LJ player_has_structure, structure_category IJ structure');
    $smarty->assign('structureList', Osteo::elementListToArray($structureList, Structure::FORMAT_PLAYER_STRUCTURE_LIST));
    $componentList = OsteoFactory::getElementList('Component');
    $smarty->assign('componentList', Osteo::elementListToArray($componentList, Component::FORMAT_PLAYER_COMPONENT_LIST));
}
$scoreDataList = Structure::getDatabaseConnection()->selectRequest('SELECT player_name, SUM(is_crafted) AS crafted, SUM(best_score) AS score, SUM(best_time) AS time FROM player INNER JOIN player_has_structure ON player.player_id = player_has_structure.player_id GROUP BY player.player_id ORDER BY crafted DESC, score DESC, time ASC LIMIT 10');
$scoreList = array();
foreach ($scoreDataList as $scoreData) {
    if (!$scoreData['time']) {
        $formattedTime = '-';
    } else {
        $formattedTime = DateTool::timestampToString($scoreData['time'], DateTool::FORMAT_MINUTES);
        if (StringTool::startsWith($formattedTime, '00m')) {
            $formattedTime = StringTool::truncateFirstChars($formattedTime, 4);
        }
        if (StringTool::startsWith($formattedTime, '0')) {
            $formattedTime = StringTool::truncateFirstChars($formattedTime, 1);
        }
    }
    $scoreList[] = array('player_name' => $scoreData['player_name'], 'crafted' => $scoreData['crafted'], 'score' => $scoreData['score'], 'time' => $formattedTime);
}
$smarty->assign('scoreList', $scoreList);
$smarty->display('layout.tpl');
<?php

require_once '../../init/initAdmin.inc.php';
OsteoFactory::getElementList('QuestionCategory');
$structureList = OsteoFactory::getElementList('Structure');
$structureId = RequestTool::getParameter('structureId', RequestTool::PARAM_TYPE_UNSIGNED_INT, false, null);
$questionList = OsteoFactory::getElementList('Question', $structureId !== null ? 'structure_id=' . $structureId : null);
//$smarty->assign('javascript', array('manageQuestion'));
//$smarty->assign('css', array('manageElement'));
$smarty->assign('structureList', Osteo::elementListToArray($structureList, Osteo::FORMAT_ADMIN));
$smarty->assign('questionList', Osteo::elementListToArray($questionList, Osteo::FORMAT_ADMIN));
$smarty->assign('currentUrl', RequestTool::getCurrentURL(false));
$smarty->assign('page', 'admin/questionList');
$smarty->display('admin/layout.tpl');
require_once 'init/end.inc.php';
Example #8
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'] = '******';
Example #9
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);
}