Ignore:
Timestamp:
10/24/11 13:47:23 (14 years ago)
Author:
jkraaijeveld
Message:

Added support for questions and users

Location:
Dev/branches/jos-branch/classes
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/jos-branch/classes/Application.php

    r128 r130  
    1414    public function __construct($uid = null, $title = null, $description = null, $style = null)
    1515    {
     16        if(!isset ($uid))
     17        {
     18            $uid = md5(uniqid(rand(), true));
     19        }
    1620        $this->uid = $uid;
    1721        $this->title = $title;
     
    1923        $this->style = $style;
    2024    }
    21    
    22     public static function getApplication($info)
    23     {
    24         return new Application(
    25                 $info['applicationID'],
    26                 $info['applicationTitle'],
    27                 $info['applicationDescription'],
    28                 $info['applicationStyle']);
    29     }
    3025
    3126}
  • Dev/branches/jos-branch/classes/ApplicationConnector.php

    r128 r130  
    6161        //Set the arguments if they are supplied
    6262        if(in_array("uid", $keys))
    63             $uid = "\"".$arguments["id"]."\"";
     63            $uid = "\"".$arguments["uid"]."\"";
    6464        if(in_array("title", $keys))
    6565            $title = '\''.$arguments["title"].'\'';
     
    8181                                        predicates:description ?description ;
    8282                                        predicates:style ?style ;
    83                                         predicates:uid ' . $uid . '
     83                                        predicates:uid ' . $uid . '
    8484                                        predicates:title ' . $title . '
    8585                                        predicates:description ' . $description . '
    86                                         predicates:style ' . $style . ' 
     86                                        predicates:style ' . $style . '
    8787            }';
    8888
    8989        //Query the model
    9090        $results = $this->model->sparqlQuery($querystring);
    91                 if(!empty($results))
    92                         {
    93                         $applications = array();
    94                         //Run over all results and create appropriate Application objets
    95                         foreach($results as $result)
    96                         {
    97                                 $applications[] = new Application($result['?uid']->label, $result['?title']->label, $result['?description']->label, $result['?style']->label);
    98                         }
    99                         //Return the list of application objects
    100                         return $applications;
    101                 }
    102                 else
    103                 {
    104                         return array();
    105                 }
     91        $applications = array();
     92        if(!empty($results))
     93        {
     94            //Run over all results and create appropriate Application objets
     95            foreach($results as $result)
     96            {
     97                    $applications[] = new Application($result['?uid']->label, $result['?title']->label, $result['?description']->label, $result['?style']->label);
     98            }
     99        }
     100        return $applications;
    106101    }
    107102   
     
    114109    public function set($rToolObject)
    115110    {
     111        $this->load();
    116112        $resourceApplication = new Resource(APPLICATION.'/'.$rToolObject->uid);
    117                 //Remove the old value stored with the given id
    118                 $this->model->subtract($this->model->find($resourceApplication, null, null));
    119                
    120                 //Add the new statements to the model
     113        //Remove the old value stored with the given id
     114        $this->model->subtract($this->model->find($resourceApplication, null, null));
     115
     116        //Add the new statements to the model
    121117        $resourceApplicationType = new Resource(APPLICATION);
    122118        $predicateRType = new Resource(RTYPE);
     
    139135        $this->model->add(new Statement($resourceApplication,$predicateStyle,$applicationStyle));
    140136               
    141                 $this->save();
     137        $this->save();
    142138    }
    143139}
  • Dev/branches/jos-branch/classes/DatabaseInterface.php

    r128 r130  
    1717     * Constructor for the DatabaseInterface class
    1818     */
    19     protected $applicationConnector;
     19    private $applicationConnector;
     20    private $questionConnector;
     21    private $userConnector;
    2022   
     23    /**
     24     * Constructor for DatabaseInterface.
     25     * Initializes all the connectors.
     26     */
    2127    public function __construct() {
    2228        $this->applicationConnector = new ApplicationConnector();
     29        $this->questionConnector = new QuestionConnector();
     30        $this->userConnector = new UserConnector();
    2331    }
    2432   
     33    /**
     34     * Get the data corresponding to the given type and arguments
     35     * @param type $type
     36     * @param type $arguments
     37     * @return type
     38     */
    2539    public function get($type, $arguments)
    2640    {
    27         switch($type)
     41        switch(strtolower($type))
    2842        {
    2943            case "application":
    3044                return $this->applicationConnector->get($arguments);
    31            
     45                break;
     46            case "question":
     47                return $this->questionConnector->get($arguments);
     48                break;
     49            case "user":
     50                return $this->userConnector->get($arguments);
     51                break;
    3252        }
    3353    }
    3454       
    35         public function set($rToolObject)
    36         {
    37                 switch(get_class($rToolObject))
    38                 {
    39                         case "Application":
    40                                 $this->applicationConnector->set($rToolObject);
    41                 }
    42         }
    43        
     55    /**
     56     * Saves the given object based on its class.
     57     * @param type $rToolObject
     58     */
     59    public function set($rToolObject)
     60    {
     61        switch(get_class($rToolObject))
     62        {
     63            case "Application":
     64                $this->applicationConnector->set($rToolObject);
     65                break;
     66            case "Question":
     67                $this->questionConnector->set($rToolObject);
     68                break;
     69            case "User":
     70                $this->userConnector->set($rToolObject);
     71                break;
     72        }
     73    }
     74   
     75    /**
     76     * Saves all the objects in the given array, assuming they are
     77     * valid ResearchToolObjects.
     78     * @param type $rToolObjects
     79     */
     80    public function batchSet($rToolObjects)
     81    {
     82        foreach ($rToolObjects as $rToolObject)
     83        {
     84            $this->set($rToolObject);
     85        }
     86    }
     87
    4488       
    4589}
  • Dev/branches/jos-branch/classes/Question.php

    r114 r130  
    1111 * @author fpvanagthoven
    1212 */
    13 class Question {   
    14     public $code;
     13class Question extends ResearchToolObject{   
    1514    public $title;
    1615    public $type;
    1716    public $description;
     17    public $category;
    1818    public $answers; // format answers['#']
    19     public $category;
    2019   
    21     public function __construct($code, $title = null, $type = null, $description = null)
     20    /**
     21     * Constructor for a Question. $uid equals the corresponding code.
     22     * @param type $uid
     23     * @param type $title
     24     * @param type $type
     25     * @param type $description
     26     * @param type $category
     27     * @param type $answers
     28     */
     29    public function __construct($uid, $title = null, $type = null, $description = null, $category = null, $answers = null)
    2230    {
    23         $this->code = $code;
     31        $this->uid = $uid;
    2432        $this->title = $title;
    2533        $this->type = $type;
    2634        $this->description = $description;
    27         $this->answers = array();
     35        $this->category =  $category;
     36        $this->answers = $answers;
    2837    }
    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($code, $info)
    37     {
    38         $question = new Question($code);
    39         $question->title = $info['questionTitle'];
    40         $question->type = $info['questionType'];
    41         if(isset($info['questionDescription']))
    42             $question->description = $info['questionDescription'];
    43         $question->category = $info['questionCategory'];
    44        
    45         $i = 1;
    46         while (isset($info['ans' . $i]))
    47         {
    48             array_push($question->answers, $info['ans' . $i]);
    49             $i++;
    50         }
    51        
    52         return $question;
    53     }
    54 
    5538}
    5639
  • Dev/branches/jos-branch/classes/ResearchToolObject.php

    r128 r130  
    66 */
    77class ResearchToolObject {
    8     private $uid;
     8    public $uid;
    99}
    1010
Note: See TracChangeset for help on using the changeset viewer.