source: Dev/trunk/classes/Loader.php @ 116

Last change on this file since 116 was 116, checked in by fpvanagthoven, 14 years ago

Some refactoring and commenting, plus, the questions within the categories in QuestionCreationTool? are now sorted aswell; on code.

File size: 2.0 KB
Line 
1<?php
2
3/**
4 * Helper class to load arrays of objects from the database.
5 *
6 * @author fpvanagthoven
7 */
8class Loader {
9
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
22    /**
23     *
24     * @return array Array of Surveys with id and title
25     */
26    public static function loadSurveys() {
27   
28        $surveyDBI = new SurveyCreationDatabaseInterface(null);
29        $surveyIDTitles = $surveyDBI->getExistingSurveys();
30
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");
53    }
54   
55    public static function loadFullQuestions() {
56        $questionDBI = new QuestionCreationDatabaseInterface();
57        $questionCodesAndTitles = $questionDBI->getExistingQuestions();
58       
59        $questions = array();
60       
61        foreach ($questionCodesAndTitles as $code => $title) {
62            $info = $questionDBI->getQuestionInfo($code);
63            $question = Question::getQuestion($code, $info);
64           
65            array_push($questions, $question);
66        }
67       
68        return $questions;
69    }
70
71}
72
73?>
Note: See TracBrowser for help on using the repository browser.