Tuesday, November 16, 2010

nu soap with joomla

Place this code in one file modify as per your requirement and add nu soap library
i palace this file inside one folder called sopa inside root folder of joomla project and also i use model from component in this i placed my model in side com-community folder and i call one model and in this example i added multiple in put , compex type out put with array variable, and u can see out put in soap UI




require_once("nusoap/nusoap.php"); //nusopa.php download from net and include it
$ns = "http://soaptest/";

if(!defined('_JEXEC'))
define( '_JEXEC', 1 );
set_time_limit(0);
ini_set('include_path', '../');
if(!defined('JPATH_BASE'))
define('JPATH_BASE', ini_get('include_path') );
if(!defined('DS'))
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
//require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'database'.DS.'table'.DS.'table.php' );


if(!isset($mainframe))
$mainframe =& JFactory::getApplication('site');

//jimport( 'joomla.plugin.plugin' );
//jimport('joomla.filesystem.file');
require_once( JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'plugin' . DS . 'helper.php');

require_once( JPATH_BASE . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php');


require_once("convertingArrayinput.php");

function GetEventInfo(&$EventId,&$Version) {
jimport( 'joomla.application.component.model' );
JModel::addIncludePath(JPATH_ROOT.DS.'components'.DS.'com_community'.DS.'models');
$profilemodel =& JModel::getInstance('webprofile', 'CommunityModel');

//$user =& JFactory::getUser($userid);
//$VersionReq=$user->Version;
//$role=$user->Role;
if($EventId) {
$result = array();
$teams= array();
$clubdata=$profilemodel->getEventInfo($EventId,$Version);
$teamdata=$profilemodel->getEventTeams($EventId);
//print_r($clubdata);
foreach($teamdata as $team) {
$teams[]=array('TeamId'=>$team->TeamId,'TeamName'=>$team->TeamName);
}
foreach($clubdata as $row) {
$result1= array('UserData'=>array('UserId'=>$row->UserId,'Role'=>$row->Role),
'EventData'=>array('EventDetails'=>array('EventId'=>$row->EventId,'EventName'=>$row->EventName,'EventLocation'=>$row->FacilityName,'EventLogo'=>$row->EventLogoPath,'EventDate'=>$row->Event),
'Facility'=>array('Longtitude'=>$row->FacilityLongtitude,'Latitude'=>$row->FacliltyLatitude),
'Schedule'=>$row->ScheduleLink,'Rules'=>$row->RulesLink,'WeatherLine'=>$row->WeatherLine,
'Teams'=>$teams));
}

$res = array('Response' => array('Code' => '100','Msg'=>'Successful'),
'ResponseData'=>$result1);
return $res;
} else {

$res = array('Response' => array('Code' => '-100','Msg'=>'In Valid Event Id'),
'ResponseData'=> array());

}



}


function checkDate1($date1){
return preg_match('`^(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])$`', $date1) ? TRUE : FALSE;
}

$server = new soap_server();
$server->configureWSDL('GetEventInfo', $ns);
$server->wsdl->schemaTargetNamespace = $ns;
$server->debug_flag = true;

$server->wsdl->addComplexType(
'ResponseInfo',
'complexType',
'struct',
'all',
'',
array(
'Response' => array('name' => 'Response', 'type' => 'tns:Response'),
'ResponseData' => array('name' => 'ResponseData', 'type' => 'tns:ResponseData'),
)
);

$server->wsdl->addComplexType(
'Response',
'complexType',
'struct',
'all',
'',
array(
'Code' => array('name' => 'Code', 'type' => 'xsd:int'),
'Msg' => array('name' => 'Msg', 'type' => 'xsd:string')
)
);


$server->wsdl->addComplexType(
'TeamsArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Team[]')
),
'tns:Team'
);




$server->wsdl->addComplexType(
'Team',
'element',
'struct',
'all',
'',
array(
'TeamId' => array('name' => 'TeamId', 'type' => 'xsd:int'),
'TeamName' => array('name' => 'TeamName', 'type' => 'xsd:string')
)
);


$server->wsdl->addComplexType(
'UserData',
'complexType',
'struct',
'all',
'',
array(
'UserId' => array('name' => 'UserId', 'type' => 'xsd:int'),
'Role' => array('name' => 'Role', 'type' => 'xsd:string')
)
);

$server->wsdl->addComplexType(
'EventDetails',
'complexType',
'struct',
'all',
'',
array(
'EventId' => array('name' => 'EventId', 'type' => 'xsd:int'),
'EventName' => array('name' => 'EventName', 'type' => 'xsd:string'),
'EventLocation' => array('name' => 'EventLocation', 'type' => 'xsd:string'),
'EventLogoPath' => array('name' => 'EventLogoPath', 'type' => 'xsd:string'),
'EventDate' => array('name' => 'EventDate', 'type' => 'xsd:date')
)
);

$server->wsdl->addComplexType(
'Facility',
'complexType',
'struct',
'all',
'',
array(
'Longtitude' => array('name' => 'Longtitude', 'type' => 'xsd:string'),
'Latitude' => array('name' => 'Latitude', 'type' => 'xsd:string')
)
);


$server->wsdl->addComplexType(
'EventData',
'complexType',
'struct',
'all',
'',
array(
'EventDetails' => array('name' => 'EventDetails', 'type' => 'tns:EventDetails'),
'Facility' => array('name' => 'Facility', 'type' => 'tns:Facility'),
'Schedule' => array('name' => 'Schedule', 'type' => 'xsd:string'),
'Rules' => array('name' => 'Rules', 'type' => 'xsd:string'),
'WeatherLine' => array('name' => 'WeatherLine', 'type' => 'xsd:string'),
'Teams' => array('name' => 'Teams', 'type' => 'tns:TeamsArray')
)
);

$server->wsdl->addComplexType(
'ResponseData',
'complexType',
'struct',
'all',
'',
array(
'UserData' => array('name' => 'UserData', 'type' => 'tns:UserData'),
'EventData' => array('name' => 'EventData', 'type' => 'tns:EventData')
)
);


$inparams = array('EventId' => 'xsd:int', 'Version' => 'xsd:string');
//$outparams = array('msg' => 'xsd:string','name' => 'xsd:string','role'=> 'xsd:int','email'=> 'xsd:string','lastName'=> 'xsd:string','temp'=>'xsd:array');
//$outparams = array('name'=> 'xsd:string', 'emailArray' => 'tns:ContactArray');
$outparams = $outparams = array('ResponseInfo' => 'tns:ResponseInfo');

//$outparams = $outparams = array('ResponseInfo' => 'xsd:string');
//$outparams = array('ProfileInfo'=> 'tns:Book');
$server->register('GetEventInfo', $inparams, $outparams, $ns, false);

if (!isset($HTTP_RAW_POST_DATA))
$HTTP_RAW_POST_DATA = file_get_contents("php://input");

$server->service($HTTP_RAW_POST_DATA);
file_put_contents("sqlwsdl.log", $HTTP_RAW_POST_DATA."\r\n".$server->getDebug());
?>