SOAP Webservice zur Abfrage von Studentendaten

This commit is contained in:
Karl Burkhart
2012-05-24 07:33:00 +00:00
parent 653191fe2f
commit 2c3f919dd7
2 changed files with 303 additions and 0 deletions
+181
View File
@@ -0,0 +1,181 @@
<?php
/* Copyright (C) 2012 Technikum-Wien
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Karl Burkhart <burkhart@technikum-wien.at>.
*/
require_once('../config/vilesci.config.inc.php');
require_once('../include/student.class.php');
require_once('../include/prestudent.class.php');
require_once('../include/webservicerecht.class.php');
require_once('../include/studiensemester.class.php');
ini_set("soap.wsdl_cache_enabled", "0");
$SOAPServer = new SoapServer(APP_ROOT."/soap/student.wsdl.php?".microtime());
$SOAPServer->addFunction("getStudentFromUid");
$SOAPServer->addFunction("getStudentFromMatrikelnummer");
$SOAPServer->addFunction("getStudentFromStudiengang");
$SOAPServer->handle();
/**
* Lädt einen Studenten anhand übergebener UID
* @param $student_uid
* @param $authentifizierung
*/
function getStudentFromUid($student_uid, $authentifizierung)
{
$recht = new webservicerecht();
$user = $authentifizierung->username;
$passwort = $authentifizierung->passwort;
// User authentifizieren
if(!check_user($user, $passwort))
return new SoapFault("Server", "Invalid Credentials");
// darf User überhaupt Methode verwenden
$recht = new webservicerecht();
if(!$recht->isUserAuthorized($user, 'getStudentFromUid'))
return new SoapFault("Server", "No permission");
$studentObj = new student(); // Studentendaten
$student = new foo(); // Rückgabeobjekt
$preStudent = new prestudent(); // StudentenStatus
if(!$studentObj->load($student_uid))
return new SoapFault("Server", "Kein Student mit übergebener Uid gefunden");
$preStudent->getLastStatus($studentObj->prestudent_id);
$student->studiengang_kz = $studentObj->studiengang_kz;
$student->semester = $studentObj->semester;
$student->verband = $studentObj->verband;
$student->gruppe = $studentObj->gruppe;
$student->vorname = $studentObj->vorname;
$student->nachname = $studentObj->nachname;
$student->uid = $studentObj->uid;
$student->status = $preStudent->status_kurzbz;
$student->personenkennzeichen = $studentObj->matrikelnr;
$student->email = $student->uid.'@'.DOMAIN;
$student = $recht->clearResponse($user, 'getStudentFromUid', $student);
return $student;
}
/**
* Lädt einen Studenten anhand übergebener Matrikelnummer
* @param $matrikelnummer
* @param $authentifizierung
*/
function getStudentFromMatrikelnummer($matrikelnummer, $authentifizierung)
{
$recht = new webservicerecht();
$user = $authentifizierung->username;
$passwort = $authentifizierung->passwort;
// User authentifizieren
if(!check_user($user, $passwort))
return new SoapFault("Server", "Invalid Credentials");
// darf User überhaupt Methode verwenden
$recht = new webservicerecht();
if(!$recht->isUserAuthorized($user, 'getStudentFromMatrikelnummer'))
return new SoapFault("Server", "No permission");
$studentObj = new student(); // Studentendaten
$student = new foo(); // Rückgabeobjekt
$preStudent = new prestudent(); // StudentenStatus
$student_uid = $studentObj->getUidFromMatrikelnummer($matrikelnummer);
if(!$studentObj->load($student_uid))
return new SoapFault("Server", "Kein Student mit übergebener Matrikelnummer gefunden");
$preStudent->getLastStatus($studentObj->prestudent_id);
$student->studiengang_kz = $studentObj->studiengang_kz;
$student->semester = $studentObj->semester;
$student->verband = $studentObj->verband;
$student->gruppe = $studentObj->gruppe;
$student->vorname = $studentObj->vorname;
$student->nachname = $studentObj->nachname;
$student->uid = $studentObj->uid;
$student->status = $preStudent->status_kurzbz;
$student->personenkennzeichen = $studentObj->matrikelnr;
$student->email = $student->uid.'@'.DOMAIN;
$student = $recht->clearResponse($user, 'getStudentFromMatrikelnummer', $student);
return $student;
}
/**
* Lädt alle Studenten eines gewissen Kriteriums
* @param $studiengang
* @param $semester
* @param $verband
* @param $gruppe
* @param $authentifizierung
*/
function getStudentFromStudiengang($studiengang, $semester = null, $verband = null, $gruppe = null, $authentifizierung)
{
$recht = new webservicerecht();
$user = $authentifizierung->username;
$passwort = $authentifizierung->passwort;
// User authentifizieren
if(!check_user($user, $passwort))
return new SoapFault("Server", "Invalid Credentials");
// darf User überhaupt Methode verwenden
$recht = new webservicerecht();
if(!$recht->isUserAuthorized($user, 'getStudentFromStudiengang'))
return new SoapFault("Server", "No permission");
$studentObj = new student(); // Studentendaten
$preStudent = new prestudent(); // StudentenStatus
$studiensemester = new studiensemester(); // aktuelles Studiensemester
$studSemester = $studiensemester->getakt();
$studentObj->result = $studentObj->getStudents($studiengang, $semester, $verband, $gruppe, null, $studSemester);
$studentArray = array();
foreach($studentObj->result as $stud)
{
$student = new foo(); // Rückgabeobjekt
$preStudent->getLastStatus($stud->prestudent_id);
$student->studiengang_kz = $stud->studiengang_kz;
$student->semester = $stud->semester;
$student->verband = $stud->verband;
$student->gruppe = $stud->gruppe;
$student->vorname = $stud->vorname;
$student->nachname = $stud->nachname;
$student->uid = $stud->uid;
$student->status = $preStudent->status_kurzbz;
$student->personenkennzeichen = $stud->matrikelnr;
$student->email = $stud->uid.'@'.DOMAIN;
$student = $recht->clearResponse($user, 'getStudentFromStudiengang', $student);
$studentArray[] = $student;
}
return $studentArray;
}
class foo{}
+122
View File
@@ -0,0 +1,122 @@
<?php
require_once('../config/vilesci.config.inc.php');
header("Content-type: text/plain");
echo "<?xml version='1.0' encoding='utf-8' ?>";
?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://technikum-wien.at"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://technikum-wien.at"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:message name="GetStudentFromUidRequest">
<wsdl:part minOccurs="0" maxOccurs="1" name="student_uid" type="s:string"/>
<wsdl:part minOccurs="0" maxOccurs="1" name="authentifizierung" type="tns:GetAuthentifizierung"/>
</wsdl:message>
<wsdl:message name="GetStudentFromUidResponse">
<wsdl:part minOccurs="0" maxOccurs="1" name="GetStudentFromUid" type="tns:Student"/>
</wsdl:message>
<wsdl:message name="GetStudentFromMatrikelnummerRequest">
<wsdl:part minOccurs="0" maxOccurs="1" name="student_uid" type="s:string"/>
<wsdl:part minOccurs="0" maxOccurs="1" name="authentifizierung" type="tns:GetAuthentifizierung"/>
</wsdl:message>
<wsdl:message name="GetStudentFromMatrikelnummerResponse">
<wsdl:part minOccurs="0" maxOccurs="1" name="GetStudentFromUid" type="tns:Student"/>
</wsdl:message>
<wsdl:message name="GetStudentFromStudiengangRequest">
<wsdl:part minOccurs="0" maxOccurs="1" name="studiengang" type="s:string"/>
<wsdl:part minOccurs="0" maxOccurs="1" name="semester" type="s:string"/>
<wsdl:part minOccurs="0" maxOccurs="1" name="verband" type="s:string"/>
<wsdl:part minOccurs="0" maxOccurs="1" name="gruppe" type="s:string"/>
<wsdl:part minOccurs="0" maxOccurs="1" name="authentifizierung" type="tns:GetAuthentifizierung"/>
</wsdl:message>
<wsdl:message name="GetStudentFromStudiengangResponse">
<wsdl:part minOccurs="0" maxOccurs="1" name="GetStudentFromStudiengang" type="tns:ArrayOfStudentItem"/>
</wsdl:message>
<s:complexType name="ArrayOfStudentItem">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="StudentItem" nillable="true" type="tns:Student"/>
</s:sequence>
</s:complexType>
<s:complexType name="Student">
<s:element minOccurs="0" maxOccurs="1" name="studiengang_kz" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="semester" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="verband" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="gruppe" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="vorname" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="nachname" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="uid" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="status" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="personenkennzeichen" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="email" type="s:string"/>
</s:complexType>
<s:complexType name="GetAuthentifizierung">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="username" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="passwort" type="s:string"/>
</s:sequence>
</s:complexType>
<wsdl:portType name="ConfigPortType">
<wsdl:operation name="getStudentFromUid">
<wsdl:input message="tns:GetStudentFromUidRequest"/>
<wsdl:output message="tns:GetStudentFromUidResponse"/>
</wsdl:operation>
<wsdl:operation name="getStudentFromMatrikelnummer">
<wsdl:input message="tns:GetStudentFromMatrikelnummerRequest"/>
<wsdl:output message="tns:GetStudentFromMatrikelnummerResponse"/>
</wsdl:operation>
<wsdl:operation name="getStudentFromStudiengang">
<wsdl:input message="tns:GetStudentFromStudiengangRequest"/>
<wsdl:output message="tns:GetStudentFromStudiengangResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ConfigBinding" type="tns:ConfigPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getStudentFromUid">
<soap:operation soapAction="<?php echo APP_ROOT."soap/getStudentFromUid";?>" />
<wsdl:input>
<soap:body use="encoded" namespace="http://technikum-wien.at" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:input>
<wsdl:output>
<soap:body use="encoded" namespace="http://technikum-wien.at" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getStudentFromMatrikelnummer">
<soap:operation soapAction="<?php echo APP_ROOT."soap/getStudentFromMatrikelnummer";?>" />
<wsdl:input>
<soap:body use="encoded" namespace="http://technikum-wien.at" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:input>
<wsdl:output>
<soap:body use="encoded" namespace="http://technikum-wien.at" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getStudentFromStudiengang">
<soap:operation soapAction="<?php echo APP_ROOT."soap/getStudentFromStudiengang";?>" />
<wsdl:input>
<soap:body use="encoded" namespace="http://technikum-wien.at" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:input>
<wsdl:output>
<soap:body use="encoded" namespace="http://technikum-wien.at" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Student">
<wsdl:port name="ConfigWebservicePort" binding="tns:ConfigBinding">
<soap:address location="<?php echo APP_ROOT."/soap/student.soap.php?".microtime();?>"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>