- <?php
- /**
- * Project Vakbibliotheek - Home Controller
- *
- * @author Tommy Laureyns
- *
- */
- class QuizController extends PlonkController {
- /**
- * The views allowed for this module
- * @var array
- */
- protected $views = array(
- 'create',
- 'join',
- 'quiz'
- );
- /**
- * The actions allowed for this module
- * @var array
- */
- protected $actions = array(
- 'create'
- );
- public function __construct() {
- }
- /**
- * Our default view
- * @return
- */
- public function showCreate()
- {
- if (!PlonkSession::exists('id')) {
- PlonkWebsite::redirect('index.php?module=login');
- }
- $this->mainTpl->assignOption('oLogout');
- $this->mainTpl->assign('pageTitle', 'Create Quiz');
- $this->mainTpl->assign('pageMeta', '
- <link rel="stylesheet" type="text/css" href="modules/quiz/css/create.css" />
- <script src="Core/js/jquerylibrary.js" type="text/javascript"></script>
- <script src="Core/js/script.js" type="text/javascript"></script>
- ');
- $this->processErrors();
- }
- public function doCreate() {
- if (PlonkFilter::getPostValue('submitQuiz')) {
- $allOk = true;
- $title = PlonkFilter::getPostValue('quizTitle');
- $code = PlonkFilter::getPostValue('quizCode');
- $codeConf = PlonkFilter::getPostValue('quizCodeConf');
- $description = PlonkFilter::getPostValue('quizDescription');
- $allOk = $this->checkQuizFilledIn($title, $code, $codeConf, $description);
- if ($code != $codeConf) {
- $allOk = false;
- $this->formErrors[] = "Code and code confirmation must be the same.";
- }
- //no questions
- if (PlonkFilter::getPostValue('question_1') === null) {
- $allOk = false;
- $this->formErrors[] = "Please fill in at least 1 question";
- }
- //Plonk::dump($_POST);
- }
- }
- public function showJoin() {
- $this->mainTpl->assign('pageTitle', 'Join Quiz');
- $this->mainTpl->assign('pageMeta', '<link rel="stylesheet" type="text/css" href="modules/quiz/css/join.css" />');
- }
- public function showQuiz() {
- if (!PlonkSession::exists('id')) {
- $this->mainTpl->assignOption('oLogin');
- }
- else {
- $this->mainTpl->assignOption('oLogout');
- }
- $this->mainTpl->assign('pageTitle', 'Quiz-It!');
- $this->mainTpl->assign('pageMeta', '<link rel="stylesheet" type="text/css" href="modules/quiz/css/quiz.css" />');
- }
- private $formErrors = array();
- /**
- * Processes the errors
- */
- public function processErrors() {
- // Ooh, we've got errors
- if (sizeof($this->formErrors) > 0) {
- // assign the option
- $this->pageTpl->assignOption('oErrors');
- // set the iteration
- $this->pageTpl->setIteration('iErrors');
- // loop all items and store 'm into the template iteration
- foreach ($this->formErrors as $error) {
- // assign vars
- $this->pageTpl->assignIteration('error', $error);
- // refill iteration
- $this->pageTpl->refillIteration();
- }
- // parse iteration
- $this->pageTpl->parseIteration();
- }
- }
- public function checkQuizFilledIn($title, $code, $codeConf, $description) {
- $allOk = true;
- if ($title === null || $code === null || $codeConf === null || $description === null) {
- $this->formErrors[] = "Not everything is filled in.";
- if ($title === null) {
- $this->formErrors[] = "Please fill in a title.";
- }
- if ($code === null) {
- $this->formErrors[] = "Please fill in a code.";
- }
- if ($codeConf === null) {
- $this->formErrors[] = "Please fill in a code confirmation.";
- }
- if ($description === null) {
- $this->formErrors[] = "Please fill in a description.";
- }
- $allOk = false;
- }
- return $allOk;
- }
- }
- // EOF