source: Dev/trunk/classes_old/SessionCreationDatabaseInterface.php @ 137

Last change on this file since 137 was 137, checked in by jkraaijeveld, 14 years ago

Added old classes

File size: 3.6 KB
Line 
1<?php
2
3// Survey database interface class as intermediate for storing data from the site to the RDF database
4require_once 'rdfConstants.php';
5
6// Include RAP Library to write RDF files
7include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
8
9
10
11class SessionCreationDatabaseInterface
12{               
13    protected $sessionRDFWriter;
14    protected $sessionRDFReader;
15
16
17    public function __construct($sessionID)
18    {
19        if($sessionID == null)
20            $sessionUID = md5( uniqid(rand(), true) );
21        else
22            $sessionUID = $sessionID;
23
24        $this->sessionRDFWriter = new SessionRDFWriter($sessionUID);
25        $this->sessionRDFReader = new SessionRDFReader($sessionUID);
26    }
27   
28    public function setSessionInfo($session)
29    {
30        $sTitle = $session['sessionTitle'];
31        $sDescription = $session['sessionDescription'];
32
33        $this->sessionRDFWriter->createSession($sTitle,$sDescription);
34       
35        $pipelineCount = $session['pipelineCount'];
36       
37        for($i = 1; $i <= $pipelineCount; $i++)
38        {
39            if(isset($session[$i.'s']))
40            {
41                $this->sessionRDFWriter->addSurveyToPipeline($session[$i.'s'], $i);
42            }
43            else if(isset($session[$i.'a']))
44            {
45                $this->sessionRDFWriter->addApplicationToPipeline($session[$i.'a'], $i);
46            }
47            else if(isset($session[$i.'d']))
48            {
49                $this->sessionRDFWriter->addDashboardToPipeline($session[$i.'d'], $i);
50            }
51        }
52    }
53   
54    public function getSessionInfo()
55    {
56        $sessionInfo = array();
57
58        $resultSession = $this->sessionRDFReader->getSurveyInfo();
59       
60        $sessionInfo['sessionTitle'] = substr($resultSession[0][0]['?title'],9,strlen($resultSession[0][0]['?title'])-11);
61        $sessionInfo['sessionDescription'] = substr($resultSession[0][0]['?description'],9,strlen($resultSession[0][0]['?description'])-11);
62       
63        foreach ($resultSession[1][1] as $surveyInfo)
64        {
65             $surveyUID = substr($surveyInfo['?uid'],9,strlen($surveyInfo['?uid'])-11);
66             $surveyIndex = substr($surveyInfo['?index'],9,strlen($surveyInfo['?index'])-11);
67             $sessionInfo[$surveyIndex . 's'] = $surveyUID;
68        }
69        foreach ($resultSession[1][2] as $applicationInfo)
70        {
71             $applicationUID = substr($applicationInfo['?uid'],9,strlen($applicationInfo['?uid'])-11);
72             $applicationIndex = substr($applicationInfo['?index'],9,strlen($applicationInfo['?index'])-11);
73             $sessionInfo[$applicationIndex . 'a'] = $applicationUID;
74        }
75        foreach ($resultSession[1][3] as $dashboardInfo)
76        {
77             $dashboardUID = substr($dashboardInfo['?uid'],9,strlen($dashboardInfo['?uid'])-11);
78             $dashboardIndex = substr($dashboardInfo['?index'],9,strlen($dashboardInfo['?index'])-11);
79             $sessionInfo[$dashboardIndex . 'd'] = $dashboardUID;
80        }
81    }
82   
83    public function getExistingSessions()
84    {
85        $sessionIDs = array();
86        $sessions = array();
87
88        if($handle = opendir('data/sessions/'))
89        {
90            while (false !== ($file = readdir($handle))) {
91                if(strstr($file, 'session_'))
92                    $sessionIDs[] = substr($file,7,strlen($file)-11);
93            }
94        }
95
96        foreach($sessionIDs as $sessionID)
97        {
98            $sessionTitle = $this->sessionRDFReader->getSessionTitleByID($sessionID);
99            $$sessions[$sessionID] = substr($sessionTitle[0]['?title'],9,strlen($sessionTitle[0]['?title'])-11);
100        }
101
102        return $surveys;
103    }
104}
105?>
Note: See TracBrowser for help on using the repository browser.