Changeset 56 for Dev/trunk/classes


Ignore:
Timestamp:
07/26/11 17:19:26 (14 years ago)
Author:
fpvanagthoven
Message:

Stubs and some refactoring

Location:
Dev/trunk/classes
Files:
2 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/classes/Survey.php

    r35 r56  
    11<?php
    2 
    32/*
    43 * To change this template, choose Tools | Templates
     
    1211 */
    1312class Survey {
     13
    1414    public $id;
    1515    public $title;
    1616    public $description;
    1717    public $questions;
    18    
    19     public function __construct($id, $title, $description = null)
    20     {
     18
     19    public function __construct($id, $title, $description = null) {
    2120        $this->id = $id;
    2221        $this->title = $title;
     
    2423        $this->questions = array();
    2524    }
    26    
    27     public static function getSurvey($info)
    28     {
     25
     26    public static function getSurvey($info) {
    2927        $id = $info['surveyID'];
    3028        $title = $info['surveyTitle'];
    3129        $description = $info['surveyDescription'];
    32        
     30
    3331        $survey = new Survey($id, $title, $description);
    34        
     32
    3533        $numQ = 1; //number questions
    36         while (isset($info['questionTitle' . $numQ]))
    37         {
     34        while (isset($info['questionTitle' . $numQ])) {
    3835            $id = $info['questionID' . $numQ];
    3936            $title = $info['questionTitle' . $numQ];
    4037            $type = $info['questionType' . $numQ];
    4138            $description = $info['questionDescription' . $numQ];
    42                    
     39
    4340            $question = new Question($id, $title, $type, $description);
    4441
    4542            $numA = 1; //number answers
    46             while (isset($info['q' . $numQ . 'ans' . $numA]))
    47             {
     43            while (isset($info['q' . $numQ . 'ans' . $numA])) {
    4844                $answer = $info['q' . $numQ . 'ans' . $numA];
    4945                $question->answers[$numA] = $answer;
    50                
     46
    5147                $numA++;
    5248            }
    53            
    54            
     49
     50
    5551            $survey->questions[$numQ] = $question;
    56            
     52
    5753            $numQ++;
    5854        }
    59        
     55
    6056        return $survey;
    6157    }
    62    
     58
     59    public static function newSurveyButton() {
     60        ?>
     61
     62        <form action="surveycreation.php" method="post">
     63
     64            <input type="submit" value="Create new survey" class="surveyButton bigSurveyButton" />
     65
     66        </form>
     67
     68        <?php
     69    }
     70
     71    /**
     72     *
     73     * @param Survey $surveys An array of surveys
     74     */
     75    public static function loadSurveyButton($surveys) {
     76        ?>
     77        <form id="loadForm" action="surveycreation.php" method="post">
     78            <input type="button" onclick="loadSurvey()" value="Load survey" class="surveyButton bigSurveyButton" />
     79        </form>
     80        <br/>
     81        <select id="surveysToLoad" size="1000">
     82            <?php
     83            foreach ($surveys as $survey) {
     84                ?><option value='<?php echo $survey->id; ?>'><?php echo $survey->title; ?></option><?php
     85        }
     86            ?>
     87        </select>
     88        <?php
     89    }
     90
    6391}
    64 
    6592?>
Note: See TracChangeset for help on using the changeset viewer.