/** * 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; }
/** * Gets an array representing current element * @param string $format The format to use to convert element to array * @return array The array */ public function &toArray($format) { $array = array(); switch ($format) { case Component::FORMAT_PLAYER_COMPONENT_LIST: case Structure::FORMAT_PLAYER_STRUCTURE_LIST: $array['id'] = $this->id; $array['name'] = $this->name; $array['codeName'] = $this->code_name; $playerComponent = $this->getPlayerHasComponentList('player_id = ' . AuthenticationTool::getInstance()->getConnectedPlayer()->id); if (count($playerComponent) > 0) { $playerComponent = reset($playerComponent); $array['quantity'] = $playerComponent->quantity; } else { $array['quantity'] = 0; } break; } return $array; }
<?php // Starts session before header is sent session_start(); require_once 'globals/globals.php'; require_once 'core/functions.php'; // init Smarty require_once 'smarty.inc.php'; // Gets class_loader require_once 'class_loader.inc.php'; // Gets error handler require_once 'error_handler.inc.php'; SystemTool::$context = SystemTool::CONTEXT_AJAX; // starts transaction DatabaseFactory::startTransaction(); $authenticationInstance = AuthenticationTool::getInstance(); $isPlayerConnected = $authenticationInstance->isPlayerConnected(); // TODO: Checks that player has access to the admin part
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'); $smarty->display('layout.tpl'); require_once 'init/end.inc.php';
/** * Gets an array representing current element * @param string $format The format to use to convert element to array * @return array The array */ public function &toArray($format) { $array = array(); switch ($format) { case Structure::FORMAT_SIMPLE_LIST: $array['id'] = $this->id; $array['name'] = $this->name; break; case Osteo::FORMAT_ADMIN: $array['id'] = $this->id; $array['name'] = $this->name; $array['questionNumber'] = $this->question_number; $array['totalQuestionNumber'] = count($this->getQuestionList()); $array['craftQuestionNumber'] = count($this->getQuestionList('question_is_in_craft_quizz=1')); $category = $this->getParentStructureCategory(); $array['categoryId'] = $category->id; $array['categoryName'] = $category->name; $array['componentName'] = $category->getParentComponent()->name; $array['order'] = $this->order; $array['componentQuantity'] = $this->component_quantity; $array['imageUrl'] = $this->image; $requiredStructureList = $this->getStructureRequiredStructureList(); $array['requiredStructureList'] = array(); $array['requiredStructureIdList'] = array(); foreach ($requiredStructureList as $requiredStructure) { $array['requiredStructureList'][] = $requiredStructure->getParentRequired_structure()->toArray(Structure::FORMAT_SIMPLE_LIST); $array['requiredStructureIdList'][] = $requiredStructure->required_structure_id; } break; case Structure::FORMAT_PLAYER_STRUCTURE_LIST: $array['id'] = $this->id; $array['name'] = $this->name; $array['order'] = $this->order; $array['image'] = $this->image; $playerStructure = $this->getPlayerHasStructureList('player_id = ' . AuthenticationTool::getInstance()->getConnectedPlayer()->id); $category = $this->getParentStructureCategory(); $array['categoryId'] = $category->id; $array['categoryName'] = $category->name; $array['categoryCodeName'] = $category->code_name; $array['isCraftable'] = count($this->getQuestionList('question_is_in_craft_quizz=1')) > 0; $array['isPlayable'] = count($this->getQuestionList()) > 0; $array['componentQuantity'] = $this->component_quantity; $array['component'] = $category->getParentComponent()->toArray(Structure::FORMAT_PLAYER_STRUCTURE_LIST); if (count($playerStructure) > 0) { $playerStructure = reset($playerStructure); $array['isAvailable'] = true; $array['bestScore'] = $playerStructure->best_score; $array['isCrafted'] = $playerStructure->is_crafted; $array['hasPlayed'] = $playerStructure->best_time > 0; } else { $array['isAvailable'] = false; $array['isCrafted'] = false; // Gets missing structures } if (!$array['isAvailable']) { $requiredStructureList = $this->getStructureRequiredStructureList(); $array['requiredStructureList'] = array(); $array['requiredStructureIdList'] = array(); foreach ($requiredStructureList as $requiredStructure) { $array['requiredStructureList'][] = $requiredStructure->getParentRequired_structure()->toArray(Structure::FORMAT_SIMPLE_LIST); $array['requiredStructureIdList'][] = $requiredStructure->required_structure_id; } } break; } return $array; }
<?php require_once '../init/init.inc.php'; AuthenticationTool::getInstance()->logout(); RequestTool::redirect('/'); require_once 'init/end.inc.php';
<?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');