Changeset 130 for Dev/branches


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
Files:
1 deleted
8 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
  • Dev/branches/jos-branch/data/applications/applications.rdf

    r129 r130  
    88   xmlns:ns1="http://tbm.tudelft.nl/researchtool/predicates/">
    99
    10 <rdf:Description rdf:about="http://tbm.tudelft.nl/researchtool/resources/application/364790b25634bf9b45fa16248a764eff">
     10<rdf:Description rdf:about="http://tbm.tudelft.nl/researchtool/resources/application/c571ae05fa6e69ad63a8793f1484206e">
    1111   <ns1:resource_type rdf:resource="http://tbm.tudelft.nl/researchtool/resources/application"/>
    12    <ns1:uid>364790b25634bf9b45fa16248a764eff</ns1:uid>
    13    <ns1:title>app2</ns1:title>
    14    <ns1:description>craft</ns1:description>
    15    <ns1:style><![CDATA[]]></ns1:style>
     12   <ns1:uid>c571ae05fa6e69ad63a8793f1484206f</ns1:uid>
     13   <ns1:title>Sup</ns1:title>
     14   <ns1:description>herpderp</ns1:description>
     15   <ns1:style>derpStyle</ns1:style>
    1616</rdf:Description>
    1717
    18 <rdf:Description rdf:about="http://tbm.tudelft.nl/researchtool/resources/application/29561e34ea30746a46f3027972a5d5f9">
     18<rdf:Description rdf:about="http://tbm.tudelft.nl/researchtool/resources/application/19770b885bb13f2c5a1e3fd03bf77179">
    1919   <ns1:resource_type rdf:resource="http://tbm.tudelft.nl/researchtool/resources/application"/>
    20    <ns1:uid>29561e34ea30746a46f3027972a5d5f9</ns1:uid>
    21    <ns1:title>Sup, testing if the title changes properly.</ns1:title>
    22    <ns1:description>test</ns1:description>
    23    <ns1:style><![CDATA[]]></ns1:style>
     20   <ns1:uid>19770b885bb13f2c5a1e3fd03bf77179</ns1:uid>
     21   <ns1:title>NewTestTitle</ns1:title>
     22   <ns1:description>NewTestDescription</ns1:description>
     23   <ns1:style>NewStylo</ns1:style>
     24</rdf:Description>
     25
     26<rdf:Description rdf:about="http://tbm.tudelft.nl/researchtool/resources/application/cc91fba98ce357d9eb6709407d8cd4a4">
     27   <ns1:resource_type rdf:resource="http://tbm.tudelft.nl/researchtool/resources/application"/>
     28   <ns1:uid>cc91fba98ce357d9eb6709407d8cd4a4</ns1:uid>
     29   <ns1:title>NewTestTitle</ns1:title>
     30   <ns1:description>NewTestDescription</ns1:description>
     31   <ns1:style>NewStylo</ns1:style>
    2432</rdf:Description>
    2533
  • Dev/branches/jos-branch/data/users/users.rdf

    r129 r130  
    44
    55<rdf:RDF
     6   xml:base="data/users/users.rdf#"
    67   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    78   xmlns:ns1="http://tbm.tudelft.nl/researchtool/predicates/">
    89
    9 <rdf:Description rdf:about="http://tbm.tudelft.nl/researchtool/resources/user/e978ee6bdc7af674060f558ce7ac1127">
     10<rdf:Description rdf:about="http://tbm.tudelft.nl/researchtool/resources/user/b76cbf38cac7a3f048ca0d64a6c3ef58">
     11   <ns1:resource_type rdf:resource="http://tbm.tudelft.nl/researchtool/resources/user"/>
     12   <ns1:name>iets</ns1:name>
     13   <ns1:uid>b76cbf38cac7a3f048ca0d64a6c3ef58</ns1:uid>
     14   <ns1:password>Vo87e37xIpm4uP4AfyHR9aSERlYpcgwE93Bc+rf2fD0=</ns1:password>
     15</rdf:Description>
     16
     17<rdf:Description rdf:about="http://tbm.tudelft.nl/researchtool/resources/user/efa84d358d1bbd732c4075a1b3832dc7">
     18   <ns1:resource_type rdf:resource="http://tbm.tudelft.nl/researchtool/resources/user"/>
     19   <ns1:name>booya</ns1:name>
     20   <ns1:uid>efa84d358d1bbd732c4075a1b3832dc7</ns1:uid>
     21   <ns1:password>Zk3CKJGWXcEvljUUmyAU5aLwTuwsMwdZZcDCzAH9Xrk=</ns1:password>
     22</rdf:Description>
     23
     24<rdf:Description rdf:about="http://tbm.tudelft.nl/researchtool/resources/user/caa33a16c3b30cdcb7a5f0434c23e210">
     25   <ns1:resource_type rdf:resource="http://tbm.tudelft.nl/researchtool/resources/user"/>
     26   <ns1:name>frans</ns1:name>
     27   <ns1:uid>caa33a16c3b30cdcb7a5f0434c23e210</ns1:uid>
     28   <ns1:password>YrNByNHxZwPoreIjW3lpAgeMg+J6kYBdl53uBCsHRKo=</ns1:password>
     29</rdf:Description>
     30
     31<rdf:Description rdf:about="http://tbm.tudelft.nl/researchtool/resources/user/9043f64705e67ceb8f28242207b83adf">
    1032   <ns1:resource_type rdf:resource="http://tbm.tudelft.nl/researchtool/resources/user"/>
    1133   <ns1:name>jkraaijeveld</ns1:name>
    12    <ns1:uid>e978ee6bdc7af674060f558ce7ac1127</ns1:uid>
     34   <ns1:uid>9043f64705e67ceb8f28242207b83adf</ns1:uid>
    1335   <ns1:password>NWCbqdOCRGewETOoMI1YepJsoGQMjKozC5XOjtM5Mm8=</ns1:password>
    1436</rdf:Description>
  • Dev/branches/jos-branch/testpage.php

    r128 r130  
    1 <?php
    2         require 'classes/master.php';
    3         require 'rdfConstants.php';
     1<?php
     2    require 'classes/master.php';
    43
     4    $db = new DatabaseInterface();
     5//    $arguments = array("id" => "c571ae05fa6e69ad63a8793f1484206e");
    56
    6        
    7         $di = new DatabaseInterface();
    8        
    9        
    10         $args = array("description" => "test");
    11         $apps = $di->get("application", $args);
    12         $app = $apps[0];
    13         $app->title = "Sup, testing if the title changes properly.";
    14         $di->set($app);
    15 
     7   
     8   
     9    $result = $db->get("user", array("name" => "jkraaijeveld"));
     10    print_r($result);
    1611?>
Note: See TracChangeset for help on using the changeset viewer.