Changeset 112


Ignore:
Timestamp:
09/19/11 16:29:02 (14 years ago)
Author:
fpvanagthoven
Message:

Code to get questions and put them in objects

Location:
Dev/trunk
Files:
7 edited

Legend:

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

    r85 r112  
    88class Loader {
    99
     10    public static function load($info, $classname) {
     11        $theArray = array();
     12       
     13        foreach ($info as $id => $title)
     14        {
     15            $object = new $classname($id, $title);
     16            array_push($theArray, $object);
     17        }
     18       
     19        return $theArray;
     20    }
     21
    1022    /**
    1123     *
     
    1325     */
    1426    public static function loadSurveys() {
    15         $surveys = array();
    16 
     27   
    1728        $surveyDBI = new SurveyCreationDatabaseInterface(null);
    1829        $surveyIDTitles = $surveyDBI->getExistingSurveys();
    1930
    20         foreach ($surveyIDTitles as $id => $title) {
    21             $survey = new Survey($id, $title);
    22             array_push($surveys, $survey);
    23         }
    24        
    25         return $surveys;
     31        return Loader::load($surveyIDTitles, "Survey");
     32    }
     33
     34    public static function loadApplications() {
     35        $applicationDBI = new ApplicationDatabaseInterface(null);
     36        $applicationTitles = $applicationDBI->getExistingApplications();
     37
     38        return Loader::load($applicationTitles, "Application");
     39    }
     40
     41    public static function loadSessions() {
     42        $sessionDBI = new SessionCreationDatabaseInterface(null);
     43        $sessionTitles = $sessionDBI->getExistingSessions();
     44
     45        return Loader::load($sessionTitles, "Session");
     46    }
     47
     48    public static function loadQuestions() {
     49        $questionDBI = new QuestionCreationDatabaseInterface();
     50        $questionCodesAndTitles = $questionDBI->getExistingQuestions();
     51
     52        return Loader::load($questionCodesAndTitles, "Question");
    2653    }
    2754   
    28     public static function loadApplications()
    29     {
    30         $applications = array();
     55    public static function loadFullQuestions() {
     56        $questionDBI = new QuestionCreationDatabaseInterface();
     57        $questionCodesAndTitles = $questionDBI->getExistingQuestions();
    3158       
    32         $applicationDBI = new ApplicationDatabaseInterface(null);
    33         $applicationTitles = $applicationDBI->getExistingApplications();
     59        $questions = array();
    3460       
    35         foreach ($applicationTitles as $id => $title) {
    36             $application = new Application($id, $title);
    37             array_push($applications, $application);
     61        foreach ($questionCodesAndTitles as $code => $title) {
     62            $info = $questionDBI->getQuestionInfo($code);
     63           
    3864        }
    39        
    40         return $applications;
    41     }
    42    
    43     public static function loadSessions()
    44     {
    45         $sessions = array();
    46        
    47         $sessionDBI = new SessionCreationDatabaseInterface(null);
    48         $sessionTitles = $sessionDBI->getExistingSessions();
    49        
    50         foreach ($sessionIDTitles as $id => $title) {
    51             $session = new Application($id, $title);
    52             array_push($sessions, $session);
    53         }
    54        
    55         return $sessions;
    5665    }
    5766
  • Dev/trunk/classes/Question.php

    r98 r112  
    1111 * @author fpvanagthoven
    1212 */
    13 class Question {
    14     public $id;
     13class Question {   
    1514    public $code;
    1615    public $title;
     
    1817    public $description;
    1918    public $answers; // format answers['#']
     19    public $category;
    2020   
    21     public function __construct($id, $code, $title, $type, $description = null)
     21    public function __construct($code, $title, $type = null, $description = null)
    2222    {
    23         $this->id = $id;
    2423        $this->code = $code;
    2524        $this->title = $title;
     
    2827        $this->answers = array();
    2928    }
     29   
     30    /* reminder that constructor doesn't contain category haha */
     31    public function setCategory($category)
     32    {
     33        $this->category = $category;
     34    }
     35   
     36    public static function getQuestion($questionInfo)
     37    {
     38       
     39    }
    3040
    3141}
  • Dev/trunk/classes/QuestionCreationDatabaseInterface.php

    r110 r112  
    5454    public function getQuestionInfo($qCode)
    5555    {
    56         $questionInfo - array();
     56        $questionInfo = array();
    5757       
    5858        $questionTitleObject = $this->questionRDFReader->readQuestionTitle($qCode);
     
    7777            }
    7878        }
     79       
     80        return $questionInfo;
    7981    }
    8082   
  • Dev/trunk/classes/QuestionCreationTool.php

    r108 r112  
    244244                categoryBox.appendChild(categoryInput);
    245245            }
    246                                                                    
     246                       
     247            function clearFields()
     248            {
     249                clearCategory();
     250                clearCode();
     251                clearTitle();
     252                clearDescription();
     253                clearType();
     254            }
     255           
     256            function clearCategory()
     257            {
     258                var categoryBox = document.getElementById("categoryBox");
     259                categoryBox.innerHTML = "";
     260               
     261                var questionCategorySelect = document.createElement("select");
     262                questionCategorySelect.setAttribute("name", "questionCategory");
     263                questionCategorySelect.id = "questionCategorySelect";
     264               
     265                var newCategoryButton = document.createElement("input");
     266                newCategoryButton.setAttribute("type", "button");
     267                newCategoryButton.setAttribute("onclick", "newCategory()");
     268                newCategoryButton.setAttribute("value", "New Category");
     269                newCategoryButton.className = "surveyButton";
     270               
     271                categoryBox.appendChild(questionCategorySelect);
     272                categoryBox.appendChild(newCategoryButton);
     273            }
     274           
     275            function clearCode()
     276            {
     277                var codeInput = document.getElementById("questionCode");
     278                codeInput.value = "";
     279            }
     280           
     281            function clearTitle()
     282            {
     283                var titleInput = document.getElementById("questionTitle");
     284                titleInput.value ="";
     285            }
     286           
     287            function clearDescription()
     288            {
     289                var descriptionInput = document.getElementById("questionDescription");
     290                descriptionInput.value = "";
     291            }
     292           
     293            function clearType()
     294            {
     295                var typeSelect = document.getElementById("questionTypeSelect");
     296                typeSelect.selectedIndex = 0;
     297            }
     298           
    247299        </script>
    248300        <?php
     
    273325                    <td><label for="questionCategory">Category</label></td>
    274326                    <td id="categoryBox"><!-- Select should be filled with existing categories-->
    275                         <select name="questionCategory">
     327                        <select id="questionCategorySelect" name="questionCategory">
    276328                            <option value='Test Category'>Test Category</option>
    277329                        </select>
     
    295347                    <td><label for="questionType">Type answer</label></td>
    296348                    <td id="questionType">
    297                         <select name="questionType" onchange="handleType(this)">
     349                        <select id="questionTypeSelect" name="questionType" onchange="handleType(this)">
    298350                            <option value='text' selected='selected'>Text</option>
    299351                            <option value='int'>Integer</option>
     
    306358            </table>
    307359            <div id="answerSpecifications"></div>
     360            <input id="clearQuestionFields" type="button" onclick="clearFields()" class="surveyButton" value="Clear" />
    308361            <input id="saveQuestion" type="submit" class="surveyButton" value="Save" />
    309362        </form>
  • Dev/trunk/css/awesome.css

    r104 r112  
    441441    top: 1em;
    442442    right: 1em;
     443}
     444
     445#clearQuestionFields {
     446    position: absolute;
     447    top: 1em;
     448    right: 5em;
    443449}
    444450
  • Dev/trunk/mainmenu.php

    r102 r112  
    2727$surveys = Loader::loadSurveys();
    2828$applications = Loader::loadApplications();
    29 
    3029?>
    3130
  • Dev/trunk/questioncreation.php

    r107 r112  
    11<?php
    22require 'classes/master.php';
    3 
    4 $questionDBI = new QuestionCreationDatabaseInterface();
    53
    64/* If a question is saved */
    75if(isset($_POST['questionCode']))
    86{
     7    $questionDBI = new QuestionCreationDatabaseInterface();
    98    echo $questionDBI->setQuestionInfo($_POST); // save to DB
    109}
    1110
    12 $existingQuestions = $questionDBI->getExistingQuestions();
    13 var_dump($existingQuestions);
     11$questions = Loader::loadQuestions();
     12var_dump($questions);
     13
     14//$dbi = new QuestionCreationDatabaseInterface();
     15//$info = $dbi->getQuestionInfo("testcode1");
     16
     17//var_dump($info);
    1418
    1519?>
     
    3236                <?php var_dump($_POST); ?>
    3337                <?php
    34                     new QuestionCreationTool();
     38                    new QuestionCreationTool($questions);
    3539                ?>
    3640            </div>
Note: See TracChangeset for help on using the changeset viewer.