[91] | 1 | <?php |
---|
| 2 | |
---|
[100] | 3 | class DashboardRDFWriter |
---|
[91] | 4 | { |
---|
| 5 | protected $model; |
---|
| 6 | |
---|
| 7 | protected $resourceDashboard; |
---|
| 8 | protected $dashboardID; |
---|
| 9 | |
---|
| 10 | protected $filePath; |
---|
| 11 | |
---|
| 12 | public function __construct($dashboardID) |
---|
| 13 | { |
---|
| 14 | // Create empty MemModel |
---|
| 15 | $factory = new ModelFactory(); |
---|
| 16 | $this->model = $factory->getDefaultModel(); |
---|
| 17 | |
---|
| 18 | $this->dashboardID = $dashboardID; |
---|
| 19 | $this->filePath = 'data/dashboards/'; |
---|
| 20 | if (!is_dir($this->filePath)) |
---|
| 21 | mkdir($this->filePath); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | public function saveDashboard() |
---|
| 25 | { |
---|
| 26 | $this->model->saveAs($this->filePath.'dashboard_'.$this->dashboardID.'.rdf','rdf'); |
---|
| 27 | } |
---|
| 28 | |
---|
[100] | 29 | public function createDashboard($dTitle, $dDescription, $dCreatorID) |
---|
[91] | 30 | { |
---|
| 31 | $this->resourceDashboard = new Resource(DASHBOARD.'/'.$this->dashboardID); |
---|
| 32 | |
---|
| 33 | $resourceDashboardType = new Resource(DASHBOARD); |
---|
| 34 | $predicateRType = new Resource(RTYPE); |
---|
| 35 | $this->model->add(new Statement($this->resourceDashboard,$predicateRType,$resourceDashboardType)); |
---|
| 36 | |
---|
| 37 | $literalDashboardID = new Literal($this->dashboardID); |
---|
| 38 | $predicateUniqueID = new Resource(UID); |
---|
| 39 | $this->model->add(new Statement($this->resourceDashboard,$predicateUniqueID,$literalDashboardID)); |
---|
| 40 | |
---|
| 41 | $predicateTitle = new Resource(TITLE); |
---|
| 42 | $dashboardTitle = new Literal($dTitle); |
---|
| 43 | $this->model->add(new Statement($this->resourceDashboard,$predicateTitle,$dashboardTitle)); |
---|
| 44 | |
---|
| 45 | $predicateDescription = new Resource(DESCRIPTION); |
---|
| 46 | $dashboardDescription = new Literal($dDescription); |
---|
| 47 | $this->model->add(new Statement($this->resourceDashboard,$predicateDescription,$dashboardDescription)); |
---|
[100] | 48 | |
---|
| 49 | $predicateCreator = new Resource(CREATOR); |
---|
| 50 | $userID = new Literal($dCreatorID); |
---|
| 51 | $this->model->add(new Statement($this->resourceDashboard,$predicateCreator,$userID)); |
---|
[91] | 52 | } |
---|
| 53 | |
---|
[100] | 54 | public function addGraph($gID,$gTitle,$gDescription,$gTypes,$gData) |
---|
[91] | 55 | { |
---|
| 56 | $resourceGraph = new Resource(GRAPH); |
---|
| 57 | |
---|
| 58 | $predicateTitle = new Resource(TITLE); |
---|
| 59 | $graphTitle = new Literal($gTitle); |
---|
| 60 | $this->model->add(new Statement($resourceGraph,$predicateTitle,$graphTitle)); |
---|
| 61 | |
---|
| 62 | $predicateDescription = new Resource(DESCRIPTION); |
---|
| 63 | $graphDescription = new Literal($gDescription); |
---|
| 64 | $this->model->add(new Statement($resourceGraph,$predicateDescription,$graphDescription)); |
---|
| 65 | |
---|
[100] | 66 | $predicateUniqueID = new Resource(UID); |
---|
| 67 | $graphID = new Literal($gID); |
---|
| 68 | $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$graphID)); |
---|
| 69 | |
---|
[91] | 70 | $predicateGraphType = new Resource(GRAPH_TYPE); |
---|
| 71 | foreach($gTypes as $gType) |
---|
| 72 | { |
---|
| 73 | $graphType = new Literal($gType); |
---|
| 74 | $this->model->add(new Statement($resourceGraph,$predicateGraphType,$gType)); |
---|
| 75 | } |
---|
| 76 | |
---|
[100] | 77 | $predicateData = new Resource(HAS_DATA); |
---|
[91] | 78 | foreach($gData as $gThis) |
---|
| 79 | { |
---|
[100] | 80 | $resourceData = new Resource(DATA); |
---|
| 81 | $this->model->add(new Statement($resourceGraph,$predicateData,$resourceData)); |
---|
| 82 | |
---|
| 83 | $dataType = new Literal($gThis['type']); |
---|
| 84 | $predicateDataType = new Resource(DATA_TYPE); |
---|
| 85 | $this->model->add(new Statement($resourceData,$predicateDataType,$dataType)); |
---|
| 86 | |
---|
| 87 | $dataID = new Literal($gThis['id']); |
---|
| 88 | $this->model->add(new Statement($resourceData,$predicateUniqueID,$dataID)); |
---|
[91] | 89 | } |
---|
| 90 | |
---|
| 91 | $predicateHasGraph = new Resource(HAS_GRAPH); |
---|
| 92 | $this->model->add(new Statement($this->resourceDashboard,$predicateHasGraph,$resourceGraph)); |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | ?> |
---|