<?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';
 /**
  * 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, $data = null)
 {
     $array = array();
     switch ($format) {
         case Osteo::FORMAT_ADMIN:
             $array['id'] = $this->id;
             $array['text'] = $this->text;
             $array['imageUrl'] = $this->image;
             $array['isInCraftQuizz'] = $this->is_in_craft_quizz;
             $structure = $this->getParentStructure();
             $array['structureId'] = $this->structure_id;
             $array['structureName'] = $structure->name;
             $questionCategory = $this->getParentQuestionCategory();
             $array['categoryId'] = $questionCategory->id;
             $array['categoryName'] = $questionCategory->name;
             $answerList = $this->getAnswerList();
             $array['answerList'] = Osteo::elementListToArray($answerList, Osteo::FORMAT_ADMIN);
             break;
         case Question::FORMAT_GAME:
             $array['id'] = $this->id;
             $array['text'] = $this->text;
             $array['imageUrl'] = $this->image;
             $array['categoryId'] = $this->question_category_id;
             $answerList = $this->getAnswerList();
             $array['answerList'] = Osteo::elementListToArray($answerList, Osteo::FORMAT_ADMIN);
             // Additional information for question type
             switch ($this->question_category_id) {
                 // QCM
                 case 1:
                     $correctQuestionNumber = 0;
                     foreach ($answerList as $answer) {
                         if ($answer->is_correct) {
                             ++$correctQuestionNumber;
                         }
                     }
                     $array['correctQuestionNumber'] = $correctQuestionNumber;
                     break;
                     // Texte à trou
                 // Texte à trou
                 case 2:
                     $array['text'] = preg_replace('/<champ([0-9])+>/', '<input type="text" name="answer$1" class="form-control" autocomplete="off" />', $this->text);
                     break;
             }
             break;
         case Question::FORMAT_RESULT:
             $array['id'] = $this->id;
             $array['text'] = $this->text;
             $array['imageUrl'] = $this->image;
             $array['categoryId'] = $this->question_category_id;
             $answerList = $this->getAnswerList();
             $array['answerList'] = Osteo::elementListToArray($answerList, Osteo::FORMAT_ADMIN);
             $array['answerCorrect'] = $data;
             // Additional information for question type
             switch ($this->question_category_id) {
                 // QCM
                 case 1:
                     $correctQuestionNumber = 0;
                     foreach ($answerList as $answer) {
                         if ($answer->is_correct) {
                             ++$correctQuestionNumber;
                         }
                     }
                     $array['correctQuestionNumber'] = $correctQuestionNumber;
                     break;
                     // Texte à trou
                 // Texte à trou
                 case 2:
                     $answerReplace = array();
                     $answerMatch = array();
                     $fieldNumber = 1;
                     foreach ($answerList as $index => $answer) {
                         $answerReplace[] = '<span>' . $answer->text . '</span>';
                         $answerMatch[] = '<champ' . $fieldNumber++ . '>';
                         echo '<champ' . ($index + 1) . '>';
                     }
                     $array['text'] = str_replace($answerMatch, $answerReplace, $this->text);
                     break;
             }
             break;
     }
     return $array;
 }
Esempio n. 3
0
<?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';
Esempio n. 4
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');
                $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');
$smarty->display('admin/layout.tpl');
require_once 'init/end.inc.php';