Ejemplo n.º 1
0
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');
require_once 'init/end.inc.php';
 /**
  * Gets property value in correct format for request
  * @param string $propertyName The name of the property to detect field type
  * @param string $propertyValue The property value
  * @return string the value in correct format for the request
  */
 private static function getFormattedPropertyValue($elementClass, $propertyName, $propertyValue)
 {
     // NULL value
     if ($propertyValue === null) {
         $formattedValue = 'NULL';
     } else {
         $formattedValue = '\'';
         if (StringTool::isInt($propertyValue)) {
             // Datetime / date property type
             if (StringTool::endsWith($propertyName, 'date')) {
                 $formattedValue .= DateTool::timestampToString($propertyValue);
             } else {
                 $formattedValue .= StringTool::toInt($propertyValue, FALSE);
             }
         } else {
             if (StringTool::isFloat($propertyValue, FALSE)) {
                 $formattedValue .= StringTool::toFloat($propertyValue, FALSE);
             } else {
                 $formattedValue .= $elementClass::getDatabaseConnection()->realEscapeString($propertyValue);
             }
         }
         $formattedValue .= '\'';
     }
     return $formattedValue;
 }
Ejemplo n.º 3
0
            }
        }
    }
}
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);
}
if (StringTool::startsWith($formattedTime, '0')) {
    $formattedTime = StringTool::truncateFirstChars($formattedTime, 1);
}
$smarty->assign('totalTime', $formattedTime);
$smarty->assign('totalQuestionNumber', count($quizz['questionList']));
$smarty->assign('page', 'score');
$smarty->display('layout.tpl');
require_once 'init/end.inc.php';