Don't like ads? PRO users don't see any ads ;-)
Guest

quiz module

By: a guest on May 7th, 2012  |  syntax: None  |  size: 4.83 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. /**
  4.  * Project Vakbibliotheek - Home Controller
  5.  *
  6.  * @author Tommy Laureyns
  7.  *
  8.  */
  9.  
  10. class QuizController extends PlonkController {
  11.  
  12.         /**
  13.          * The views allowed for this module
  14.          * @var array
  15.          */    
  16.         protected $views = array(
  17.             'create',
  18.             'join',
  19.             'quiz'
  20.         );
  21.  
  22.        
  23.         /**
  24.          * The actions allowed for this module
  25.          * @var array
  26.          */
  27.         protected $actions = array(
  28.                'create'
  29.         );
  30.        
  31.        
  32.  
  33.         public function __construct() {
  34.            
  35.         }
  36.  
  37.         /**
  38.          * Our default view
  39.          * @return
  40.          */
  41.         public function showCreate()
  42.         {
  43.             if (!PlonkSession::exists('id')) {
  44.                 PlonkWebsite::redirect('index.php?module=login');
  45.             }
  46.             $this->mainTpl->assignOption('oLogout');
  47.             $this->mainTpl->assign('pageTitle',                   'Create Quiz');
  48.             $this->mainTpl->assign('pageMeta',          '
  49.                 <link rel="stylesheet" type="text/css" href="modules/quiz/css/create.css" />
  50.                 <script src="Core/js/jquerylibrary.js" type="text/javascript"></script>
  51.                 <script src="Core/js/script.js" type="text/javascript"></script>
  52.             ');
  53.            
  54.            
  55.             $this->processErrors();
  56.         }
  57.        
  58.        
  59.         public function doCreate() {
  60.             if (PlonkFilter::getPostValue('submitQuiz')) {
  61.                 $allOk = true;
  62.                 $title = PlonkFilter::getPostValue('quizTitle');
  63.                 $code = PlonkFilter::getPostValue('quizCode');
  64.                 $codeConf = PlonkFilter::getPostValue('quizCodeConf');
  65.                 $description = PlonkFilter::getPostValue('quizDescription');
  66.                
  67.                 $allOk = $this->checkQuizFilledIn($title, $code, $codeConf, $description);
  68.                
  69.                 if ($code != $codeConf) {
  70.                     $allOk = false;
  71.                     $this->formErrors[] = "Code and code confirmation must be the same.";
  72.                 }
  73.                
  74.                 //no questions
  75.                 if (PlonkFilter::getPostValue('question_1') === null) {
  76.                     $allOk = false;
  77.                     $this->formErrors[] = "Please fill in at least 1 question";
  78.                 }
  79.                
  80.                 //Plonk::dump($_POST);
  81.             }
  82.            
  83.         }
  84.        
  85.        
  86.        
  87.         public function showJoin() {
  88.             $this->mainTpl->assign('pageTitle',                   'Join Quiz');
  89.             $this->mainTpl->assign('pageMeta',          '<link rel="stylesheet" type="text/css" href="modules/quiz/css/join.css" />');
  90.         }
  91.        
  92.         public function showQuiz() {
  93.             if (!PlonkSession::exists('id')) {
  94.                 $this->mainTpl->assignOption('oLogin');
  95.             }
  96.             else {
  97.                 $this->mainTpl->assignOption('oLogout');
  98.             }
  99.            
  100.             $this->mainTpl->assign('pageTitle',                   'Quiz-It!');
  101.             $this->mainTpl->assign('pageMeta',          '<link rel="stylesheet" type="text/css" href="modules/quiz/css/quiz.css" />');
  102.            
  103.         }
  104.        
  105.        
  106.         private $formErrors = array();
  107.  
  108.                 /**
  109.          * Processes the errors
  110.          */
  111.         public function processErrors() {
  112.  
  113.                 // Ooh, we've got errors
  114.                 if (sizeof($this->formErrors) > 0) {
  115.  
  116.                         // assign the option
  117.                         $this->pageTpl->assignOption('oErrors');
  118.  
  119.                         // set the iteration
  120.                         $this->pageTpl->setIteration('iErrors');
  121.  
  122.                         // loop all items and store 'm into the template iteration
  123.                         foreach ($this->formErrors as $error) {
  124.  
  125.                                 // assign vars
  126.                                 $this->pageTpl->assignIteration('error', $error);
  127.  
  128.                                 // refill iteration
  129.                                 $this->pageTpl->refillIteration();
  130.  
  131.                         }
  132.  
  133.                         // parse iteration
  134.                         $this->pageTpl->parseIteration();
  135.  
  136.                 }
  137.         }
  138.        
  139.        
  140.         public function checkQuizFilledIn($title, $code, $codeConf, $description) {
  141.             $allOk = true;
  142.            
  143.             if ($title === null || $code === null || $codeConf === null || $description === null) {
  144.                     $this->formErrors[] = "Not everything is filled in.";
  145.                    
  146.                     if ($title === null) {
  147.                         $this->formErrors[] = "Please fill in a title.";
  148.                     }
  149.                     if ($code === null) {
  150.                         $this->formErrors[] = "Please fill in a code.";
  151.                     }
  152.                     if ($codeConf === null) {
  153.                         $this->formErrors[] = "Please fill in a code confirmation.";
  154.                     }
  155.                     if ($description === null) {
  156.                         $this->formErrors[] = "Please fill in a description.";
  157.                     }
  158.                     $allOk = false;
  159.                 }
  160.                 return $allOk;
  161.         }
  162.  
  163. }
  164.  
  165. // EOF