Changeset 130 for Dev/branches/jos-branch/classes
- Timestamp:
- 10/24/11 13:47:23 (14 years ago)
- Location:
- Dev/branches/jos-branch/classes
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/jos-branch/classes/Application.php
r128 r130 14 14 public function __construct($uid = null, $title = null, $description = null, $style = null) 15 15 { 16 if(!isset ($uid)) 17 { 18 $uid = md5(uniqid(rand(), true)); 19 } 16 20 $this->uid = $uid; 17 21 $this->title = $title; … … 19 23 $this->style = $style; 20 24 } 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 }30 25 31 26 } -
Dev/branches/jos-branch/classes/ApplicationConnector.php
r128 r130 61 61 //Set the arguments if they are supplied 62 62 if(in_array("uid", $keys)) 63 $uid = "\"".$arguments[" id"]."\"";63 $uid = "\"".$arguments["uid"]."\""; 64 64 if(in_array("title", $keys)) 65 65 $title = '\''.$arguments["title"].'\''; … … 81 81 predicates:description ?description ; 82 82 predicates:style ?style ; 83 83 predicates:uid ' . $uid . ' 84 84 predicates:title ' . $title . ' 85 85 predicates:description ' . $description . ' 86 predicates:style ' . $style . ' 86 predicates:style ' . $style . ' 87 87 }'; 88 88 89 89 //Query the model 90 90 $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; 106 101 } 107 102 … … 114 109 public function set($rToolObject) 115 110 { 111 $this->load(); 116 112 $resourceApplication = new Resource(APPLICATION.'/'.$rToolObject->uid); 117 118 119 120 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 121 117 $resourceApplicationType = new Resource(APPLICATION); 122 118 $predicateRType = new Resource(RTYPE); … … 139 135 $this->model->add(new Statement($resourceApplication,$predicateStyle,$applicationStyle)); 140 136 141 137 $this->save(); 142 138 } 143 139 } -
Dev/branches/jos-branch/classes/DatabaseInterface.php
r128 r130 17 17 * Constructor for the DatabaseInterface class 18 18 */ 19 protected $applicationConnector; 19 private $applicationConnector; 20 private $questionConnector; 21 private $userConnector; 20 22 23 /** 24 * Constructor for DatabaseInterface. 25 * Initializes all the connectors. 26 */ 21 27 public function __construct() { 22 28 $this->applicationConnector = new ApplicationConnector(); 29 $this->questionConnector = new QuestionConnector(); 30 $this->userConnector = new UserConnector(); 23 31 } 24 32 33 /** 34 * Get the data corresponding to the given type and arguments 35 * @param type $type 36 * @param type $arguments 37 * @return type 38 */ 25 39 public function get($type, $arguments) 26 40 { 27 switch( $type)41 switch(strtolower($type)) 28 42 { 29 43 case "application": 30 44 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; 32 52 } 33 53 } 34 54 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 44 88 45 89 } -
Dev/branches/jos-branch/classes/Question.php
r114 r130 11 11 * @author fpvanagthoven 12 12 */ 13 class Question { 14 public $code; 13 class Question extends ResearchToolObject{ 15 14 public $title; 16 15 public $type; 17 16 public $description; 17 public $category; 18 18 public $answers; // format answers['#'] 19 public $category;20 19 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) 22 30 { 23 $this-> code = $code;31 $this->uid = $uid; 24 32 $this->title = $title; 25 33 $this->type = $type; 26 34 $this->description = $description; 27 $this->answers = array(); 35 $this->category = $category; 36 $this->answers = $answers; 28 37 } 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 55 38 } 56 39 -
Dev/branches/jos-branch/classes/ResearchToolObject.php
r128 r130 6 6 */ 7 7 class ResearchToolObject { 8 p rivate$uid;8 public $uid; 9 9 } 10 10
Note: See TracChangeset
for help on using the changeset viewer.